PINGWorks.SitecoreAI.TransferSDK 1.0.0

dotnet add package PINGWorks.SitecoreAI.TransferSDK --version 1.0.0
                    
NuGet\Install-Package PINGWorks.SitecoreAI.TransferSDK -Version 1.0.0
                    
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="PINGWorks.SitecoreAI.TransferSDK" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PINGWorks.SitecoreAI.TransferSDK" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="PINGWorks.SitecoreAI.TransferSDK" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PINGWorks.SitecoreAI.TransferSDK --version 1.0.0
                    
#r "nuget: PINGWorks.SitecoreAI.TransferSDK, 1.0.0"
                    
#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.
#:package PINGWorks.SitecoreAI.TransferSDK@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PINGWorks.SitecoreAI.TransferSDK&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=PINGWorks.SitecoreAI.TransferSDK&version=1.0.0
                    
Install as a Cake Tool

PINGWorks.SitecoreAI.TransferSDK

This is a .NET SDK for working with SitecoreAI's Content Transfer and Item Transfer APIs, and for migrating content between two SitecoreAI environments in a single call.<br /> More information about Sitecore's APIs is at:

Features

  • Typed, DI-friendly services for both transfer APIs
  • MigrateContent runs the whole source-to-destination workflow, with progress reporting and per-file results
  • Separate automation client and host for the source and the destination environment
  • Async-first API with CancellationToken support and full XML documentation comments
  • NetStandard 2.1 for wide compatibility
  • Automatic token maintenance using client credentials flow
  • Retries re-send the same chunk and blob bytes

Getting started

Prerequisites

To work with the SDK you will require two environments and an automation client for each. Create the credentials in the SitecoreAI Deployment Portal.

Create an Environment credential of type Automation for the project and environment combination of the source, and another for the destination. Both APIs require the Organization Admin or Organization Owner role.

Install

From your project directory:

dotnet add package PINGWorks.SitecoreAI.TransferSDK

Register services

Register the SDK in Program.cs, e.g. when using the minimal hosting model:

// Program.cs
var builder = WebApplication.CreateBuilder( args );

builder.Services.AddSitecoreEETransferSDK( opt => {
	opt.Source.Host = new Uri( "https://xmc-source.sitecorecloud.io/" );
	opt.Source.ClientID = "[Source automation client ID]";
	opt.Source.ClientSecret = "[Source automation client secret]";

	opt.Destination.Host = new Uri( "https://xmc-destination.sitecorecloud.io/" );
	opt.Destination.ClientID = "[Destination automation client ID]";
	opt.Destination.ClientSecret = "[Destination automation client secret]";
} );

Options can also be bound from configuration:

builder.Services.AddSitecoreEETransferSDK( opt => builder.Configuration.GetSection( "Transfer" ).Bind( opt ) );

We recommend the use of Visual Studio's User Secrets feature to store ClientID and ClientSecret values during development.

HttpClient defaults. This call (via AddSitecoreEECommon) applies AddStandardResilienceHandler() and a DEBUG-only console request/response logger to every HttpClient in your container. The two Transfer clients use their own resilience pipeline sized by RequestTimeout. See the PINGWorks.SitecoreExperienceEdge.Common README for how to customize the resilience options per-client.

This library uses Json serialization through System.Text.Json.

Options

Option Default Description
Source The environment content is read from.
Destination The environment content is written to.
PollInterval 5 seconds The interval between status polls.
RequestTimeout 5 minutes The timeout of a single HTTP attempt. The total time allowed for a request, including retries, is three times this value.
StageTimeout 2 hours The longest MigrateContent waits in one polling stage: the content transfer, a blob, or an item transfer attempt.
MaxParallelChunks 4 The maximum number of chunks copied at once within a chunk set.
MaxItemTransferRetries 1 The number of times a Failed item transfer is retried with RetryTransfer.

The options are validated when first read. PollInterval and StageTimeout must be greater than zero, RequestTimeout must be greater than zero and finite, MaxParallelChunks must be at least 1, and MaxItemTransferRetries must not be negative. An invalid value throws OptionsValidationException naming the option.

Each environment (Source, Destination) takes:

Option Default Description
Host The CM host of the environment, for example https://xmc-example.sitecorecloud.io/. Required.
ClientID The automation client ID from the SitecoreAI Deploy Portal. Required.
ClientSecret The automation client secret from the SitecoreAI Deploy Portal.
TokenEndpoint https://auth.sitecorecloud.io/oauth/token The URL of the Token Request API.
Audience https://api.sitecorecloud.io The auth audience.
GrantType client_credentials The auth grant type.

