Month: September 2024

Deploy Headless SXA Site to XM Cloud

Last Updated on November 16, 2024 by sandeeppote

In this blog blost lets create Project and Environment to deploy the sxastarter site to XM Cloud. The deployment is based on the existing repository in GitHub and have solution ready to deploy. Please see this blog posts on how to fork Foundation Head Template and setup your local instance along with creating Headless SXA Site(sxastarter) also configure the serliazation of Sitecore items.

To create project and environment you need to have access to XM Cloud either Admin or Contributor.

Login to XM Cloud

https://portal.sitecorecloud.io/

XM Cloud Organization-

Contains organization you are assigned to-

An organization is business unit either company or brand and contains team members and Sitecore Products you are subscribed and can have more than one Sitecore Product as seen in the below screen.

XM Cloud Deploy

As highlighted quick links container XM Cloud Deploy

https://deploy.sitecorecloud.io/

Deploy contanis list of projects and deployments done for each project and environments. It also container connections to GitHub or Vercel if site is hosted their.

The highlighted shows Organization name at the top and list of projects.

Connect to GitHub (Source Control Connections)

Ensure the changes (Sitecore Items) are pushed to GitHub repo.

Recommended – create separate branch for each environment. I have created dev, staging and main(prod)

Connections – should show list of all connections for projects mainly Github and Azure Devop for Source Control, while hosting connections can be mafe to Vercel. In this section we will configure GitHub provider.

Create a new GitHub connection

Should ask to login and provide access to a repository, you may choose all or specific repository-

Since I already had connection you will be shown a different option to Install and Authorize

Create Project

Click on Create project option

This should show the type of project to be created. We want to start from our own Source Code(GitHub) based on the connection made.

Since we configured only GitHub connection defaults to this Source Control-

Your connection name will be displayed here. Choose the connection. This will also show any other connections available.

You may also create a new connection from here.

Provide the project name and the repository where Foundation Head code resides along with any other changes you might have done sa a part of development.

Environment name – provide name – should be able to relate which branch is this pulled from.

Production environment – if this is then choose yes, I have selected this as no since I ma setting dev environment

Linked branch- Select the appropriate branch ensure yuo have all the changes available in this branch which you want to deploy

Trigger deployment on commit to branch – Set if this has to be auto deployed if changes are pushed to selected branch.

Deploy. This should start the deployment. This should take 10 -15 mins. Wait for the post actions.

You should now see the newly created project with dev environment-

New Project Created

New Environment Created

New Site Created (sxastarter)

Select environment and goto Sites tab-

Will see in the next blog hot to setup the Hosting

Select environment and Details tab- You should be able to see hostname, url’s and tokens along with Environment details.

Click on the Dashboard link –> Tools to see if the items are synched-

We now have templates, content and relevant items in layouts and image created

Content Editor with Site Collection, Site and Content

Templates Created

Experience Editor

Lets check the home page in experience editor

In the next bog will configure the Site hosting to Vercel.

Errors-

In connections select Create Connection –> GitHub

Click on Uninstall “Sitecore Deploy Prod”

Follow the process of creating a Connection again and this time you will see option to Install & Authorize

Once this is done an confirmed try creating a project –

Loading

Sitecore CDP- Create Guests using REST Api

Last Updated on November 16, 2024 by sandeeppote

https://{apiEndpoint}/v2/guests

Request to the api-

Use Client Key in User name and API Token in password to send request with Basic Auth-

Response-

Note ref field. The ref field is a guest reference which can be used further to extend or pull the guests details-

See the Properties tab to verify all the guests details-

cURL code snippet-

curl --location --request POST 'https://api.boxever.com/v2/guests' \
--header 'Authorization: Basic <<Enter Token>>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "guestType": "customer",
    "title": "Mr",
    "firstName": "Icy",
    "lastName": "Saber",
    "gender": "male",
    "dateOfBirth": "",
    "emails": [
        "icy.saber@mailfy.com"
    ],
    "phoneNumbers": [
        "01234567890"
    ],
    "nationality": "British",
    "passportNumber": "GB4B9565",
    "passportExpiry": "",
    "street": [
        "Apartment 140",
        "West Drive Avenue"
    ],
    "city": "London",
    "country": "GB",
    "postCode": "SW12",
    "state": "London"
}

C# code snippet-

var client = new RestClient("https://api.boxever.com/v2/guests");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Basic <<Enter Token>>");
request.AddHeader("Content-Type", "application/json");
var body = @"{
" + "\n" +
@"    ""guestType"": ""customer"",
" + "\n" +
@"    ""title"": ""Mr"",
" + "\n" +
@"    ""firstName"": ""Icy"",
" + "\n" +
@"    ""lastName"": ""Saber"",
" + "\n" +
@"    ""gender"": ""male"",
" + "\n" +
@"    ""dateOfBirth"": """",
" + "\n" +
@"    ""emails"": [
" + "\n" +
@"        ""icy.saber@mailfy.com""
" + "\n" +
@"    ],
" + "\n" +
@"    ""phoneNumbers"": [
" + "\n" +
@"        ""01234567890""
" + "\n" +
@"    ],
" + "\n" +
@"    ""nationality"": ""British"",
" + "\n" +
@"    ""passportNumber"": ""GB4B9565"",
" + "\n" +
@"    ""passportExpiry"": """",
" + "\n" +
@"    ""street"": [
" + "\n" +
@"        ""Apartment 140"",
" + "\n" +
@"        ""West Drive Avenue""
" + "\n" +
@"    ],
" + "\n" +
@"    ""city"": ""London"",
" + "\n" +
@"    ""country"": ""GB"",
" + "\n" +
@"    ""postCode"": ""SW12"",
" + "\n" +
@"    ""state"": ""London""
" + "\n" +
@"}
" + "\n" +
@"
" + "\n" +
@"";
request.AddParameter("application/json", body,  ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Python code snippet-

import http.client
import json

conn = http.client.HTTPSConnection("api.boxever.com")
payload = json.dumps({
  "guestType": "customer",
  "title": "Mr",
  "firstName": "Icy",
  "lastName": "Saber",
  "gender": "male",
  "dateOfBirth": "",
  "emails": [
    "icy.saber@mailfy.com"
  ],
  "phoneNumbers": [
    "01234567890"
  ],
  "nationality": "British",
  "passportNumber": "GB4B9565",
  "passportExpiry": "",
  "street": [
    "Apartment 140",
    "West Drive Avenue"
  ],
  "city": "London",
  "country": "GB",
  "postCode": "SW12",
  "state": "London"
})
headers = {
  'Authorization': 'Basic <Enter Token>>',
  'Content-Type': 'application/json'
}
conn.request("POST", "/v2/guests", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Reference-

https://doc.sitecore.com/cdp/en/developers/sitecore-customer-data-platform–data-model-2-1/use-the-create-guest-function-in-sitecore-cdp-rest-api.html

https://doc.sitecore.com/cdp/en/developers/sitecore-customer-data-platform–data-model-2-1/overview-of-sitecore-cdp-rest-apis.html

https://doc.sitecore.com/cdp/en/developers/sitecore-customer-data-platform–data-model-2-1/sitecore-cdp-guest-extensions-data-model-for-rest-api.html

Loading