Skip to main content

API credentials

A common pattern when interacting with APIs is authentication. There are several ways to authenticate using the api command.

--headers​

The --headers flag can be used to pass in Authorization or other credential related headers along with a request.

Example​

api get http://{AUTHENTICATED API} --headers '{"Authorization": "Bearer {TOKEN}"}'

NOTE When using API tokens, it is a best practice to configure the token as a custom credential and use the $CREDENTIAL.*$ internal token syntax to reference it. This avoids having the credential in plaintext as a part of the query.

--bearer​

The --bearer flag is a simplified way of providing a bearer token without needing to construct a full set of headers

NOTE When using API tokens, it is a best practice to configure the token as a custom credential and use the $CREDENTIAL.*$ internal token syntax to reference it. This avoids having the credential in plaintext as a part of the query.

Example​

api get http://{AUTHENTICATED API} --bearer {TOKEN}

is equivalent to

api get http://{AUTHENTICATED API} --headers '{"Authorization": "Bearer {TOKEN}"}'

--oauth​

The --oauth flag requires a configured OAuth credential. Once configured, you can use the credential name to authenticate through the Client Credentials OAuth flow using the configured Client Id/Secret.

Example​

api get http://{AUTHENTICATED API} --oauth "{OAUTH CREDENTIAL NAME}"