An environment with an empty ClientID or no Host is not configured. MigrateContent throws InvalidOperationException before making any call when Source or Destination is not configured.

Migrating content

MigrateContent takes the items to transfer and runs the whole workflow.

using PINGWorks.SitecoreAI.TransferSDK;
using PINGWorks.SitecoreAI.TransferSDK.Enums;
using PINGWorks.SitecoreAI.TransferSDK.Requests;
using PINGWorks.SitecoreAI.TransferSDK.Responses;

public class Migrator( ISitecoreTransferSdk sdk )
{
	public async Task Run( CancellationToken ct )
	{
		DataTree[] trees = [
			new() { ItemPath = "/sitecore/content/Home", Scope = TransferScope.ItemAndDescendants },
			new() { ItemPath = "/sitecore/media library/Images/logo", MergeStrategy = MergeStrategy.KeepExistingItem }
		];

		var progress = new Progress<MigrationProgress>( p => Console.WriteLine( $"{p.Stage}: {p.Completed}/{p.Total}" ) );

		var result = await sdk.MigrateContent( trees, "master", "master", progress, ct );

		if ( result.IsSuccessful )
		{
			Console.WriteLine( $"Transfer {result.TransferId} finished" );
			return;
		}

		Console.WriteLine( $"Run error: {result.Error}" );
		foreach ( var file in result.Files )
		{
			Console.WriteLine( $"{file.FileName}: {file.FinalTransferState} (item transfer {file.ItemTransferId}, blob {file.FinalBlobState})" );

			if ( file.Error is not null )
				Console.WriteLine( $"  Error: {file.Error}" );

			foreach ( var validationError in file.ValidationErrors )
				Console.WriteLine( $"  Validation: {validationError}" );
		}
	}
}

Items in a transfer need their parent chain to exist in the destination with the same item IDs, otherwise they transfer but do not appear in the content tree. Transfer from a common ancestor with Scope = TransferScope.ItemAndDescendants, or transfer the parents first.

What MigrateContent does

Stages, reported through IProgress<MigrationProgress>:

Stage Where What happens
Preparing Source Creates the content transfer and polls until it is Completed.
Chunks Source and destination Gets each chunk from the source and saves it to the destination, up to MaxParallelChunks at once.
Completing Destination Completes each chunk set once all its chunks are saved. Each chunk set becomes one .raif file.
Consuming Destination For each .raif file: waits for the blob to be Uploaded, starts the item transfer, polls until it finishes, then deletes the blob.

MigrationProgress carries Stage, Completed and Total for the stage.

Cleanup and failure behaviour:

  • The source transfer is always deleted at the end of the export, whether the export succeeded, failed or was cancelled. The delete is best effort and its failure does not change the result.
  • A .raif blob is deleted only after its item transfer reaches Finished.
  • While a blob is Uploading or Unknown the run keeps waiting. Any other state that is not Uploaded fails that file with Blob is in state X; expected Uploaded.
  • A source transfer that completes with no chunk sets fails the export with Transfer produced no chunk sets.
  • A failed file leaves its blob in place. Call StartTransfer or RetryTransfer by hand, then DeleteBlobSource when it finishes.
  • A Failed item transfer is retried up to MaxItemTransferRetries times before the file is reported as failed.
  • A Discarded item transfer counts as a failed file.
  • A polling stage that runs longer than StageTimeout fails with Timed out after <StageTimeout> waiting for <stage>. During the export this is MigrationResult.Error; while consuming a file it is that file's Error.
  • A failure on one file is recorded in that file's Error and the remaining files are still consumed.
  • If the export fails, MigrationResult.Error holds the reason and Files lists the .raif files completed so far, each with only its FileName. Their blobs remain in the destination.
  • TransferredWithErrors is a terminal partial success and counts as finished. FinalBlobState reports it. Check ValidationErrors on the file.
  • Cancelling through the CancellationToken throws OperationCanceledException.
  • An empty dataTrees throws ArgumentException.

MigrationResult:

Member Description
TransferId The identifier of the content transfer created on the source.
IsSuccessful True when Error is null and every file's FinalTransferState is Finished.
Error The reason the run stopped before the consume stage. Null when the run reached it.
Files One RaifTransferResult per .raif file.

