1. Authentication

Requests to Moltin require an Authorization header containing your Bearer token. There are two token types; implicit and client_credentials. See Authentication for more details.

This guide will use the implicit grant type. This grant type can be thought of as READ ONLY and most commonly used client side.

Get your API keys

Head to the Moltin Dashboard, sign in, select your project and make a copy of your client_id.

Get an access token

Using the client_id, we can now make our very first API request. Inside your Terminal or command-line equivalent, make the following request:

curl -X POST https://api.moltin.com/oauth/access_token \
-d "client_id=XXXX" \
-d "grant_type=implicit"

A successful request will respond with something similar to:

{
"expires": 1537779121,
"identifier": "implicit",
"expires_in": 3600,
"access_token": "0e82127a8d9c20abb3d6e48561cbfe81448956ab",
"token_type": "Bearer"
}

Congratulations! 🙌

Now you'll want to make a copy of your access_token. This is your implicit Bearer token that is required for future requests.

You'll need to re-authenticate when the access_token expires.

Make a request with your access token

Let's go ahead and request a new Cart. We'll use the unique reference abc for the Cart. We'll need this when requesting the items, adding items and checking out.

Replace XXXX below with your access_token from above.

Inside your command-line, run the following cURL request:

curl https://api.moltin.com/v2/carts/abc \
-H "Authorization: Bearer XXXX"

You'll receive a response similar to:

{
"data":{
"id":"a054e10e-5fb7-4a76-a496-c59638d45939",
"type":"cart",
"links":{
"self":"https://api.moltin.com/carts/a054e10e-5fb7-4a76-a496-c59638d45939"
},
"meta":{
"display_price":{
"with_tax":{
"amount":0,
"currency":"",
"formatted":"0"
},
"without_tax":{
"amount":0,
"currency":"",
"formatted":"0"
}
},
"timestamps":{
"created_at":"0001-01-01T00:00:00Z",
"updated_at":"0001-01-01T00:00:00Z"
}
}
}
}

Now that we have successfully authenticated and retrieved a Cart, in the next lesson we will add a custom item to the Cart.