Skip to content

Auto generated schema based ARRAY OPERATION API

Request Method: PUT

  • It is uses for MongoDb only.

Sample MongoDb data

[
    {
        "customer_id": 1,
        "ages": [
            {
                "age": 20,
                "birth_year": 1989,
                "country_id": 56
            },
            {
                "age": 21,
                "birth_year": 1989,
                "country_id": ""
            },
            {
                "age": 22,
                "birth_year": 1989,
                "country_id": ""
            }
        ],
        "hobbies": ["cricket", "football", "traveling", "riding"],
        "distances" : [ 73.28, 9.67, 124.36 ],
        "address": "Surat"
    },
    {
        "customer_id": 2,
        "ages": [
            {
                "age": 5,
                "birth_year": 1989,
                "country_id": 87
            },
            {
                "age": 6,
                "birth_year": 1989,
                "country_id": ""
            },
            {
                "age": 8,
                "birth_year": 1989,
                "country_id": ""
            }
        ],
        "hobbies": ["tracking"],
        "distances" : [ 16.04, 3.25, 6.82 ],
        "address": "Delhi"
    }
]

Push Operation

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 1
    },
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": [
                {
                    "age": 33,
                    "birth_year": 1989,
                    "country_id": 1
                }
            ]
        }
    ]
}

Pull Operation

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 1
    },
    "operations": [
        {
            "operation": "pull",
            "path": "ages",
            "queryToRemove": {
                "age": 2,
                "birth_year": 1989,
                "country_id": 1
            }
        }
    ]
}

Pop Operation

  • POP operation removes the first or last element of an array.
  • The value 'direction:-1' to remove the first element and 'direction:1' to remove the last element in an array.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 5
    },
    "operations": [
        {
            "operation": "pop",
            "path": "ages",
            "direction": 1
        }
    ]
}

PullAll Operation

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 1
    },
    "operations": [
        {
            "operation": "pullAll",
            "path": "ages",
            "dataToPull": [
                {
                    "age": 2,
                    "birth_year": 1989,
                    "country_id": 1
                }
            ]
        }
    ]
}

Push in all

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {},
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": [
                {
                    "age": 2,
                    "birth_year": 1989
                }
            ]
        }
    ]
}

Pull from all

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {},
    "operations": [
        {
            "operation": "pullAll",
            "path": "ages",
            "dataToPull": [
                {
                    "age": 2,
                    "birth_year": 1989
                }
            ]
        }
    ]
}

addToSet

  • Add to set adds a value to an array. If the value is already present it does nothing to that array.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {},
    "operations": [
        {
            "operation": "addToSet",
            "path": "ages",
            "dataToPush": {
                "age": 2,
                "birth_year": 1989
            }
        }
    ]
}

set operation

  • The 'set' operation will update the value to an array. If the value is already present it does nothing to that array.
  • If we provide 'upsert:true' it will add 'field:value' if any related key is not found.
  • 'arrayFilters' array is used to find the data object in the array.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {},
    "operations": [
        {
            "operation": "set",
            "upsert": true,
            "dataToSet": {
                "ages.$[item].age": 4566,
                "ages.$[item].birth_year": 1999,
                "ages.$[item].birth_date": 29
            },
            "arrayFilters": [
                {
                    "item.birth_year": 1999
                }
            ]
        }
    ]
}

slice

  • 'slice' contains numbers.
  • If it's zero it will update the array with an empty array.
  • If it's negative it will update the array fields to contain only the last given number of elements.
  • If it's positive the array update with only the first given number of elements.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "_id": "63e0775abd0e063920533f7c"
    },
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": [
                {
                    "age": 66,
                    "birth_year": 1961,
                    "country_id": ""
                }
            ],
            "slice": 2
        }
    ]
}

position

  • Give the index number as 'position' and the data will push at that index.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "_id": "63e0775abd0e063920533f7c"
    },
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": [
                {
                    "age": 66,
                    "birth_year": 1961,
                    "country_id": ""
                }
            ],
            "position": 2
        }
    ]
}

sort

  • To get the sorted response array data use 'sort'.
  • It supports only two values 1 and -1.
  • Here, 1 will sort data in ascending order and -1 will give response data in descending order.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "_id": "63e0775abd0e063920533f7c"
    },
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": [
                {
                    "age": 66,
                    "birth_year": 1961,
                    "country_id": ""
                }
            ],
            "sort": {
                "age": 1
            }
        }
    ]
}

Push - Pull both operation in single payload.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {},
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": {
                "age": 2,
                "birth_year": 1989
            }
        },
        {
            "operation": "pull",
            "path": "ages",
            "queryToRemove": {
                "age": 2,
                "birth_year": 1989
            }
        }
    ]
}

$and use in operation in single payload.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 3
    },
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": {
                "age": 4,
                "birth_year": 3112
            }
        },
        {
            "operation": "pull",
            "path": "ages",
            "queryToRemove": {
                "$and": [
                    {
                        "age": {
                            "$gte": 3
                        }
                    },
                    {
                        "birth_year": 7889
                    }
                ]
            }
        }
    ]
}

$or use in operation in single payload.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 2
    },
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": {
                "age": 4,
                "birth_year": 3112
            }
        },
        {
            "operation": "pull",
            "path": "ages",
            "queryToRemove": {
                "$or": [
                    {
                        "age": {
                            "$gte": 3
                        }
                    },
                    {
                        "birth_year": 7889
                    }
                ]
            }
        }
    ]
}