RaifTransferResult:

Member Description
FileName The .raif file (blob) name.
ItemTransferId The item transfer identifier. Null when the item transfer was not started.
FinalBlobState The last observed blob state.
FinalTransferState The last observed item transfer state.
ValidationErrors The validation errors reported by the item transfer.
Error The reason the file did not reach Finished. Null when it did, or when it was not attempted.

Available services

Injectable interface ISitecoreTransferSdk

Combines ISitecoreContentTransferSdk and ISitecoreItemTransferSdk, and adds:

Method Description
MigrateContent(dataTrees, sourceDatabase?, destinationDatabase?, progress?) Migrates items from the Source to the Destination environment. Both databases default to master.

Injectable interface ISitecoreContentTransferSdk

Source-side calls use the Source environment. Destination-side calls use the Destination environment.

Method Environment Description
CreateTransfer(request) Source Creates a content transfer.
GetTransferStatus(transferId) Source Retrieves the state and chunk sets of a transfer.
GetChunk(transferId, chunkSetId, chunkId) Source Retrieves one chunk. Fails when the response omits a valid IsMedia value.
SaveChunk(transferId, chunkSetId, chunkId, chunk) Destination Saves a chunk exactly as returned by GetChunk.
CompleteChunkSet(transferId, chunkSetId) Destination Completes a chunk set and returns the .raif file name.
DeleteTransfer(transferId) Source Deletes a transfer and its resources.

Injectable interface ISitecoreItemTransferSdk

Every call uses the Destination environment. page and pageSize use the server defaults (page 1, 50 per page) when omitted.

Method Description
ListTransfers(page?, pageSize?) Lists the transfers.
GetTransfer(transferId) Retrieves the details of a transfer, including validation errors.
StartTransfer(databaseName, blobName?, fileName?) Starts consuming an uploaded blob or an existing file. Returns the transfer ID.
RetryTransfer(databaseName, sourceName) Retries the failed items of a transfer.
ListTransferredItems(databaseName, sourceName, page?, pageSize?) Lists the items transferred from a source.
GetTransferredItem(databaseName, sourceName, itemId) Retrieves one transferred item with its field values.
ListBlobSources(page?, pageSize?) Lists the blob sources.
GetBlobSource(blobName) Retrieves the state of one blob source.
UploadBlobSource(blobName, content, gzip?) Uploads a blob (Stream). A stream that cannot seek is buffered in memory first.
DeleteBlobSource(blobName) Deletes a blob source.
ListFileSources(page?, pageSize?) Lists the file sources.
GetHistory(page?, pageSize?) Retrieves the transfer history with state transitions.

All methods take an optional CancellationToken.

Manual workflow

The methods map to the workflow steps of the official documentation. Use them when you need control that MigrateContent does not give, such as retrying a single file.

Step Method
Create the transfer (source) CreateTransfer
Wait for the transfer to be ready (source) GetTransferStatus until State is Completed. Record each ChunkSetId and ChunkCount.
Retrieve a chunk (source) GetChunk for chunk IDs 0 to ChunkCount - 1
Save a chunk (destination) SaveChunk, passing the TransferChunk from GetChunk unchanged
Complete the chunk set (destination) CompleteChunkSet. The result holds the .raif file name.
Delete the transfer (source) DeleteTransfer
Verify the blob is available (destination) GetBlobSource or ListBlobSources until BlobState is Uploaded
Start consuming the blob (destination) StartTransfer with blobName set to the .raif file name
Monitor the transfer GetTransfer until TransferState is Finished. On Failed, call RetryTransfer.
Investigate TransferredWithErrors GetTransfer and read ValidationErrors
Clean up DeleteBlobSource

Notes

  • Empty response bodies. Calls that return an empty 201, 202 or 204 body (CreateTransfer, SaveChunk, UploadBlobSource, DeleteBlobSource, DeleteTransfer) return ApiResponse<bool>. Check IsSuccessful, not Result.
  • Error bodies. The transfer APIs return errors as { "Error": "..." }. The message arrives in response.Error.AdditionalData["Error"].
  • Large chunks. RequestTimeout governs the time allowed for each HTTP attempt. Raise it when chunks are large or the link is slow.
  • Retries. The resilience pipeline retries every method, including the StartTransfer and CompleteChunkSet POSTs. A retried chunk save or blob upload sends the same bytes again.
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 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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.0 91 11/30/2026

v1.0.0 Initial release