TLDR: API requests are authorized using bearer tokens. Generating a token requires FlatPeak account_id and API key. Get both in Dashboard and obtain a token at login endpoint.
FlatPeak uses Bearer authentication (also called token authentication) to authorize access to API endpoints. This is an HTTP authentication scheme that involves security tokens called bearer tokens. The name “Bearer authentication” can be understood as “giving access to the bearer of this token.” The bearer token is a cryptic string, usually generated by the server in response to a login request. The client must send this token in the Authorization header when making requests to protected resources.
Follow two simple steps below to start making requests to FlatPeak API endpoints:
1
Get an API key
You can create, view and delete API keys in API keys section of FlatPeak Dashboard. You can create multiple keys so you can use separate keys at various parts of your service and perform key rotation without interrupting the operation of your service.
Never place your API keys at a location where they can be accessed by unauthorised personnel, your website visitors or the general public.
2
Create a bearer token
To make requests to FlatPeak API endpoints you first need to generate a bearer_token at the login endpoint. This endpoint uses HTTP Basic Authentication. The username is your FlatPeak account_id and the password is the api_key.
Bearer token request
curl--request GET \--url https://api.flatpeak.com/login \--header'Authorization: Basic base64(account_id:api_key)'
Bearer token returned by FlatPeak API
{"bearer_token":"<token>","expires_in":3600}
You can use the bearer_token to make calls to any FlatPeak API endpoints until it expires. The expiry time is returned together with the token in the expires_in field. Get a new token before the one you are using expires to avoid failed requests.