Skip to main content

Quickstart

What you will build​

You exchange the client ID and secret of a test environment for an access token, then use the token to make your first successful call: a list of the customers of the test environment.

Before you start​

You need a client ID and a client secret for the test environment of an account. You receive your client ID and secret from Black when your account is set up. A secret is shown once, so keep it in an environment variable of your server. Never put it in browser or mobile code.

You need a tool that sends HTTP requests. The samples use cURL.

Steps​

  1. Check that your request reaches Black. Send a GET request to /v1/ping. It needs no credentials. The response is 200 OK and holds the version of the API. See Ping.

    curl https://api.black.example/v1/ping
  2. Exchange your client ID and secret for an access token. Send a POST request to /v1/oauth/token with the form fields grant_type, set to client_credentials, client_id and client_secret. The response holds the access_token, which lasts one hour:

    curl --request POST https://api.black.example/v1/oauth/token \
    --data grant_type=client_credentials \
    --data client_id=PLACEHOLDER_CLIENT_ID \
    --data client_secret=PLACEHOLDER_CLIENT_SECRET
  3. Make your first call with the token. Send a GET request to /v1/customers with the header Authorization: Bearer <access token>. The response is 200 OK and holds a list of the customers of the test environment. The list is empty in a new environment.

    curl https://api.black.example/v1/customers \
    --header "Authorization: Bearer PLACEHOLDER_ACCESS_TOKEN"

A token of a test environment reaches the test data of its account and nothing else. See Authentication for the refusals, the lifetime of a token and the rate limits.

A runnable sample​

The sample gets a token and lists the customers. It writes PLACEHOLDER_CLIENT_ID and PLACEHOLDER_CLIENT_SECRET where your own values go, and reads the token from the first response. It needs sed.

TOKEN=$(curl --silent --request POST https://api.black.example/v1/oauth/token \
--data grant_type=client_credentials \
--data client_id=PLACEHOLDER_CLIENT_ID \
--data client_secret=PLACEHOLDER_CLIENT_SECRET \
| sed -n 's/.*"access_token":"\([^"]*\)".*/\1/p')

curl --silent --request GET https://api.black.example/v1/customers \
--header "Authorization: Bearer $TOKEN"

What to do next​

  • Read what an account can do in the guides.
  • Read how to retry a write safely in Idempotency.
  • Move to a live environment when you are ready: it has its own client ID and secret.