Authentication

Keyrails integrates with Auth0 to facilitate secure access and authentication across our APIs. When you make a request to the Auth0 API using the Keyrails tenant credentials, a bearer token will be returned. This token must be included in all future API calls. The server’s response will also include a timestamp, informing you of the bearer token’s expiration time and when a new token must be retrieved.

You will need the client_id located in your dashboard settings. This identifier differs per environment.

Generating access token

Initiate the following API call to obtain your bearer token:

Important. Ensure that Content-Type is application/json.

curl --request POST \
  --url https://auth.sandbox.keyrails.com/oauth/token \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data '{
    "grant_type": "http://auth0.com/oauth/grant-type/password-realm",
    "realm": "Api-Key-Authentication",
    "audience": "https://api.sandbox.keyrails.com/api",
    "client_id": "{{clientId}}", 
    "username": "{{ApiKey}}", 
    "password": "{{ApiSecret}}"
}'
import axios from 'axios';

const options = {
  method: 'POST',
  url: 'https://auth.sandbox.keyrails.com/oauth/token',
  headers: {'Content-Type': 'application/json', Accept: 'application/json'},
  data: {
    grant_type: "http://auth0.com/oauth/grant-type/password-realm",
    realm: "Api-Key-Authentication",
    audience: "https://api.sandbox.keyrails.com/api",
    client_id: "{{clientId}}", // Client Id is located in your dashboard settings
    username: "{{ApiKey}}", // API Key is located in your dashboard settings
    password: "{{ApiKeyPassword}}" // API Key Password is displayed once while generation in the dashboard
  }
};

try {
  const { data } = await axios.request(options);
  console.log(data);
} catch (error) {
  console.error(error);
}

Access token usage

When specifying the access token in the Authorization header, you must include the Bearer prefix. For example, Bearer {{AccessToken}}.

curl --request GET \
  --url https://api.sandbox.keyrails.com/api/v1/accounts \
  --header 'Accept: application/json' \
  --header 'Authorization: Bearer {{AccessToken}}'
import axios from 'axios';

const options = {
  method: 'GET',
  url: 'https://api.sandbox.keyrails.com/api/v1/accounts',
  headers: {
    'Content-Type': 'application/json', 
    Accept: 'application/json', 
    Authorization: 'Bearer {{AccessToken}}}'
};

try {
  const { data } = await axios.request(options);
  console.log(data);
} catch (error) {
  console.error(error);
}