SitecoreCDP.SDK 1.0.0-alpha2

This is a prerelease version of SitecoreCDP.SDK.
There is a newer version of this package available.
See the version list below for details.
dotnet add package SitecoreCDP.SDK --version 1.0.0-alpha2
NuGet\Install-Package SitecoreCDP.SDK -Version 1.0.0-alpha2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SitecoreCDP.SDK" Version="1.0.0-alpha2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SitecoreCDP.SDK --version 1.0.0-alpha2
#r "nuget: SitecoreCDP.SDK, 1.0.0-alpha2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SitecoreCDP.SDK as a Cake Addin
#addin nuget:?package=SitecoreCDP.SDK&version=1.0.0-alpha2&prerelease

// Install SitecoreCDP.SDK as a Cake Tool
#tool nuget:?package=SitecoreCDP.SDK&version=1.0.0-alpha2&prerelease

Sitecore CDP/Personalize SDK for .NET

SitecoreCDP.SDK

The unofficial .Net SDK for Sitecore CDP/Personalize

Example

using SitecoreCDP.SDK;

// initialize client
var cdpClient = new CdpClient(new CdpClientConfig
{
    ClientKey = "tenant-client-key",
    ApiToken = "tenant-api-token",
    
    BaseUrl = "https://api-engage-eu.sitecorecloud.io", // or "https://api.boxever.com"
    Version = "v2"
});

// batch import
var batchRef = await cdpClient.BatchApi.UploadJson("import.json");

...

// check status
var status = await cdpClient.BatchApi.CheckStatus(batchRef);
if (status.Status.Code == BatchStatusCode.Error)
{
	// download log and extract error records
    var logRecords = await cdpClient.BatchApi.DownloadBatchLog(status.Status.LogUri);
    var errorRecords = logRecords.Where(x => x.Code != 200);
}

Available services

At this moment Batch API, Interactive API and Audience Sync are ready. Stream API and Tenant API are in progress.

Batch API

Batch API is used to upload guests, orders, and tracking events. The are 3 types of supported import formats:

  • Model based:
var batchRef = await cdpClient.BatchApi.Upload(new List<Batch>
{
    new BatchGuest { Guest = new Guest() {/* populate fields */ } },
    new BatchOrder {Order = new Order(){ /* populate fields */}},
	...
});
  • JSON file:
var batchRef = await cdpClient.BatchApi.UploadJson("import.json");
  • GZip file:
var batchRef = await cdpClient.BatchApi.UploadGZip("import.json.gz");

Check batch import status and download error log in strongly typed records:

// check status
var status = await cdpClient.BatchApi.CheckStatus(batchRef);
if (status.Status.Code == BatchStatusCode.Error)
{
	// download log and extract error records
    var logRecords = await cdpClient.BatchApi.DownloadBatchLog(status.Status.LogUri);
    var errorRecords = logRecords.Where(x => x.Code != 200);
}

AudienceSync API

AudienceSync REST API to trigger and retrieve batch jobs, download output files.

var triggerResponse = await cdpClient.AudienceSyncApi.Trigger(flowRef, segmentRef, datasetDate);

var jobStatus = await cdpClient.AudienceSyncApi.CheckStatus(triggerResponse.Ref);
if (jobStatus.Status == TriggerResponseStatus.Success)
{
    await cdpClient.AudienceSyncApi.GetOutputFiles(triggerResponse.Ref, "outputFiles.gz");
}

Interactive API (REST)

  • Guest API: cdpClient.InteractiveApi.Guests
  • Guest Data extensions API: cdpClient.InteractiveApi.GuestExtensions
  • Orders API: cdpClient.InteractiveApi.Orders
  • OrderItems API: cdpClient.InteractiveApi.OrderItems

Stream API

In progress.

await cdpClient.StreamApi.RunExperiment(friendlyId);
await cdpClient.StreamApi.IdentifyUser(new IdentityEvent{});
await cdpClient.StreamApi.TrackEvent(new Event{});
await cdpClient.StreamApi.CreateNewSession();
await cdpClient.StreamApi.AbandonSession();

Tenant API

In progress.

FAQ

Do I have to use async/await when calling endpoints?

Yes. The SDK uses HttpClient, which does not support synchronous calls (and for good reason). Do not use .Result or .Wait() on calls made with this SDK, ever. These will block threads and potentially cause deadlocks. In short, don't block on async code. Use await.

Supported Platforms

The SDK targets net7.0 at this moment (will be rebuid with .NET Framework 4x and .NET Standard 2.x to make it compatible with almost all .NET solutions.

Getting Help

For programming questions you can ask me in Sitecore Slack channels @@x3mxray.

To report a bug or request a feature specific to the SDK, please open an issue.

Helpful Resources

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 54 5/15/2024
1.0.5 198 3/20/2024
1.0.4 161 3/6/2024
1.0.3 106 1/16/2024
1.0.2 190 12/26/2023
1.0.1 389 6/6/2023
1.0.0 126 5/16/2023
1.0.0-alpha3 184 5/15/2023
1.0.0-alpha2 109 5/7/2023
1.0.0-alpha 107 5/7/2023