Authentication
The Cash App Afterpay Online API uses two different authentication options, which are discussed below. With the exception of Ping, all Online API endpoints require that one of these forms of authentication are used. Failure to correctly authenticate an API request will result in a 401 Unauthorized
response.
Basic auth
The first authentication method is Basic HTTP Authentication, a simple authentication scheme built into the HTTP protocol, as specified by RFC 7617.
Example request
HTTP
cURL
Node.js
Ruby
Python
Consider the following example:
In conventional HTTP terms, “Merchant ID” is the username and “Secret Key” is the password. Afterpay provides merchant accounts per region, and each merchant account has unique API credentials.
The credentials are joined by a colon character (without any spaces), then base64-encoded.
The Authorization
header can then be formed by including the word Basic
, followed by a single space character, followed by the base64-encoded credential pair.
Security Notice
The base64-encoding of the Authorization header is unrelated to security. All HTTP headers and bodies (for both requests and responses) between the Merchant and Afterpay are encrypted with TLS. The reason for base64-encoding is solely to comply with the RFC 7617 standard, which allows non-HTTP characters and multibyte strings to be used for Basic HTTP Authentication.
Bearer tokens
The Client Credentials Authentication method is another authentication method available to merchants. It is a secure mechanism used to obtain access tokens which is defined in RFC 6749.
When using this method, a client application uses its unique credentials to fetch an access token, which enables it to access Cash App Afterpay’s online APIs.
Token URLs
Tokens are generated using separate URLs from those described in the API environments
OAuth Endpoint Production
OAuth Endpoint Sandbox
Example request
The following examples use the same credentials as the Basic Auth section.
The scopes
field mentioned below is merchant_api_v2
, but merchant_api_v1
may be used to access the first version of the merchant APIs.
Access token request
Access token response
The response to a successful authentication request includes the full JWT access_token
. In the example below, the token is shortened for brevity.
The field expires_in
is the time (in seconds) that the token is valid from when its generated. The token is not usable after this time elapses.
API requests with token
See the following example where the access_token
field is provided in the Authorization
header of the request to access a secure API:
Basic
, the token authentication method uses Bearer
. Omitting this value or setting it to something else will return an HTTP status code of 401 Unauthorized