Quick start
Authenticate with a System API token and read your first records from the Servicely REST API.
Make your first call to the REST API: authenticate with a token, read a page of records and check the paging headers. Do this before you build an integration, to confirm the token, the user and the network path work.
Before you begin
- An administrator with the
api_token_administratororadministratorrole has created a System API token for you with the validation type None (Bearer token in Header). See Create a System API token in the Administrator guide. - The token’s Impersonate user can read the
Usertable. Every request runs as this user. - If the token has Allowed Scopes, they include REST API (v1).
- You know your instance URL, for example
https://<instance>.servicely.ai. - You have an HTTP client. The examples use curl.
Steps
-
Store the token in an environment variable so it stays out of your shell history and scripts.
export SERVICELY_TOKEN='<token>' -
Request one user record. Send the token in the
Authorizationheader with theBearerscheme.curl -i "https://<instance>.servicely.ai/v1/User?fields=id,Name&page_size=1" \ -H "Authorization: Bearer $SERVICELY_TOKEN" -
Check the status line. A 200 means the call worked. A 401 means the token was not accepted: check the header and that the token is active. A 404 means no record matched.
-
Read the body. The records are in the
dataarray, with only the fields you named infields.{ "data": [ { "Name": "<user name>", "id": "00000000000000000000000000000110" } ] } -
Read the paging headers.
X-Total-Result-Countis the number of matching records andX-Result-More: truemeans more pages follow.X-Page: 1 X-Page-Size: 1 X-Result-Count: 1 X-Result-More: true X-Total-Result-Count: 14 -
Fetch the same record by its ID to read a single record. The
datakey now holds one object instead of an array.curl "https://<instance>.servicely.ai/v1/User/00000000000000000000000000000110?fields=id,Name,Email" \ -H "Authorization: Bearer $SERVICELY_TOKEN"
Result
You have read records through the REST API as the token’s user. The same URL pattern, /v1/<Table> and /v1/<Table>/<id>, serves every table the user can read.
Basic authentication with a username and password also works, unless an administrator has turned it off. For requests that must prove they were not changed in transit, sign them with HMAC instead of sending a bearer token.