🚀 'GET' API in API Maker
Tags: api, programming, backend, nocodesolution
Published: 2023-08-18 05:39:52

Get APIs in detail made by API Maker
https://youtu.be/L8GqKGGEQjo
check YouTube video

Sample data table

| customer_id | first_name | last_name | last_update           | pincode | isActive |
|-------------|------------|-----------|-----------------------|---------|----------|
| 1           | Bob        | lin       | 2022-11-14 04: 34: 58 | 382345  | 1        |
| 2           | Alice      | Page      | 2022-10-15 02: 10: 40 | 382346  | 1        |
| 3           | Mallory    | Brown     | 2022-09-13 03: 44: 05 | 382347  | 1        |
| 4           | Eve        | Mathly    | 2022-11-12 01: 59: 33 | 382348  | 1        |
| 5           | Eve        | Page      | 2022-11-12 01: 59: 33 | 382349  | 1        |


## **GET ALL API**

To get all the data of the collection/table use SCHEMA_GET_ALL API. API Maker provides multiple query params and headers options while getting all data.

URL
```
/api/gen/user-path/instance/database/table
```

- 'user-path' is the given API Maker user's API_PATH.
- 'instance' contains the instance name.
- 'database' contains the database name.
- 'table' contains the table/collection name.

Get by any field
```
/api/gen/user-path/instance/database/table?customer_id=1
```
You will get data which has 'customer_id' column value 1.

Get by multiple fields
```
?first_name=Bob&last_name=lin
```
You will get data which has 'first_name' column value 'Bob' and 'last_name' column value is 'lin'.


### Supported query params
Here, API Maker supports below query parameters,


