You are on page 1of 2

How to request an Authentication Token in OCAPI

Objective This article provides the different OCAPI requests to get an Authentication Token on Sandboxes environment with testing client id aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.
You will need to change your credentials to adapt to PIG instances.

Environment Instance Type: Sandboxes

Procedure There are 3 different levels of permission:

1. Account Manager
2. Business Manager user
3. Storefront user

1. Guest
2. Logged in

Depending the level of permission the user will not access to all the resources.

Account Manager grant access

POST https://account.demandware.com/dw/oauth2/access_token

Authorization: Basic client_id:client_pwd (encoded in base 64)

Account Manager Authorization Account Manager Authorization Sample Client (for Sandboxes)

client_id:client_pwd aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

grant_type=client_credentials

Curl:
Request:
curl -X POST \
https://account.demandware.com/dw/oauth2/access_token \
-H 'authorization: Basic YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhOmFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==' \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'grant_type=client_credentials'

Result:
{"access_token":"ab5a05d0-a077-4cd1-8429-ba8295b77a06","scope":"mail","token_type":"Bearer","expires_in":1799}

Business manager grant access

POST https://example.com/dw/oauth2/access_token?client_id=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Authorization: Basic User Login:User Password:Client Password (encoded in base 64)

BM Authorization BM Authorization Sample

userlogin:userpwd:client_pwd admin:pwd123:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

grant_type=urn:demandware:params:oauth:grant-type:client-id:dwsid:dwsecuretoken

Curl:
Request:
curl -X POST \
'https://example.demandware.net/dw/oauth2/access_token?client_id=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' \
-H 'authorization: Basic YWRtaW46cHdkMTIzOmFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==' \
-H 'content-type: application/x-www-form-urlencoded'
-d 'grant_type=urn:demandware:params:oauth:grant-type:client-id:dwsid:dwsecuretoken'

Result:
{"access_token":"060153d5-a069-4d93-a768-1b5a9183fcbh","expires_in":899,"token_type":"Bearer"}

Storefront Customer grant access

Guest User:

POST https://example.demandware.net/s/SiteGenesis/dw/shop/v17_3/customers/auth?client_id=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

{
"type" : "guest"
}

Curl:
Request:
'https://example.net/s/SiteGenesis/dw/shop/v17_3/customers/auth?client_id=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' \
-H 'Content-Type: application/json' \
-d '{
"type" : "guest"
}' \
-i

Result:
HTTP/1.1 200 OK
Accept-Ranges: bytes
x-dw-request-base-id: 1EfFu74Mg1pvAAAK
Allow: OPTIONS,POST
x-dw-version-status: deprecated
Authorization: Bearer eyJfdiI6IjEiLCJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJfdiI6IjEiLCJleHAiOjE1MTg1Mz...
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 122
Date: Tue, 13 Feb 2018 16:05:18 GMT
Server: Apache

{"_v":"17.3","_type":"customer","auth_type":"guest","customer_id":"bcmrxyatg6ZLUnnkWwPcoUqmqN","preferred_locale":"en_US"}
Logged In User:

POST https://example.demandware.net/s/SiteGenesis/dw/shop/v17_3/customers/auth?client_id=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

{
"type" : "credentials"
}

customerlogin:customerpwd

Storefront Authorization Storefront Authorization Sample

userlogin:userpwd:client_id customerlogin:customerpwd

Curl:
Request:
curl -X POST \
'https://example.demandware.net/s/SiteGenesis/dw/shop/v17_3/customers/auth?client_id=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' \
-H 'Authorization: Basic Y3VzdG9tZXJsb2dpbjpjdXN0b21lcnB3ZA==' \
-H 'Content-Type: application/json' \
-d '{"type" : "credentials"}' \
-i

Result:
HTTP/1.1 200 OK
Accept-Ranges: bytes
x-dw-request-base-id: 1Ecnuh1mgVpvAAAK
Allow: OPTIONS,POST
x-dw-version-status: deprecated
Authorization: Bearer eyJfdiI6IjEiLCJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJfdiI6I...
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 546
Date: Mon, 12 Feb 2018 10:02:05 GMT
Server: Apache

{"_v":"17.3","_type":"customer","auth_type":"registered","birthday":"1988-10-21","creation_date":"2015-05-18T19:19:51.000Z","customer_id":"abZtspg6bDhWIUcEvmTTx1vFLI","customer_no":"D0000

Additional Documentation:
Info https://documentation.demandware.com/DOC1/topic/com.demandware.dochelp/OCAPI/18.3/usage/OAuth.html
https://documentation.demandware.com/DOC1/topic/com.demandware.dochelp/OCAPI/18.3/usage/JWT.html
https://documentation.demandware.com/DOC1/topic/com.demandware.dochelp/OCAPI/18.3/shop/Resources/Customers.html

Attachment

You might also like