Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Generate a Public OAuth Token

Generate a Public OAuth Token

An access token is required for applications to access Cortex API. To use the API or build an application that doesn't require the end user to create an account or authenticate, the client application should request a public access token. This access token enables access to resources that don't require a registered account.

Requesting an access token

Below is an example of the authentication workflow for requesting a PUBLIC access token from the client application's perspective.

  1. Construct a POST request to the OAuth2 Resource and set the content-type to application/x-www-form-urlencoded
    Content-Type: application/x-www-form-urlencoded
  2. Include the following parameters in the request body
    Note: Username and Password not Used

    Usernames and Passwords are not used in this scenario. To generate a token to access resources that require a registered account, see Authenticate a customer.

  3. The Cortex API authenticates the request and returns either a success or failure HTTP response. Successful authentication returns the following HTTP response:
       "access_token": "a9256d79-9273-4820-b45d-587f90d1dc9b",
       "expires_in": 359,
       "scope" : "MOBEE",
       "role": "PUBLIC"
    Unsuccessful authentication returns a 401 status code and an error message.

Using an access token

Once a token is granted, all subsequent requests to Cortex API must include the access token in an Authorization request header. If the access token is invalid, does not exist in the Authorization request header, or the user does not have the authority to access a resource, Cortex API returns a 401 status code

Add the access token to your request headers as shown in the example below:

Content-Type: application/json
Authorization: Bearer a9256d79-9273-4820-b45d-587f90d1dc9b
Note: Token Type

You must use Bearer in the Authorization header. This is an OAuth 2.0 standard.

Revoking an access token

Revoke an access token by calling DELETE on the OAuth2 Resource. Include the access token to revoke in the Authroization request header.

Authorization: Bearer a9256d79-9273-4820-b45d-587f90d1dc9b

Access token validity and expiration

Access tokens are immediately valid once they are returned to the client application. Tokens are valid for 1 week, after which they expire and are no longer valid for access.