Contentstack Management .NET SDK
Overview
This reference covers the public API of the contentstack.management.csharp package, with one page per class. Use it to look up method signatures, parameters, return types, validation behavior, and worked examples for every object you reach from a ContentstackClient.
Before you begin This reference assumes you have installed and initialized the SDK. If you have not, complete the Get Started with .NET Management SDK guide first. This SDK requires .NET 10 or later, because the package targets net10.0. This reference documents version 1.2.0, and the changelog lists behavior changes between releases.
The command below adds the package to a project that targets .NET 10 or later:
dotnet add package contentstack.management.csharp
Minimum Working Example
This snippet creates a client with an authtoken, fetches one entry, and prints its title.
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").FetchAsync();
Console.WriteLine(response.OpenJsonObjectResponse()["entry"]?["title"]);
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}SDK Structure
The chain. The SDK builds each Content Management API (CMA) request from a chain of objects. ContentstackClient stores your credentials and settings, and client.Stack() returns a Stack for one stack. An accessor of the stack, such as ContentType, Asset, or Release, returns an object for one resource type. These calls send no request. A request method on the resource object sends one request: Fetch, Create, Update, Delete, or Publish, for example, or Query().Find() for a list. Every chain starts at the ContentstackClient.
Collection or item. The UID you pass to an accessor decides which methods you can call. Without a UID, the object works with the collection, for example Create or Query. With a UID, it works with one item, for example Fetch or Delete. A method from the other group throws InvalidOperationException before any request leaves the SDK. Query option methods, such as Limit and Skip, store a value and send nothing. An invalid value therefore fails on Find, which throws a ContentstackErrorException.
Sync and async. Each request method has a sync form that returns ContentstackResponse and an async form, with an Async suffix, that returns Task<ContentstackResponse>. The response contains the raw JSON body, which you read with OpenJsonObjectResponse() or OpenTResponse<T>().
Class Overview
Set up the client and sign in.
| Class | Role | Accessed via |
|---|---|---|
| ContentstackClient | The connection settings and credentials, and the start of every chain. | new ContentstackClient(...) |
| ContentstackClientOptions | Every client setting in one object, including the host, timeout, proxy, and retries. | new ContentstackClientOptions() |
| OAuthHandler | The Open Authorization (OAuth) 2.0 authorization code flow of one app. | client.OAuth(options) |
| OAuthOptions | The settings of one OAuth app. | new OAuthOptions() |
| OAuthTokens | The tokens and user details of one OAuth sign-in. | oauth.GetCurrentTokens() |
| Endpoint | A static lookup of the Contentstack service hosts of a region. | Endpoint.GetContentstackEndpoint(region, service) |
| Organization | The organizations of the signed-in user. | client.Organization(uid) |
| User | The password reset requests of a Contentstack account. | client.User() |
Send requests and read results.
| Class | Role | Accessed via |
|---|---|---|
| ContentstackResponse | The HTTP response of one request, with its body and headers. | entry.Fetch() |
| Query | A list request for one stack resource. | contentType.Query() |
| ParameterCollection | The query parameters of one request. | new ParameterCollection() |
| BoolParameterValue | A true or false query parameter value. | new BoolParameterValue(true) |
| DoubleParameterValue | A number query parameter value. | new DoubleParameterValue(10) |
| DoubleListParameterValue | A list of numbers for one query parameter. | new DoubleListParameterValue(values) |
| StringParameterValue | A text query parameter value. | new StringParameterValue(value) |
| StringListParameterValue | A list of text values for one query parameter. | new StringListParameterValue(values) |
| JObjectParameterValue | A JSON query parameter value. | new JObjectParameterValue(json) |
Handle errors.
| Class | Role | Accessed via |
|---|---|---|
| ContentstackErrorException | The exception for a request that the API rejects. | catch (ContentstackErrorException e) |
| ContentstackException | The base exception for errors that the SDK raises itself. | catch (ContentstackException e) |
| OAuthException | The exception for a failed OAuth step, with four subclasses. | catch (OAuthException e) |
Manage stacks, branches, environments, and languages.
| Class | Role | Accessed via |
|---|---|---|
| Stack | One stack, and the accessors for every stack resource. | client.Stack(apiKey) |
| StackSettings | The settings that AddSettings sends to a stack. | new StackSettings() |
| UserInvitation | One user and the roles to give that user. | new UserInvitation() |
| Branch | The branches of a stack. | stack.Branch(uid) |
| BranchModel | The details of a branch. | new BranchModel() |
| BranchAliasModel | An alias that points to a branch. | branchModel.Alias |
| BranchPublishConfigModel | The environments that a new branch clones. | new BranchPublishConfigModel() |
| Environment | The publishing environments of a stack. | stack.Environment(name) |
| EnvironmentModel | The details of a publishing environment. | new EnvironmentModel() |
| Server | One deployment server of a publishing environment. | new Server() |
| LocalesUrl | A language code and the URL that an environment serves it from. | new LocalesUrl() |
| Locale | The languages of a stack. | stack.Locale(code) |
| LocaleModel | The details of a language. | new LocaleModel() |
Model content types and global fields.
| Class | Role | Accessed via |
|---|---|---|
| ContentType | The content types of a stack. | stack.ContentType(uid) |
| GlobalField | The global fields of a stack. | stack.GlobalField(uid) |
| ContentModelling | The schema of a content type or a global field. | new ContentModelling() |
| Option | The page settings of a content type. | new Option() |
| Field | The base class of every field in a schema. | contentModelling.Schema |
| TextboxField | A text field. | new TextboxField() |
| JsonField | A JSON field, such as a JSON Rich Text Editor (JSON RTE). | new JsonField() |
| NumberField | A number field. | new NumberField() |
| DateField | A date field. | new DateField() |
| FileField | A file field. | new FileField() |
| ImageField | A file field that accepts only images. | new ImageField() |
| SelectField | A text field whose value comes from a fixed list of choices. | new SelectField() |
| SelectEnum | The choices of a select field. | new SelectEnum() |
| ReferenceField | A reference field that links to entries of other content types. | new ReferenceField() |
| GroupField | A group field with a nested schema. | new GroupField() |
| ModularBlockField | A modular blocks field. | new ModularBlockField() |
| Block | One block type of a modular blocks field. | new Block() |
| GlobalFieldReference | A field that places a global field inside a schema. | new GlobalFieldReference() |
| GlobalFieldRefs | One nested global field inside the schema of a global field. | new GlobalFieldRefs() |
| ExtensionField | A custom field that an extension renders. | new ExtensionField() |
| TaxonomyField | A taxonomy field. | new TaxonomyField() |
| FieldMetadata | The extra settings of a field, such as a default value. | new FieldMetadata() |
| FieldRules | One field visibility rule of a content type. | new FieldRules() |
| Condition | One condition of a field visibility rule. | new Condition() |
| Action | What a field visibility rule does to one target field. | fieldRules.Actions |
| Label | The labels that group content types. | stack.Label(uid) |
| LabelModel | The details of a label. | new LabelModel() |
Work with entries.
| Class | Role | Accessed via |
|---|---|---|
| Entry | The entries of one content type. | contentType.Entry(uid) |
| EntryVariant | The variants of one entry. | entry.Variant(uid) |
| Version | The versions of one entry or asset. | entry.Version(versionNumber) |
| VariantGroup | The variant groups of a stack. | stack.VariantGroup(uid) |
| PublishUnpublishDetails | The environments, locales, and schedule of a publish or unpublish request. | new PublishUnpublishDetails() |
| PublishVariant | One entry variant in a publish or unpublish request. | new PublishVariant() |
| EntryPublishAction | The publish rule details of a publish request. | new EntryPublishAction() |
| EntryWorkflowStage | The workflow stage details of an entry. | new EntryWorkflowStage() |
| AssignToUser | One user that a workflow stage assigns to an entry. | new AssignToUser() |
| AssignByRole | One role that a workflow stage assigns to an entry. | new AssignByRole() |
Work with assets.
| Class | Role | Accessed via |
|---|---|---|
| Asset | The assets of a stack. | stack.Asset(uid) |
| AssetModel | The file and details of an asset to upload. | new AssetModel(...) |
| Folder | The asset folders of a stack. | asset.Folder(uid) |
Run bulk operations.
| Class | Role | Accessed via |
|---|---|---|
| BulkOperation | Publish, unpublish, delete, workflow, and release actions on many items in one request. | stack.BulkOperation() |
| BulkPublishDetails | The entries, assets, locales, and environments of a bulk publish or unpublish request. | new BulkPublishDetails() |
| BulkPublishEntry | One entry in a bulk publish or unpublish request. | new BulkPublishEntry() |
| BulkPublishAsset | One asset in a bulk publish or unpublish request. | new BulkPublishAsset() |
| BulkPublishRules | The rules object of a bulk publish or unpublish request. | new BulkPublishRules() |
| BulkDeleteDetails | The entries and assets of a bulk delete request. | new BulkDeleteDetails() |
| BulkDeleteEntry | One entry in a bulk delete request. | new BulkDeleteEntry() |
| BulkDeleteAsset | One asset in a bulk delete request. | new BulkDeleteAsset() |
| BulkWorkflowUpdateBody | The entries and new workflow details of a bulk workflow update. | new BulkWorkflowUpdateBody() |
| BulkWorkflowEntry | One entry in a bulk workflow update. | new BulkWorkflowEntry() |
| BulkWorkflowStage | The target stage and assignees of a bulk workflow update. | new BulkWorkflowStage() |
| BulkWorkflowUser | One user to assign in a bulk workflow update. | new BulkWorkflowUser() |
| BulkWorkflowRole | One role to assign in a bulk workflow update. | new BulkWorkflowRole() |
| BulkAddItemsData | The release, action, locales, and items of a bulk release request. | new BulkAddItemsData() |
| BulkAddItem | One entry or asset in a bulk release request. | new BulkAddItem() |
| BulkReleaseItemsData | The release, action, locales, and items of a bulk add-to-release request. | new BulkReleaseItemsData() |
| BulkReleaseItem | One entry or asset in a bulk add-to-release request. | new BulkReleaseItem() |
Classify content with taxonomies.
| Class | Role | Accessed via |
|---|---|---|
| Taxonomy | The taxonomies of a stack. | stack.Taxonomy(uid) |
| TaxonomyModel | The details of a taxonomy. | new TaxonomyModel() |
| TaxonomyImportModel | A JSON or CSV taxonomy file to import. | new TaxonomyImportModel(...) |
| Term | The terms of one taxonomy. | taxonomy.Terms(uid) |
| TermModel | The details of a taxonomy term. | new TermModel() |
| TermMoveModel | The target parent and position of a term to move. | new TermMoveModel() |
| TermAncestorDescendant | One term above or below another term in a hierarchy. | termModel.Ancestors |
Plan and deploy releases.
| Class | Role | Accessed via |
|---|---|---|
| Release | The releases of a stack. | stack.Release(uid) |
| ReleaseModel | The details of a release. | new ReleaseModel() |
| ReleaseItem | The entries and assets of one release. | release.Item() |
| ReleaseItemModel | One entry or asset in a release. | new ReleaseItemModel() |
| DeployModel | The environments, locales, and action of a release deployment. | new DeployModel() |
Govern publishing.
| Class | Role | Accessed via |
|---|---|---|
| Workflow | The workflows of a stack. | stack.Workflow(uid) |
| WorkflowModel | The details of a workflow. | new WorkflowModel() |
| WorkflowStage | One stage of a workflow. | new WorkflowStage() |
| PublishRule | The publish rules of a stack. | workflow.PublishRule(uid) |
| PublishRuleModel | The details of a publish rule. | new PublishRuleModel() |
| Approvals | The users and roles who approve publishing under a publish rule. | new Approvals() |
| PublishQueue | The publish queue of a stack. | stack.PublishQueue(uid) |
| AuditLog | The audit log of a stack. | stack.AuditLog(uid) |
Extend the stack.
| Class | Role | Accessed via |
|---|---|---|
| Extension | The extensions of a stack. | stack.Extension(uid) |
| ExtensionModel | The title, type, source, and settings of an extension. | new ExtensionModel() |
| ExtensionScope | The content types whose entries show a custom widget. | new ExtensionScope() |
| CustomFieldModel | The file and settings of a custom field to upload. | new CustomFieldModel(...) |
| CustomWidgetModel | The file and settings of a custom widget to upload. | new CustomWidgetModel(...) |
| DashboardWidgetModel | The file and settings of a dashboard widget to upload. | new DashboardWidgetModel(...) |
| Webhook | The webhooks of a stack. | stack.Webhook(uid) |
| WebhookModel | The details of a webhook. | new WebhookModel() |
| WebhookTarget | One destination of a webhook. | new WebhookTarget() |
Manage roles and tokens.
| Class | Role | Accessed via |
|---|---|---|
| Role | The roles of a stack. | stack.Role(uid) |
| RoleModel | The name, description, and rules of a role. | new RoleModel() |
| DeliveryToken | The delivery tokens of a stack. | stack.DeliveryToken(uid) |
| DeliveryTokenModel | The details of a delivery token. | new DeliveryTokenModel() |
| DeliveryTokenScope | One scope entry of a delivery token. | new DeliveryTokenScope() |
| ManagementToken | The management tokens of a stack. See the Known issue on its class page. | stack.ManagementTokens(uid) |
| ManagementTokenModel | The details of a management token. | new ManagementTokenModel() |
| TokenScope | One scope entry of a token. | new TokenScope() |
| PreviewToken | The preview token of one delivery token. | stack.PreviewToken(deliveryTokenUid) |
| PreviewTokenModel | The name and description of a preview token. | new PreviewTokenModel() |
Task Index
| Task | Start here | Class |
|---|---|---|
| Sign in with an email, a password, and a two-factor code | Login | ContentstackClient |
| Sign users in through an OAuth app | OAuth | ContentstackClient |
| Work in one branch with a management token | Stack | ContentstackClient |
| List the entries of a content type | Query | Entry |
| Paginate a list | Skip | Query |
| Filter a list with a JSON query | AddQuery | ParameterCollection |
| Create an entry | Create | Entry |
| Publish an entry to an environment | Publish | Entry |
| Upload a file as an asset | Create | Asset |
| Publish many entries and assets in one request | Publish | BulkOperation |
| Read a response into your own class | OpenTResponse | ContentstackResponse |
| Set the host, timeout, retries, or proxy | ContentstackClientOptions | ContentstackClientOptions |
Key Usage Patterns
Each example below is a complete C# file with every using directive it needs, so it compiles with implicit usings turned off. Run it as a top-level program.
Sign in with a two-factor code and list the stacks of an organization
When token is empty and mfaSecret has a value, LoginAsync generates the time-based one-time password (TOTP) from the secret. The client stores the authtoken from the response and sends it on every later request.
using System;
using System.Net;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient();
try
{
await client.LoginAsync(new NetworkCredential("<EMAIL>", "<PASSWORD>"), mfaSecret: "<MFA_SECRET>");
ContentstackResponse stacks = await client.Organization("<ORGANIZATION_UID>").GetStacksAsync();
Console.WriteLine(stacks.OpenJsonObjectResponse().ToJsonString());
await client.LogoutAsync();
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Work in one branch with a management token
A management token belongs to one stack and needs no authtoken on the client. The SDK sends the branch UID as the branch header on every request from the Stack, including the requests of the objects its accessors return.
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
Stack stack = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>", "<BRANCH_UID>");
try
{
ContentstackResponse contentTypes = await stack.ContentType().Query().FindAsync();
Console.WriteLine(contentTypes.OpenJsonObjectResponse().ToJsonString());
ContentstackResponse entry = await stack.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").FetchAsync();
Console.WriteLine(entry.OpenJsonObjectResponse()["entry"]?["title"]);
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Filter entries with query parameters and read them into your own class
ParameterCollection contains the parameters that a method has no argument for. OpenTResponse<T> maps the whole body onto your class, including the entries wrapper key. The following example filters entries by title and reads them into a typed class.
using System;
using System.Collections.Generic;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ParameterCollection collection = new ParameterCollection();
collection.Add("locale", "<LOCALE_CODE>");
collection.Add("include_count", true);
collection.AddQuery(new JsonObject { ["title"] = "Blog Post" });
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ContentType("<CONTENT_TYPE_UID>").Entry().Query().FindAsync(collection);
EntriesResponse body = response.OpenTResponse<EntriesResponse>();
Console.WriteLine($"{body?.Count} matching entries");
foreach (BlogPost post in body?.Entries ?? new List<BlogPost>())
{
Console.WriteLine($"{post.Title}: {post.Url}");
}
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}
public class EntriesResponse
{
public List<BlogPost> Entries { get; set; }
public int Count { get; set; }
}
public class BlogPost
{
public string Uid { get; set; }
public string Title { get; set; }
public string Url { get; set; }
[JsonPropertyName("updated_at")]
public DateTime UpdatedAt { get; set; }
}Page through every entry of a content type
The SDK sends one request for each Find call and requests no further pages. Skip and Limit each take one value per query, so the loop below creates a new query for each page.
using System;
using System.Text.Json.Nodes;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
Stack stack = client.Stack("<API_KEY>");
const int pageSize = 100;
int skip = 0;
int received;
try
{
do
{
ContentstackResponse response = await stack.ContentType("<CONTENT_TYPE_UID>").Entry().Query().Limit(pageSize).Skip(skip).FindAsync();
JsonArray entries = response.OpenJsonObjectResponse()["entries"]?.AsArray() ?? new JsonArray();
received = entries.Count;
skip += received;
Console.WriteLine($"Read {received} entries, {skip} in total");
}
while (received == pageSize);
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Tell a client-side check, a network failure, and an API rejection apart
The SDK throws a different exception type for each of the three failures below:
- A client-side check throws before any request.
- A network failure throws the original .NET exception after the network retries end.
- An API rejection throws ContentstackErrorException after the status retries end.
The following example catches each of the three exception types separately.
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").FetchAsync();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (InvalidOperationException e)
{
// No authtoken or management token, no API key, or a method that the object's UID state does not allow
Console.WriteLine($"Client-side check: {e.Message}");
}
catch (ArgumentException e)
{
// A required UID or argument is missing
Console.WriteLine($"Client-side check: {e.Message}");
}
catch (TaskCanceledException e)
{
// Every attempt timed out
Console.WriteLine($"Timed out: {e.Message}");
}
catch (HttpRequestException e)
{
// A refused connection, an unreachable host, or a failed host name lookup
Console.WriteLine($"Network failure: {e.Message}");
}
catch (ContentstackErrorException e)
{
// The API answered with a status outside 2xx
Console.WriteLine($"API error: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
foreach (KeyValuePair<string, object> error in e.Errors ?? new Dictionary<string, object>())
{
Console.WriteLine($"{error.Key}: {error.Value}");
}
}Target another region with a longer timeout and bounded retries
The client has no region option, so set Host to the CMA host of the region. The retry settings below stop the client from retrying a 500 to 504 status without a limit. See the Known issue under SDK-Wide Notes below.
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
ContentstackClientOptions options = new ContentstackClientOptions()
{
Authtoken = "<AUTHTOKEN>",
Host = "eu-api.contentstack.com",
Timeout = TimeSpan.FromSeconds(60),
RetryLimit = 3,
RetryDelay = TimeSpan.FromMilliseconds(500),
RetryOnHttpServerError = false,
RetryCondition = status => (int)status == 429
};
ContentstackClient client = new ContentstackClient(options);
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").FetchAsync();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Register the client for dependency injection in `ASP.NET` Core
Known issue AddContentstackClient(services, options) and TryAddContentstackClient(services, options) from the contentstack.management.aspnetcore package register no ContentstackClient, so the container fails to resolve the client. Register the client yourself with services.AddSingleton(new ContentstackClient(options)), as in the file below.
The file below registers one client and a service class that receives it through its constructor. Give the client its own ContentstackClientOptions object, because the client writes the authtoken into it when you sign in or out.
using System.Threading.Tasks;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Microsoft.Extensions.DependencyInjection;
public static class ContentstackSetup
{
// Call from Program.cs: ContentstackSetup.AddServices(builder.Services)
public static void AddServices(IServiceCollection services)
{
ContentstackClientOptions options = new ContentstackClientOptions() { Authtoken = "<AUTHTOKEN>" };
services.AddSingleton(new ContentstackClient(options));
services.AddTransient<StackService>();
}
}
// The container passes the registered ContentstackClient.
public class StackService
{
private readonly ContentstackClient _client;
public StackService(ContentstackClient client)
{
_client = client;
}
public async Task<string> GetStackJsonAsync(string apiKey)
{
try
{
ContentstackResponse response = await _client.Stack(apiKey).FetchAsync();
return response.OpenJsonObjectResponse().ToJsonString();
}
catch (ContentstackErrorException e)
{
return e.ErrorMessage;
}
}
}SDK-Wide Notes
| Concern | Behavior | Default when unset |
|---|---|---|
| Authentication | The client sends its authtoken as the authtoken header. Set it in the constructor, or call Login or LoginAsync to get one. | No authtoken. Without an authtoken or a management token, the stack accessors throw InvalidOperationException before any request. |
| Two-factor sign-in | Login and LoginAsync send the two-factor authentication (2FA) code from token. When token is empty, the SDK generates the 2FA code from mfaSecret. | null for both, so the request carries no 2FA code, and an account with 2FA turned on fails to sign in. |
| Management tokens | client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>") sends the token as the authorization header on every request from that stack, instead of the authtoken. Some CMA requests accept only an authtoken, and each method page says when. | null, so the stack uses the client's authtoken. |
| OAuth | client.OAuth(options) returns an OAuthHandler. After the token exchange, the client sends authorization: Bearer <ACCESS_TOKEN> and refreshes the token before each async request when it expires in less than five minutes. | Not applicable. The client uses an authtoken until an OAuth token exchange. |
| Branches | Pass branchUid to client.Stack(). The SDK sends it as the branch header on every request from that stack. | null, so the SDK sends no branch header. |
| Sync and async methods | Each request method has a sync form and an Async form. await the async form, because .Result or .Wait() wraps an API rejection in AggregateException, and a catch (ContentstackErrorException) block does not catch it. | Not applicable. Both forms send the same request. |
| Error surfacing | A status outside 2xx throws ContentstackErrorException with StatusCode, ErrorCode, ErrorMessage, and Errors. Client-side checks throw InvalidOperationException, ArgumentException, or ArgumentNullException before any request. | Not applicable. A network failure throws the original .NET exception, such as TaskCanceledException or HttpRequestException. |
| Responses | A returned ContentstackResponse always has a 2xx status. Read its raw JSON body with OpenJsonObjectResponse() or OpenTResponse<T>(). | Not applicable. The SDK never maps the body to a model by itself. |
| Query parameters | Pass a ParameterCollection to the collection argument of a request method. The SDK does not URL-encode its names or values, except for AddQuery. | null, so the request carries no extra parameters. |
| Rate limiting and retry | This SDK automatically retries on 429 with configurable delay and attempt limits. It also retries 500 to 504 statuses and network failures, and it does not read the Retry-After header. See the ContentstackClientOptions class page. | On. RetryLimit 5 with a RetryDelay of 300 milliseconds, and MaxNetworkRetries 3 with a NetworkRetryDelay of 100 milliseconds. |
| Timeouts | Set Timeout on ContentstackClientOptions as a TimeSpan, or pass timeout in seconds to the settings constructor. The timeout applies to each attempt. | 30 seconds. |
| Regions and endpoints | The client has no region option. Set Host to the CMA host of the region, for example eu-api.contentstack.com, and look up a host with the Endpoint class. | api.contentstack.io, port 443, API version v3. |
| Proxy configuration | Set ProxyHost, ProxyPort, and ProxyCredentials on ContentstackClientOptions. The SDK does not use them when you pass your own HttpClient. | ProxyPort -1, so the client uses no proxy. |
| Client settings | The constructor applies the timeout, proxy, and retry settings once, and the client writes Authtoken into its options object when you sign in or out. Create a new client to change a setting, and give each client its own options object. | Not applicable. |
| JSON | The SDK reads and writes JSON with System.Text.Json only and leaves null model properties out of request bodies. Use [JsonPropertyName] when a property name differs from its JSON key. | client.SerializerOptions, with case-insensitive names, null values skipped, and the SDK's converters. |
| Logging | The client writes retry and error lines to the console. Set DisableLogging to true to turn them off. | false, so the client logs to the console. |
| Dependency injection | Register ContentstackClient in your ASP.NET Core container yourself. The registration methods of contentstack.management.aspnetcore register no client, as the Known issue in Key Usage Patterns above describes. | Not applicable. Without a registration, create the client with a constructor. |
Warning This SDK sends an authtoken, an OAuth access token, or a management token. Neither the constructor nor client.Stack() checks a token, so a delivery token or a preview token in their place fails at the first request with ContentstackErrorException. Refer to Content Management API Errors for the full error code list.
Known issue When the API keeps returning a 500 to 504 status, the client retries without a limit and the call never returns. Set RetryOnHttpServerError to false and RetryCondition to a function that leaves out 500 to 504, for example status => (int)status == 429, or set RetryOnError to false.
SDK Limitations
| Capability | Supported | Notes / Alternative |
|---|---|---|
| Select a region by name | No | Set Host to the region's CMA host. The Endpoint class looks up a region's hosts. |
| Honor the Retry-After header | No | Set RetryDelay or RetryDelayOptions.CustomBackoff to wait longer between retries. |
| Read every page of a list in one call | No | Call Find once per page with a new query and a higher Skip value, as in Key Usage Patterns above. |
| Refresh an OAuth token before a sync request | No | Use async request methods, or call RefreshTokenAsync on the OAuthHandler. |
| Change a client setting after construction | No | Create a new client with a new ContentstackClientOptions object. |
| Read or write Newtonsoft.Json types | No | Use System.Text.Json types. Refer to Migrate the .NET Management SDK from Newtonsoft.Json to System.Text.Json. |
| Log to a destination other than the console | No | Set DisableLogging to true and log in your own code. |