Managing Guest using Engage REST API in Sitecore CDP – Developer Guide
In real time scenario, when you are working on projects, sometime for testing purpose you might have to perform some actions on the guest profile in Sitecore XM Cloud stored in CDP. In this case, I have found the Engage API becomes very useful to add/update or manage the CDP guest profile using the REST APIs.
Example:
Suppose you are working on some
Decision Model which need to return some offer based on some Guest Extension
Properties. But in order to put the values under the extension properties you
might have to build a complete form to push the values into CDP.
Rather going that path, it would
be easier to push the Guest and their properties using Engage API and running
the test on Decision Model on the same guest, showing the results and lowering
the dependency on other teams.
In this blog, I will show how you
can setup the APIs quickly using Postman and run the GUEST REST API using it.
Setup API Access Key Token
Before we proceed further you
need to create a Client Key and API Token which will serve as username and
password in Postman as Basic Authorization. Without this you will not be able
to fetch any records
Step 1: Login into XM Cloud portal and go to your CDP
Instance
Now click on API access.
Step 3: Add New Client Key
Please make sure you have set to Active.
Keep this client key and API token with you, we will use it later.
Know your Region
Engage API url consists of the environment or region based
on your setup. To find out, go to your cdp instance and click on settings icon
on right corner
Click on the Company Information
So the region is AP and based on that, the engage api url should
be like below:
Exploring the GUEST Engage REST API
Step 1: Setup Authorization in Postman
Setup using Basic Auth and your Client Key is username and API token is your password.
Request 1: Create Guests
Response:
Ref is the guest reference id which is primary value for that
particular customer.
Request Type: POST
{
"guestType": "customer",//visitor
"channel": "WEB",
"type": "IDENTITY",//Add in case
you want to identifiy the guest
"language": "EN",
"firstName": "Arjun",
"lastName": "Arora",
"identifiers": [
{
"provider": "Mobile",
"id": "917485485419"
}
],
"phoneNumbers": ["917485485419"]
}
Lets see what we got in CDP:
Open the guest:
Request 2: Create guest extensions
NOTE: please keep a note of PUT and PATCH while operating on
extensions.
PUT will remove all the existing extension property for that
guest and will keep the ones which you are providing, PATCH will update the
values for existing properties values, keeping others as it is.
Request 3: Update Extensions
Note: we are using PATCH here, After Update:
Request 4: Get Guest using Identifiers
You must set the guest as customer if you have any
identifier value like mobile or email address. This will allow you to fetch the
customer using their provider and id.
Provider => Identifier Name
ID => Value
If you have noticed in the first request, I have use type as
Identity, which will trigger Identity event and make the guest known along with
identifier.
Request 5: Get Guest using guest ref
Request 6: Get Guest extensions using Guest Ref
Request 7: Delete Guest
Summary
In this blog I have shown how you can use the Sitecore Guest
REST API to do CRUD operations on guest. This you can use specially when you
are simulating the real scenarios based on CDP guest data.
References
https://api-docs.sitecore.com/cdp/guest-rest-api
Comments
Post a Comment