API Pull Query finds Machines using search conditions and converts their latest States to a predefined output format. Unlike a Pull integration with preselected Machines, it selects targets by name or State each time it is called.

You need a compatible environment, an enabled Integration created by an owner, and available usage quota. If the management screen does not offer this type, confirm availability with your deployment contact. It does not retrieve historical measurements.

## Define and verify the output

1. As an owner, open [Integrations](https://now.obniz.com/integrations), add an Integration, and select `API Pull Query`. Do not select fixed Machines.
2. Enter an Integration name, output schema, and ID, timestamp, and State mappings. Set `latest_only` to `true`.
3. Enter preview States and verify field names, types, and times with `Transform Data`, then save. Saving creates an enabled definition.
4. Open the created definition to check its retrieval URL, and give the caller an API key with Read permission for `integrations`.

Replace `<Integration ID>` and the token, then send this request from your server:

```http
GET /api/1/integrations/<Integration ID>/data?limit=100&offset=0
Host: now.obniz.com
Authorization: Bearer <Account API Token>
```

The response is `{ count, limit, offset, items }`. `items` contains the data converted to your schema.

## Search and paginate

`limit` accepts 1–100 and defaults to 100. `offset` starts at 0. Use `search_filter`, `search_word`, `group_id`, `connection_model`, and `states` as described in [Machine search](../developers/machine-search). URL-encode the JSON in `states`. Unsupported parameters and invalid values return 400.

With `include_null: false`, Machines whose converted result is null are omitted from `items`. `count` is the number of matches before conversion. More pages may therefore remain even when `items.length` is below `limit` or zero. Determine the next page using the returned `offset + limit` and `count`. Zero and `false` are not missing values.

## Quotas and errors

Each successfully retrieved page consumes Integration quota equal to the number of entries in `items`. Retained nulls count as entries; excluded nulls and empty pages do not. If the remaining quota cannot cover the complete page, the request returns 402 without charging for it. Reduce `limit` and try again. Every successful repeated retrieval is charged again.

| HTTP status | Action |
| --- | --- |
| 400 | Correct parameters, JSON format, or definition settings |
| 402 | Check quota and adjust request frequency or contract |
| 403 | Check that the Integration is enabled and permissions are sufficient |
| 404 | Check the ID and Account; another Account's definition is inaccessible |

Latest States can change between page requests. The complete result is not necessarily a snapshot from one instant.
