SitecoreCDP.SDK
1.0.7
dotnet add package SitecoreCDP.SDK --version 1.0.7
NuGet\Install-Package SitecoreCDP.SDK -Version 1.0.7
<PackageReference Include="SitecoreCDP.SDK" Version="1.0.7" />
paket add SitecoreCDP.SDK --version 1.0.7
#r "nuget: SitecoreCDP.SDK, 1.0.7"
// Install SitecoreCDP.SDK as a Cake Addin #addin nuget:?package=SitecoreCDP.SDK&version=1.0.7 // Install SitecoreCDP.SDK as a Cake Tool #tool nuget:?package=SitecoreCDP.SDK&version=1.0.7
Sitecore CDP/Personalize SDK for .NET
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:
// by file name
var batchRef = await cdpClient.BatchApi.UploadJson("import.json");
// by file stream
var batchRef = await cdpClient.BatchApi.UploadJson(jsonFileBytes);
- GZip file:
// by file name
var batchRef = await cdpClient.BatchApi.UploadGZip("import.json.gz");
// by file stream
var batchRef = await cdpClient.BatchApi.UploadGZip(gzFileBytes);
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);
// get batch job and check status
var jobStatus = await cdpClient.AudienceSyncApi.GetBatchJob(triggerResponse.Ref);
if (jobStatus.Status == AudienceSyncJobStatus.Success)
{
// get file urls
var outputFiles = await _cdpClient.AudienceSyncApi.GetOutputFiles(triggerResponse.Ref);
foreach (var fileUrl in outputFiles.SignedUrls)
{
// do something
}
// or download files
var outputFiles = await _cdpClient.AudienceSyncApi.GetOutputFiles(triggerResponse.Ref, "outputFiles.gz");
// if there is nore than one file, they will be saved as outputFiles_0.gz, outputFiles_1.gz, etc.
}
// get batch jobs from Flow:
var jobs = await _cdpClient.AudienceSyncApi.GetBatchJobs(flowRef);
foreach (var job in jobs.Items)
{
if (job.Status == AudienceSyncJobStatus.Success)
{
// do something
}
}
Interactive API (REST)
- Guest API:
cdpClient.InteractiveApi.Guests
// create guest:
var newGuest = new GuestCreate
{
Email = "x3m.xray@gmail.com",
FirstName = "Sergey",
LastName = "Baranov",
Gender = Gender.Male,
PhoneNumbers = new List<string> { "+99988877766" },
...
Identifiers = new List<Identifier>
{
new Identifier { Provider = "email", Id = "x3m.xray@gmail.com" },
new Identifier { Provider = "CMS_ID", Id = "12345" },
}
};
var result = await _cdpClient.InteractiveApi.Guests.Create(newGuest);
// update guest:
newGuest.DateOfBirth = new DateTime(1986,5,25);
var updateResult = await _cdpClient.InteractiveApi.Guests.Update(result.Ref, newGuest);
// find guest with context (extensions and orders) by identifier:
var user = await _cdpClient.InteractiveApi.Guests.FindByIdentifier(identityProvider: "CMS_ID", identityValue: "12345");
// find guest with context by parameter:
var guests = await _cdpClient.InteractiveApi.Guests.FindByParameter(GuestParameter.email, "x3m.xray@gmail.com").ToListAsync();
var me = guests.First();
// Get guest context by guestRef:
var guest = await _cdpClient.InteractiveApi.Guests.GetContext(me.Ref);
- Guest Data extensions API:
cdpClient.InteractiveApi.GuestExtensions
:
// create custom guest data extension:
public class DemoExt : DataExtension
{
[JsonPropertyName("text")]
public string Text { get; set; }
[JsonPropertyName("logic")]
public bool Logic { get; set; }
[JsonPropertyName("number")]
public int Number { get; set; }
}
// populate values
var dataExt = new DemoExt
{
Key = "demo",
Text = "lorem ipsum",
Logic = true,
Number = 456
};
var result = await _cdpClient.InteractiveApi.GuestExtensions.CreateOrUpdate(guestRef, "custom", dataExt);
// get extension items by extension name
var ext = await _cdpClient.InteractiveApi.GuestExtensions.Get(guestRef, "custom");
var items = ext.Items;
// get extension item by extension name and extension itemRef
var ext = await _cdpClient.InteractiveApi.GuestExtensions.Get(guestRef, "custom", extensionItemRef);
Dictionary<string, dynamic> items = ext.Values;
// delete extension
await _cdpClient.InteractiveApi.GuestExtensions.Delete(guestRef, "custom");
- Orders API:
cdpClient.InteractiveApi.Orders
:
// get order by orderRef:
var order = await _cdpClient.InteractiveApi.Orders.Get(orderRef);
// get guest orders:
var orders = await _cdpClient.InteractiveApi.Orders.Find(guestRef).ToListAsync();
foreach (var order in orders)
{
// access to order items, contacts, payment, etc.
}
- OrderItems API:
cdpClient.InteractiveApi.OrderItems
:
// get all order items by orderRef:
var orderItems = await _cdpClient.InteractiveApi.OrderItems.Find(orderRef).ToListAsync();
foreach (var item in orderItems)
{
// access to order item fields
}
// get single order item:
var orderItem = await _cdpClient.InteractiveApi.OrderItems.Get(item.Ref);
// delete order item:
await _cdpClient.InteractiveApi.OrderItems.Delete(item.Ref);
Stream API
In progress.
Tenant API
- Settings and configurations:
// get tenant settings and configurations:
TenantConfiguration config = await _cdpClient.TenantApi.GetConfiguration();
// get tenant point of sales list:
List<PointOfSale> pos = await _cdpClient.TenantApi.GetPointOfSales();
// get tenant Identity rules:
List<IdentityRules> identityRules = await _cdpClient.TenantApi.GetIdentityRules();
- Connections API:
cdpClient.TenantApi.Connections
:
// get connection:
Connection connection = await _cdpClient.TenantApi.Connections.Get("ee202d47-6bb6-4d4d-84e5-5adcd4d07013");
// create connection:
connection.Name = "new connection";
var newConnection = await _cdpClient.TenantApi.Connections.Create(connection);
// update connection:
newConnection.Auth = new Auth { AuthType = "NONE" };
await _cdpClient.TenantApi.Connections.Update(newConnection);
- Batch Segments API:
cdpClient.TenantApi.BatchSegments
:
// get by ref:
var batchSegment = await _cdpClient.TenantApi.BatchSegments.Get("d99c8189-32a2-4549-8193-afc091efd9d2");
// get by friendly name:
var batchSegment = await _cdpClient.TenantApi.BatchSegments.Get("demo_brimit");
// get all batch segments:
List<Segment> batchSegments = await _cdpClient.TenantApi.BatchSegments.GetAll();
- Tenant Users API:
cdpClient.TenantApi.Users
// get information about tenant user (with roles and permissions):
User tenantUser = await _cdpClient.TenantApi.Users.Get("e7198a5d-26d2-4420-938f-950c1a487bd1");
// get all tenant users:
var users = await _cdpClient.TenantApi.Users.GetAll(limit: 100, offset: 0);
FAQ
Does it supportasync
/await
?
Yes.
Does it use 3rd party http client when calling endpoints?
No, default HttpClient
is used.
Any references to libraries that versions should be taken into account (like Newtonsoft.Json)?
No.
Is SDK covered by test?
Yes and no 😃 For each new API/endpoint a test is written, but it is still local, because you need a tenant to run them. I'm not posting them publicly yet.
Supported Platforms
The SDK is available with .NET 7.0, .NET Framework 4.6.x and .NET Standard 2.x that makes 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 | Versions 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. |
-
.NETFramework 4.6.1
- Microsoft.Bcl.AsyncInterfaces (>= 6.0.0)
- System.Net.Http (>= 4.3.4)
- System.Text.Json (>= 6.0.0)
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 6.0.0)
- System.Text.Json (>= 6.0.0)
-
net7.0
- No dependencies.
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.7 | 101 | 6/4/2024 |
1.0.6 | 317 | 5/15/2024 |
1.0.5 | 220 | 3/20/2024 |
1.0.4 | 187 | 3/6/2024 |
1.0.3 | 128 | 1/16/2024 |
1.0.2 | 209 | 12/26/2023 |
1.0.1 | 411 | 6/6/2023 |
1.0.0 | 145 | 5/16/2023 |
1.0.0-alpha3 | 203 | 5/15/2023 |
1.0.0-alpha2 | 128 | 5/7/2023 |
1.0.0-alpha | 126 | 5/7/2023 |
- fix auth with ApiKey, add user-agent