| Key                                             | Value                                                           |
|-------------------------------------------------| --------------------------------------------------------------- |
| **[find](https://docs.apimaker.dev/v1/docs/apis-all/query-params/find.html)** | ?find={first_name:'Bob'}                                        |
| **[skip](https://docs.apimaker.dev/v1/docs/apis-all/query-params/skip.html)** | 2                                                               |
| **[limit](https://docs.apimaker.dev/v1/docs/apis-all/query-params/limit.html)**           | 2                                                               |
| **[sort](https://docs.apimaker.dev/v1/docs/apis-all/query-params/sort.html)**           | customer_id                                                     |
| **[select](https://docs.apimaker.dev/v1/docs/apis-all/query-params/select.html)**         | ?select=first_name,customer_id                                  |
| **[deep](https://docs.apimaker.dev/v1/docs/apis-all/query-params/deep.html)**             | ?deep=[{s_key:'customer_id,t_col: 'products',t_key:'owner_id'}] |
| **[getTotalCount](https://docs.apimaker.dev/v1/docs/apis-all/query-params/getTotalCount.html)** | true                                                            |

#### Find
valid JSON support for fetching data using find.

[JSON 5 support](https://json5.org/)

- It will return documents/rows as per JSON condition.

```text
?find={first_name:'Bob'}
```
```text
?find={first_name:{$in:['Bob','Alice']}}
```
```text
?find={customer_id:{$gte:3}}
```


#### Skip data

- It will skip the first 10 documents/rows.

```text
?skip=10
```

- It will skip the first 2 documents/rows having pinCode equals "382345"

```text
?pinCode=382345&skip=2
```

#### Limit data

- It will return only 10 documents/rows having first_name equals "Bob"

```text
?first_name=Bob&limit=10
```

#### Sort data

- It will sort documents/rows in order of ascending or descending

ascending
```text
?sort=customer_id
```

descending
```text
?sort=-customer_id
```

#### Select data

- It will return only first_name and last_name in response

```text
?select=first_name,last_name
```

#### Deep data

- It will return documents/rows from multiple table combinations.

```text
?deep=[{s_key:'customer_id,t_col: 'products',t_key:'owner_id'}]
```
Here,

    s_key = Source collection/table field
    t_col = Target collection/table name
    t_key = Target collection/table field

- also use multiple query params [skip, limit, sort, find, etc...] in a single deep query.

```text
?deep=[{s_key:'customer_id',t_col:'products',t_key:'owner_id',skip:1,isMultiple:true,limit:5,sort:'name',find:{category_id:{$in:[56572,89355]}}}]
```

#### GetTotalCount data

- It will return an additional parameter of 'totalCount' which indicate the total number of documents/rows get in to the response.

```text
?getTotalCount=true
```


### Supported headers


<table>
    <tr>
        <th>Header</th>
        <th>Description</th>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-response-case">x-am-response-case</a></td>
        <td>
            It will change the response keys text as requested case.
            ```json
            "x-am-response-case": "camelCase"
            ```
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#nochange-response">noChange</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#camelcase-response">camelCase</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#capitalcase-response">capitalCase</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#constantcase-response">constantCase</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#dotcase-response">dotCase</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#headercase-response">headerCase</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#nocase-response">noCase</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#paramcase-response">paramCase</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#pascalcase-response">pascalCase</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#pathcase-response">pathCase</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#sentencecase-response">sentenceCase</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#snakecase-response">snakeCase</a>
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-response-object-type">x-am-response-object-type</a></td>
        <td>
            To get flat response we use this request header.
            ```json
            "x-am-response-object-type": "make_flat"
            ```
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#no-action">no_action</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#make-flat">make_flat</a>
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-meta">x-am-meta</a></td>
        <td>
            To get the meta-data of requested API.
            ```json
            "x-am-meta": "true"
            ```
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#false">false</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#true">true</a>
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-secret">x-am-secret</a></td>
        <td>
            Place secret id from API Maker.
            ```json
            "x-am-secret": "6381b80359bdbd3a87c9abd5"
            ```
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-internationalization">x-am-internationalization</a></td>
        <td>
            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.
            <br>
            Provide saved internationalization name in request header.
            ```json
            "x-am-internationalization": "HINDI"
            ```
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-run-in-sandbox">x-am-run-in-sandbox</a></td>
        <td>
            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.
            ```json
            "x-am-run-in-sandbox": "0"
            ```
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-content-type-response">x-am-content-type-response</a></td>
        <td>
            We can provide response type in request header. As provided header value we can expect the response type.
            ```json
            "x-am-content-type-response": "application/json"
            ```
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#applicationjson">application/json</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#textxml">text/xml</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#textyaml">text/yaml</a>
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-cache-control">x-am-cache-control</a></td>
        <td>
            To reset the cache of the requested API manually and get fresh data, we can use 'x-am-cache-control' request header.
            ```json
            "x-am-cache-control": "reset_cache"
            ```
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#no-action-to-cache">no_action</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#reset-cache">reset_cache</a>
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-get-encrypted-data">x-am-get-encrypted-data</a></td>
        <td>
            Encrypt response data and get in to the response.
            ```json
            "x-am-get-encrypted-data": "get_data_and_encryption"
            ```
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#no-encryption">no_encryption</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#get-only-encryption">get_only_encryption</a> |
            <a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#get-data-and-encryption">get_data_and_encryption</a>
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-authorization">x-am-authorization</a></td>
        <td>
            Provide token of API user in "x-am-authorization" header which will be generated from API Users inside API Maker.
            ```json
            "x-am-authorization": "eyJhbGciOiJIUzI1NiIsdlRrblJlcS"
            ```
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-user-authorization">x-am-user-authorization</a></td>
        <td>
            User token should be provided in 'x-am-user-authorization' header which will be generated based on some database user if required.
            ```json
            "x-am-user-authorization": "eyJhbGciOiJIpc1BydlRrblJlcS"
            ```
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-aws-authorization">x-aws-authorization</a></td>
        <td>
            Provide AWS Cognito token in request header 'x-aws-authorization', if required.
            ```json
            "x-aws-authorization": "eyJhbGciOiJIUc1BdlRrlJlcS"
            ```
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-google-authorization">x-google-authorization</a></td>
        <td>
            Provide Google user token in request header 'x-google-authorization', if required.
            ```json
            "x-google-authorization": "eyJhbGceyJpc1BdlRrlJlcS"
            ```
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-azure-authorization">x-azure-authorization</a></td>
        <td>
            Provide Azure active directory token in request header 'x-azure-authorization', if required.
            ```json
            "x-azure-authorization": "eyJhbGciOiJIUzI1NiIJpc1BdlRrlJlcS"
            ```
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-no-compression">x-no-compression</a></td>
        <td>
            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.
            ```json
            "x-no-compression": "true"
            ```
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-sandbox-timeout">x-am-sandbox-timeout</a></td>
        <td>
            If any API did not give a response within given time, the sandbox will break and give a proper error message in the response.
            ```json
            "x-am-sandbox-timeout": "13000"  // milliseconds
            ```
        </td>
    </tr>
    <tr>
        <td><a href="https://docs.apimaker.dev/v1/docs/apis-all/header/requestHeader.html#x-am-sandbox-timeout">x-am-encrypted-payload</a></td>
        <td>
            When user sent encrypted payload, user must have to sent "x-am-encrypted-payload:true".
            ```json
            "x-am-encrypted-payload": "true"
            ```
        </td>
    </tr>
</table>

## **GET ALL BY STREAM API**

- The only difference between 'get_all' and '[get_all_by_stream](https://docs.apimaker.dev/v1/docs/apis-all/schema-apis/auto-generated-schema-based-get-all-by-stream-api.html)' API is that the stream API uses a streaming technique to send data from the server.  When we are required to get huge amounts of data this API is used to send data in small chunks so the server will not have high memory spikes and the user can get data continuously.

## **GET BY ID API**

- Provide two params 'id' and 'primaryKey'. This API always return a single document/row. [more details](https://docs.apimaker.dev/v1/docs/apis-all/schema-apis/auto-generated-schema-based-get-by-id-api.html)

URL
```
/api/schema/user-path/instance/database/table/get-by-id/4
```

### Override default primary key

```
/api/schema/user-path/instance/database/table/get-by-id/382348/pincode
```

- It will return a document/row having pincode 382348.
- In the above request 'pincode' is the overridden primary key and 382348 is the primary key value.

### Supported query params

| Key                                                         | Value                                                           |
|-------------------------------------------------------------| --------------------------------------------------------------- |
| **[select](https://docs.apimaker.dev/v1/docs/apis-all/query-params/select.html)**                     | ?select=first_name,customer_id                                  |
| **[deep](https://docs.apimaker.dev/v1/docs/apis-all/query-params/deep.html)**                        | ?deep=[{s_key:'customer_id,t_col: 'products',t_key:'owner_id'}] |

### Supported headers
- All the headers which are available in the 'get_all' API will be supported in the 'get_by_id'.


## **Query for get data API**

URL
```
/api/schema/user-path/instance/database/table/query
```

The request method of this API is POST. User need to provide payload to use this API. The body supports find, sort, skip, limit, select, deep, getTotalCount, groupBy keywords.

Sample request payload
```json
{
    "find": {
        "owner_id": {
            "$in": [1, 2, 3]
        }
    },
    "skip": 1,
    "limit": 4,
    "sort": "price",
    "select": "name, owner_id, id, price",
    "deep": [
        {
            "s_key": "owner_id",
            "t_instance": "mysql",
            "t_db": "inventory",
            "t_col": "customers",
            "t_key": "customer_id",
            "find": {
                "first_name": "Billy"
            },
            "isMultiple": true,
            "limit": 10,
            "select": "customer_id,first_name",
            "skip": 2,
            "sort": "first_name"
        }
    ],
    "getTotalCount": true,
    "groupBy": "name"
}
```

### Circular dependency
In API Maker if the user creates a circular dependency error to get deep data by mistake it will never make an issue any how.

Request payload
```json
{
    "deep": [
        {
            "s_key": "owner_id",
            "t_col": "customers",
            "t_key": "customer_id",
            "deep": [
                {
                    "s_key": "customer_id",
                    "t_col": "products",
                    "t_key": "owner_id",
                    "select": "owner_id",
                    "deep": [
                        {
                            "s_key": "owner_id",
                            "t_col": "customers",
                            "t_key": "customer_id",
                            "select": "customer_id"
                        }
                    ]
                }
            ]
        }
    ]
}
```

#### Deep inheritance

Request payload
```json
{
    "deep": [
        {
            "s_key": "price",
            "t_col": "orders",
            "t_key": "total",
            "select": "pincode",
            "deep": [
                {
                    "s_key": "shipping_id",
                    "t_col": "customers",
                    "t_key": "shipping_id",
                    "select": "phone"
                },
                {
                    "s_key": "shipping_id.pincode",
                    "t_col": "orders",
                    "t_key": "pincode"
                }
            ]
        }
    ]
}
```
#### find join example

- Set instance, database, collection and column in [schema](https://docs.apimaker.dev/v1/docs/schema/schema.html) of the collection and provide only source key(s_key) to get deep data. [more details](https://docs.apimaker.dev/v1/docs/apis-all/schema-apis/auto-generated-schema-based-query-for-get-data-api.html#request-method-post).

```json
{
    find: {
        "first_name.customer_id.shipping_id": 2
    }
}
```


## **Query for get data by stream API**

- The only difference between 'query_for_get_data' and '[query_for_get_data_by_stream](https://docs.apimaker.dev/v1/docs/apis-all/schema-apis/auto-generated-schema-based-query-for-get-data-by-stream-api.html)' APIs are that the stream API uses a streaming technique to send data from the server.  When we are required to get huge amounts of data this API is used to send data in small chunks so the server will not have high memory spikes and the user can get data continuously.

---


To get more information about APIs please refer [API Maker documentation](https://docs.apimaker.dev/v1/docs/apis-all/generated-apis/auto-generated-get-all-api.html).

Websites
https://apimaker.dev
https://cloud.apimaker.dev

Follow on twitter
https://twitter.com/api_maker

Linked In
https://www.linkedin.com/company/api-maker

Youtube Quick introduction video
https://youtu.be/_c6kEJJgfAw