auto convert String into Number datatype in dataToPush

  • Here age, birth_year, and country_id fields are numbers in API Maker's schema, we provide value in a string.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 1
    },
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": [
                {
                    "age": "5",
                    "birth_year": "1990",
                    "country_id": "2"
                }
            ]
        }
    ]
}

auto convert String into Number datatype in queryToRemove

  • Here age, birth_year, and country_id fields are numbers in API Maker's schema, we provide value in a string.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 1
    },
    "operations": [
        {
            "operation": "pull",
            "path": "ages",
            "queryToRemove": {
                "age": "5",
                "birth_year": "1990",
                "country_id": "2"
            }
        }
    ]
}

auto convert String into Number datatype in dataToPull

  • Here age, birth_year, and country_id fields are numbers in API Maker's schema, we provide value in a string.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 1
    },
    "operations": [
        {
            "operation": "pullAll",
            "path": "ages",
            "dataToPull": [
                {
                    "age": "2",
                    "birth_year": "1989"
                }
            ]
        }
    ]
}

auto convert String into Number datatype in addToSet

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 1
    },
    "operations": [
        {
            "operation": "addToSet",
            "path": "ages",
            "dataToPush": {
                "age": "2",
                "birth_year": "1989"
            }
        }
    ]
}

queryToRemove support object,string,number

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 2
    },
    "operations": [
        {
            "operation": "pull",
            "path": "ages",
            "queryToRemove": {
                "birth_year": 1991
            }
        }
    ]
}

user multiple operation in single payload

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 5
    },
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": {
                "age": 29,
                "birth_year": 1991,
                "country_id": 5
            }
        },
        {
            "operation": "pull",
            "path": "ages",
            "queryToRemove": {
                "age": 30,
                "birth_year": 1992,
                "country_id": 5
            }
        }
    ]
}

auto save/update field if not available in the schema, while performing any operation.

  • Here country_name equals "COLOMBO" not available in the country table, even though data save success.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 4
    },
    "operations": [
        {
            "operation": "push",
            "path": "ages",
            "dataToPush": [
                {
                    "age": 55,
                    "birth_year": 1972,
                    "country_id": {
                        "country_name": "COLOMBO"
                    }
                }
            ]
        }
    ]
}  

auto convert object into a string.

  • "hobbies" field is an array of strings. Here we try to save an object in that. It will convert objects into strings and save them.

URL

/api/schema/user-path/instance/database/table/array-operations
Request Payload
{
    "find": {
        "customer_id": 4
    },
    "operations": [
        {
            "operation": "push",
            "path": "hobbies",
            "dataToPush": [
                {
                    "age": 999,
                    "birth_year": 2500
                },
                4896,
                ["data_type"],
                true,
                45.55
            ]
        }
    ]
}

Supported headers

Header Description
x-am-response-case It will change the response keys text as requested case.
"x-am-response-case": "camelCase"
noChange | camelCase | capitalCase | constantCase | dotCase | headerCase | noCase | paramCase | pascalCase | pathCase | sentenceCase | snakeCase
x-am-response-object-type To get flat response we use this request header.
"x-am-response-object-type": "make_flat"
no_action | make_flat
x-am-meta To get the meta-data of requested API.
"x-am-meta": "true"
false | true
x-am-secret Place secret id from API Maker.
"x-am-secret": "6381b80359bdbd3a87c9abd5"
x-am-internationalization We can get backend error messages in any user language and directly show them to the user in UI, so the user can take appropriate actions.
Provide saved internationalization name in request header.
"x-am-internationalization": "HINDI"
x-am-run-in-sandbox System will try to run requests in maximum provided sandbox, so if 1 provided every request will run in one sandbox, even if we have multiple sandbox with multiple API Maker instances.
"x-am-run-in-sandbox": "0"
x-am-content-type-response We can provide response type in request header. As provided header value we can expect the response type.
"x-am-content-type-response": "application/json"
application/json | text/xml | text/yaml
x-am-cache-control To reset the cache of the requested API manually and get fresh data, we can use 'x-am-cache-control' request header.
"x-am-cache-control": "reset_cache"
no_action | reset_cache
x-am-get-encrypted-data Encrypt response data and get in to the response.
"x-am-get-encrypted-data": "get_data_and_encryption"
no_encryption | get_only_encryption | get_data_and_encryption
x-am-authorization Provide token of API user in "x-am-authorization" header which will be generated from API Users inside API Maker.
"x-am-authorization": "eyJhbGciOiJIUzI1NiIsdlRrblJlcS"
x-am-user-authorization User token should be provided in 'x-am-user-authorization' header which will be generated based on some database user if required.
"x-am-user-authorization": "eyJhbGciOiJIpc1BydlRrblJlcS"
x-aws-authorization Provide AWS Cognito token in request header 'x-aws-authorization', if required.
"x-aws-authorization": "eyJhbGciOiJIUc1BdlRrlJlcS"
x-google-authorization Provide Google user token in request header 'x-google-authorization', if required.
"x-google-authorization": "eyJhbGceyJpc1BdlRrlJlcS"
x-azure-authorization Provide Azure active directory token in request header 'x-azure-authorization', if required.
"x-azure-authorization": "eyJhbGciOiJIUzI1NiIJpc1BdlRrlJlcS"
x-no-compression If user do not send 'x-no-compression' in request header, and response characters are more than value of "maxCharsResToCache" than the response will be compressed.
"x-no-compression": "true"
x-am-sandbox-timeout If any API did not give a response within given time, the sandbox will break and give a proper error message in the response.
"x-am-sandbox-timeout": "13000"  // milliseconds
x-am-encrypted-payload When user sent encrypted payload, user must have to sent "x-am-encrypted-payload:true".
"x-am-encrypted-payload": "true"