Conventions
emnify provides a RESTful API.
Communication with the API is done over HTTP(S) requests with JSON request body with application/json content-type and an authentication token as a requirement for every API call.
The API is defined in detail in the following section, but here are some highlights:
- Lookup values are accessed at the same level as the resource they describe.
For example, the URL to retrieve the list of possible statuses of an endpoint is
/api/v1/endpoint/status. - Collection responses aren’t wrapped in an envelope. Instead the result metadata is returned in the header of the response.
- Paging, filtering sorting of large datasets are managed via query parameters of GET requests.
- The API provides complex error messages capable of reporting a set of errors.
- The API implicitly provides multi-tenancy management. The server limits the visibility of the data and available operations based on the organization of the user identified by authentication token.
- When associating an existing objects to a collection, it’s sufficient to provide only the objects IDs.
The following service pattern is provided for all major resources:
The word endpoint, typically used in RESTful API definitions has a particular meaning in the emnify application domain. To avoid confusion, the word endpoint is used in this documentation to identify endpoint entities (resources) of the emnify System domain while the word entrypoint is used to identify generic RESTful API endpoints.
Securing the API
The API is secured through usage of JSON Web Tokens (JWT) which are an open standard (RFC 7519) for representing claims securely between two parties.
The server generates JWT tokens for accessing the API (further referenced as ‘authentication token’) for users or applications after they present verifiable credentials.
Once the credentials are exchanged for an authentication token on the server, the client has to submit it within the HTTP Authorization header in each subsequent request.
The system validates the rights and permissions of the requesting user/application by parsing the token’s content.
The authentication token expires after 240 minutes. Therefore the authentication needs to be performed again to obtain a new authentication token.
If the authentication token is missing, invalid, or expired, the API returns 401 Unauthorized response status.
If a client tries to access resources that exists, but the client doesn’t have the permissions or the rights to access it, the API returns either 403 Forbidden or 404 Not Found.
These requirements are general and aren’t repeated in the remainder of this API specification.
Connection
All API calls including the authentication must be made over secure socket (SSL).
The server responds to API request in gzip compressed format with the following header:
URL format
All API URLs follow a generic structure:
For example:
Some resources may also provide access to further sub-resources:
HTTP guidelines
HTTP verbs
Here is the definition of HTTP verbs used in the API with description and typical responses upon request to collection entrypoint and single resource entrypoint.
HTTP headers
Request headers
Each HTTP request must have at least the following headers:
- Content-Type:
application/json - Accept:
application/json - Authorization:
Bearer AUTH_TOKEN
Response headers
The API uses header to transfer meta information about the returned result. The usage varies depending on the operation. The details are available within the specification of particular resource description:
HTTP return codes
Timestamps
Unless otherwise specified, you can expect timestamps returned by the emnify REST API to be ISO 8601-encoded date and time strings in the UTC (Coordinated Universal Time) time zone.
2023-03-06- Date in YYYY-MM-DD formatT- Represents time11:15:57.000- Time in HH:mm:ss.sss format+0000- Offsets the time 0 hours from UTC