Data management clients

Sitefinity Insight administrators use data management clients to work with contacts’ data stored in Sitefinity Insight. Thus, Sitefinity Insight visitors, both anonymous and registered contacts, can employ their “right to erasure (or right to be forgotten)” and “right of access.” Sitefinity Insight completes these requests via the ContactDeleteRequestClient and the ContactExportRequestClient, respectively.

NOTE: For consistency, the examples in this article use "contacts" to describe both anonymous visitors and registered contacts, who request their data exported or deleted.

The following article lists Sitefinity Insight .NET SDK clients, along with their constructors, methods, and sample code.

Contact delete request client

Constructors

  • public ContactDeleteRequestClient(IAccessToken accessToken, string datacenterKey)
    Initializes a new instance of the ContactDeleteRequestClient class using authorization token and datacenter API key.
  • public ContactDeleteRequestClient(IAccessToken accessToken, string serverAddress, string datacenterKey)
    Initializes a new instance of the ContactDeleteRequestClient class using authorization token, Sitefinity Insight API server address, and datacenter API key.

    NOTE: This constructor is obsoleted and will be removed in a future version of the SDK. Consider using the constructor overload which accepts only authorization token and datacenter key. For more information, see Capture server side data with .NET SDK.

Methods

  • public Task<IEnumerable<ContactDeleteRequest>> GetAll(LoadOptions loadOptions)
    Gets all delete requests.
  • public Task<ContactDeleteRequest> GetById(int id)
    Gets a contact delete request by identifier.
  • public Task<ContactDeleteRequest> CreateDeleteRequest(IEnumerable<SubjectId> subjectIds)
    Creates a delete request.

Contact export request client

Constructors

  • public ContactExportRequestClient(IAccessToken accessToken, string datacenterKey) : base(accessToken, datacenterKey)
    Initializes a new instance of the ContactExportRequestClient class using authorization token and datacenter API key.
  • public ContactExportRequestClient(IAccessToken accessToken, string serverAddress, string datacenterKey)
    Initializes a new instance of the ContactExportRequestClient class using authorization token, Sitefinity Insight API server address, and datacenter API key.

    NOTE: This constructor is obsoleted and will be removed in a future version of the SDK. Consider using the constructor overload which accepts only authorization token and datacenter key. For more information, see Capture server side data with .NET SDK.

Methods

  • public Task<IEnumerable<ContactExportRequest>> GetAllExportRequests(LoadOptions loadOptions)
    Gets all of the data export requests for the datacenter with which the client has been instantiated.
  • public Task<ContactExportRequest> GetExportRequestById(int id)
    Gets a data export request by its identifier.
  • public Task<ContactExportRequest> CreateExportRequest(IEnumerable<SubjectId> subjectIds)
    Creates a new data export request.
  • public Task<Stream> DownloadExportedData(int exportRequestId)
    Downloads the exported data.

Data management client sample code

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using Telerik.DigitalExperienceCloud.Client;
using Telerik.Sitefinity.Utilities.Zip;
namespace Sitefinity.DEC.Snippets
{
public class DataManagementClients
{
public static void WorkWithDataManagementClients(string accessKey, string dataCenterApiKey, string dataSourceName, string trackingID)
{
// Fill in your credentials and data center api key
var accessToken = new AccessToken(accessKey);
// Set the contact for which you wish to delete/export data
var contactForWhichToDeleteOrExportData = new List<SubjectId>()
{
new SubjectId(dataSourceName,trackingID)
};
// Create the export data client
IContactExportRequestClient contactExportClient = new ContactExportRequestClient(accessToken, dataCenterApiKey);
// This is how you create a new report for exporting data
ContactExportRequest newlyCreatedExportRequest = contactExportClient.CreateExportRequest(contactForWhichToDeleteOrExportData).Result;
// You can get all of the export requests in the data center
var allExportRequests = contactExportClient.GetAllExportRequests(new LoadOptions());
// Or you can get a specific request by knowing its id
ContactExportRequest existingExportRequestObtainedById = contactExportClient.GetExportRequestById(newlyCreatedExportRequest.Id).Result;
// If the status of the export request is DataPrepared, you can proceed and download the exported data
if (existingExportRequestObtainedById.Status == ContactExportRequestStatus.DataPrepared)
{
// Note that the report is zipped
Stream exportedDataZipStream = contactExportClient.DownloadExportedData(existingExportRequestObtainedById.Id).Result;
string zipFileDownloadLocation = Path.Combine(Directory.GetCurrentDirectory(), "report.zip");
using (var zipFileStream = File.Create(zipFileDownloadLocation))
{
exportedDataZipStream.CopyTo(zipFileStream);
}
// The exported data is in json format
string extractedReportFileLocation = Path.Combine(Directory.GetCurrentDirectory(), "exportedData.json");
var extractedReportFileStream = new MemoryStream();
using (ZipFile archivedReport = ZipFile.Read(zipFileDownloadLocation))
{
archivedReport.Entries.FirstOrDefault().Extract(extractedReportFileStream);
extractedReportFileStream.Position = 0;
using (var reportZipFileStream = File.Create(extractedReportFileLocation))
{
extractedReportFileStream.CopyTo(reportZipFileStream);
}
extractedReportFileStream.Position = 0;
using (var exportedDataStreamReader = new StreamReader(extractedReportFileStream))
{
using (var exportedDataJsonReader = new JsonTextReader(exportedDataStreamReader))
{
ExportFileData exportedData = new JsonSerializer().Deserialize<ExportFileData>(exportedDataJsonReader);
}
}
}
}
// This is how you create a delete data client
IContactDeleteRequestClient contactDeleteClient = new ContactDeleteRequestClient(accessToken, dataCenterApiKey);
// And this is how you can create a new data delete request
ContactDeleteRequest newlyCreatedDeleteRequest = contactDeleteClient.CreateDeleteRequest(contactForWhichToDeleteOrExportData).Result;
// You can get all of the delete requests in the data center
var allDeleteRequests = contactDeleteClient.GetAll(new LoadOptions());
// Or a specific one if you know its id
ContactDeleteRequest existingDeleteRequestObtainedById = contactDeleteClient.GetById(newlyCreatedDeleteRequest.Id).Result;
// You can consider the data to have been deleted when the status of the request is Done
if (existingDeleteRequestObtainedById.Status == ContactDeleteRequestStatus.Done)
{
Console.WriteLine("The data has been successfully deleted");
}
}
}
public class ExportFileData
{
public string Source { get; set; }
public DateTime DataExportDateInUtc { get; set; }
public DemographicItem[] DemographicData { get; set; }
public BehavioralItem[] BehavioralData { get; set; }
}
public class BehavioralItem
{
public string Action { get; set; }
public string Object { get; set; }
public DateTime Timestamp { get; set; }
}
public class DemographicItem
{
public string Key { get; set; }
public string Value { get; set; }
}
}

Was this article helpful?

Next article

Other clients