Learning to use Cortex
Before you do anything, take a look at our Request Entry Points to get a basic understanding of how to access Cortex resources. Then follow the steps outlined below to make your first Cortex call to retrieve a customer’s cart.
Step 1: Get an Access Token
Start by getting a Cortex access token. All customers, both Public customers (customers without an account) and Registered customers (customers with an account), require access tokens. Without an access token, the client application will receive a 401 Unauthorized
response when it tries to access a resource.
To get an access token, follow the directions in these sections:
- For customers with an account: Authenticate a Customer
- For customers without an account: Generate a Public OAuth Token
Step 2: Prepare a Request
Prepare the following request to retrieve the customer’s cart.
Construct a GET
request to the carts resource, setting the content-type to application/json
, and the requests authorization
header to Bearer with the customer’s access key.
Content-Type: application/json
Authorization: Bearer c7326d79-9273-4820-b45d-587f90d1dc9b
GET http://api.elasticpath.net/cortex/carts/mobee/default
Step 3: Make API Calls
The user’s cart returns in a JSON
object in the response body:
{
"self": {
"type": "elasticpath.carts.cart",
"uri": "/carts/mobee/guz=",
"href": "http://api.elasticpath.net/cortex/carts/mobee/guz="
},
"total-quantity": 0,
"links": [
{
"type": "elasticpath.totals.total",
"rel": "total",
"rev": "cart",
"href": "http://api.elasticpath.net/cortex/totals/carts/mobee/guz=",
"uri": "/totals/carts/<scope>/<cartid>"
},
{
"type": "elasticpath.orders.order",
"rel": "order",
"rev": "cart",
"href": "http://api.elasticpath.net/cortex/orders/carts/mobee/guz=",
"uri": "/orders/carts/mobee/guz="
},
{
"type": "elasticpath.collections.links",
"rel": "lineitems",
"rev": "cart",
"href": "http://api.elasticpath.net/cortex/carts/mobee/guz=/lineitems",
"uri": "/carts/mobee/guz=/lineitems"
}
]
}
Now that you’ve made your first API call, the rest is up to you! Remember, all your calls require an access token, so make sure to include it in the response header.
Recommended Reading for Getting Started
To get a better understanding of how our API works, we recommend reading the following:
- API Basics - This section describes the basics components of our API, such as Resources, Request Methods, Request Entry Points, and so on
- Add an Item to a Cart - Describes the calls required to add an item to a customer’s cart
- Purchasing: From Start to Finish - Describes an overview of a basic purchase workflow
- Resource Reference Guide - Lists all Cortex resources, methods, and response fields