Skip to content

Using the API

Clio Brichaut edited this page Jan 14, 2023 · 1 revision

Here's how to make a request to the API and use its response.

The illustrations were made using Insomnia (https://insomnia.rest/) and Swagger (http://localhost/api/documentation)

Requests

Headers

  • All requests must include the Accept: application/json header.
  • POST, PUT and PATCH requests must also include the Content-Type: application/json header.

If omitted, the API will return this 400 Bad Request error:

{
	"success": false,
	"errors": {
		"MISSING_HEADER_ACCEPT": "Requests to the API must include the \"accept = application\/json\" header.",
		"MISSING_HEADER_CONTENT_TYPE": "POST, PUT and PATCH requests to the API  must include the \"content-type = application\/json\" header."
	}
}
Add the headers manually in your script or API tool (e.g. Insomnia)
image
Swagger takes care of the headers itself, you just need to hit "Execute"
image

Authentication

All endpoints except the authentication ones (i.e. /api/auth/sign-up and /api/auth/sign-in) must include a valid bearer token obtained from a successful sign-up or sign-in request.

If omitted, the API will return this 401 Unauthorized error:

{
	"message": "Unauthenticated."
}
Adding the token in Insomnia
image
In Swagger, click "Authorize" in the top right corner of the page, then type "Bearer " followed by the token
image

Payloads

When required, payloads must be in JSON format.

A missing or invalid payload will return a 400 Bad Request error.

Swagger provides a payload example for each endpoint.
image
Swagger also provides the list of potential 400 errors for each endpoint.
image

Responses

All responses are formated in JSON (except when downloading a .csv report).

Swagger provides an example of a successful response's content for each endpoint.
image

Clone this wiki locally