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
-
Check that your request reaches Black. Send a
GETrequest to/v1/ping. It needs no credentials. The response is200 OKand holds the version of the API. See Ping.curl https://api.black.example/v1/ping -
Exchange your client ID and secret for an access token. Send a
POSTrequest to/v1/oauth/tokenwith the form fieldsgrant_type, set toclient_credentials,client_idandclient_secret. The response holds theaccess_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 -
Make your first call with the token. Send a
GETrequest to/v1/customerswith the headerAuthorization: Bearer <access token>. The response is200 OKand 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.