> For the complete documentation index, see [llms.txt](https://docs.octoxlabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.octoxlabs.com/adapters/c/custom-rest-api-devices.md).

# Custom REST API Devices

Custom REST API Devices reads devices from any JSON REST endpoint that you describe with parameters. OctoXLabs uses it to add devices from products that have no dedicated adapter.

## Use cases

* List devices imported from the custom API.

```
Adapters = custom-rest-api-devices
```

* Find imported devices that are missing from Active Directory.

```
Adapters = custom-rest-api-devices AND NOT Adapters = active-directory
```

## Before you begin

### Network

| Source              | Destination                   | Port | Protocol |
| ------------------- | ----------------------------- | ---- | -------- |
| OctoXLabs connector | Your API host (from Base URL) | 443  | HTTPS    |

### Required permissions

| Scope or role                    | Permission | Needed for |
| -------------------------------- | ---------- | ---------- |
| Read access to the list endpoint | Read       | Devices    |

## Create credentials in Custom REST API Devices

{% stepper %}
{% step %}

### Collect the API details

Note the base URL, the endpoint that returns the list, the HTTP method and where the array is in the JSON response.
{% endstep %}

{% step %}

### Choose the authentication

Pick one of `none`, `api_key`, `basic`, `bearer_static` or `bearer_login`. For `bearer_login`, note the login URL, the login body and the path of the token in the login response.
{% endstep %}

{% step %}

### Create a read-only API account

Create credentials in the target product that can read the list endpoint. This adapter does not define a product, so the exact steps depend on your API.
{% endstep %}

{% step %}

### Check pagination

Note whether the API pages by page number or by offset, and the parameter names.
{% endstep %}
{% endstepper %}

## Connection parameters

| Parameter                     | Required            | Type               | Default       | Description                                                                                                                                                                                                                                                                                |
| ----------------------------- | ------------------- | ------------------ | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Base URL                      | Yes                 | Text               |               | Full address of the API with the scheme, for example `https://api.acme.com`. The data path is appended to it.                                                                                                                                                                              |
| Data path                     | Yes                 | Text               |               | Endpoint that returns the list, for example `/api/v1/devices`.                                                                                                                                                                                                                             |
| Data method                   | No                  | Choice (GET, POST) | GET           | HTTP method of the data request.                                                                                                                                                                                                                                                           |
| Data body (JSON)              | No                  | JSON object        |               | Request body sent when Data method is POST.                                                                                                                                                                                                                                                |
| Items path                    | No                  | Text               |               | Location of the array in the response, in dot notation. Leave empty when the response itself is the array. For `{"data": {"items": [...]}}` use `data.items`.                                                                                                                              |
| Hostname field                | Yes                 | Text               |               | Field that identifies the device, in dot notation, for example `host.name`. The code parameter is `primary_key_field`. If empty for a record, the adapter falls back to the mapped MacAddresses, then IpAddresses. Records with none of them are skipped and counted in the discovery log. |
| Field mapping (JSON)          | No                  | JSON object        |               | Maps platform field names (keys) to dot-notation paths in your response (values). Only the allowed keys listed below are accepted.                                                                                                                                                         |
| Authentication type           | No                  | Choice             | none          | `none`, `api_key`, `basic`, `bearer_static` or `bearer_login`.                                                                                                                                                                                                                             |
| API key header                | No                  | Text               | Authorization | Header name for `api_key` authentication.                                                                                                                                                                                                                                                  |
| API key value                 | With api\_key       | Password           |               | API key sent with `api_key` authentication.                                                                                                                                                                                                                                                |
| Username                      | With basic          | Text               |               | Username for `basic` authentication.                                                                                                                                                                                                                                                       |
| Password                      | With basic          | Password           |               | Password for `basic` authentication.                                                                                                                                                                                                                                                       |
| Bearer token                  | With bearer\_static | Password           |               | Token sent in the Authorization header.                                                                                                                                                                                                                                                    |
| Auth URL                      | With bearer\_login  | Text               |               | Full login URL called with `bearer_login`.                                                                                                                                                                                                                                                 |
| Auth method                   | No                  | Choice (GET, POST) | POST          | HTTP method of the login request.                                                                                                                                                                                                                                                          |
| Auth body (JSON)              | No                  | JSON object        |               | Sent to the Auth URL: as the body with POST, as query parameters with GET.                                                                                                                                                                                                                 |
| Token path                    | No                  | Text               | access\_token | Dot-notation path of the token in the login response.                                                                                                                                                                                                                                      |
| Pagination type               | No                  | Choice             | none          | `none` (one request), `page` or `offset`.                                                                                                                                                                                                                                                  |
| Page parameter                | With page           | Text               | page          | Query parameter that holds the page number.                                                                                                                                                                                                                                                |
| Page size parameter           | With page           | Text               | page\_size    | Query parameter that holds the page size.                                                                                                                                                                                                                                                  |
| First page number             | No                  | Number (min 0)     | 1             | Page number of the first request with `page` pagination.                                                                                                                                                                                                                                   |
| Offset parameter              | With offset         | Text               | offset        | Query parameter that holds the offset.                                                                                                                                                                                                                                                     |
| Limit parameter               | With offset         | Text               | limit         | Query parameter that holds the page size.                                                                                                                                                                                                                                                  |
| Page size                     | No                  | Number (1 to 1000) | 100           | Items requested per page.                                                                                                                                                                                                                                                                  |
| Last seen field               | No                  | Text               |               | Dot-notation path of a last seen timestamp.                                                                                                                                                                                                                                                |
| Extra headers (JSON)          | No                  | JSON object        |               | Headers added to every request.                                                                                                                                                                                                                                                            |
| Extra query parameters (JSON) | No                  | JSON object        |               | Query parameters added to every data request.                                                                                                                                                                                                                                              |
| Proxy                         | No                  | Text               |               | Proxy URL.                                                                                                                                                                                                                                                                                 |
| Timeout                       | No                  | Number             | 30            | Seconds to wait for API responses.                                                                                                                                                                                                                                                         |

## Troubleshooting

| Error message                              | Cause                                                        | Fix                                      |
| ------------------------------------------ | ------------------------------------------------------------ | ---------------------------------------- |
| token\_path ... not found in auth response | The login response has no value at Token path.               | Check Token path and the login response. |
| ... required when auth\_type is ...        | A field needed by the selected authentication type is empty. | Fill the listed fields.                  |
| Unknown mapping keys: ...                  | Field mapping has a key that is not allowed.                 | Use only the allowed keys.               |
| must be a JSON object.                     | A JSON field is not a JSON object.                           | Provide a valid JSON object.             |

## Change history
