Stack
Stack
Stack represents one Contentstack stack, the space that holds the content of a project. Use this class to
- list the stacks of your account and create new ones
- fetch, rename, share, or transfer one stack
- read and change the stack settings
- get the objects that manage the content types, entries, assets, languages, environments, and other resources of the stack
When to Use This Class: Start every stack-level task here. Every resource of a stack comes from an accessor method of this class.
Conceptual Role: Acts as the entry point for stack-level Content Management API requests and as the factory for the resource classes.
Returns: Stack. A handle for stack operations.
Create an instance with the Stack method of ContentstackClient, which takes the parameters below. The public constructor new Stack(client, apiKey, managementToken, branchUid) takes the same values after the client.
| Name | Type | Description |
|---|---|---|
| apiKey | string? | API key of the stack. Omit it for GetAll and Create. |
| managementToken | string? | Management token for the stack. Sent instead of the authtoken. |
| branchUid | string? | Branch UID. Sent as the branch header on every request. |
Instance State
The API key you pass to client.Stack() decides which methods you can call:
- Call client.Stack() without an API key to work across your account, for example GetAll or Create.
- Call client.Stack("<API_KEY>") to work with one stack, for example Fetch, Update, or an accessor such as ContentType.
A method from the other group throws InvalidOperationException before any request leaves the SDK. The Method Index below lists every method in each group.
Warning The SDK treats an empty string as no API key in its checks. client.Stack("") allows GetAll and Create, but Create then sends the Update stack request instead of the Create stack request. Call client.Stack() with no arguments when you mean no stack.
Class-Level Notes
Credentials.
- Every method, including each accessor, throws InvalidOperationException when the client has no authtoken and the Stack has no management token. The method pages do not repeat this check.
- When the Stack has a management token, the SDK sends it in the authorization header and leaves the authtoken out of the request.
- The Content Management API reference lists only the authtoken for the stack requests on this class, from GetAll to UnShare. Create the Stack without a management token for those methods. The resource classes that the accessors return describe the credentials their own requests accept.
Branch scoping.
- The branchUid you pass to client.Stack() goes out as the branch header on every request from this Stack, including the requests of the objects its accessors return.
Accessors.
- An accessor such as Environment returns a new object and sends no request. The returned object builds its request path from the UID you pass, when the accessor runs.
- Pass no argument, or null, when you mean the collection. The resource classes treat an empty string as no UID in their checks but still add it to the path.
Requests and responses.
- Each method that is not an accessor sends one request and returns the raw API response as ContentstackResponse. Read the body with OpenJsonObjectResponse().
Rate Limiting & Retry.
- The client retries requests from this class, as its ContentstackClient settings set.
Additional Resource For more information on retry settings, refer to the ContentstackClientOptions documentation.
Capability Matrix
| Capability | Supported | Notes / Alternative |
|---|---|---|
| Delete a stack | No | The Content Management API has a Delete stack request. This SDK has no method for it. |
| List the users of a stack | No | The Content Management API has a Get all users of a stack request. This SDK has no method for it. |
| Accept a stack ownership invitation | No | The invited user accepts through the link in the invitation email. |
| Reset the stack settings to defaults | No | See the Known issue on the ResetSettings method. |
| Send the organization_uid header on Fetch or GetAll | No | The Content Management API reference requires it for organizations that enable single sign-on. |
Properties
| Property | Type | Access | Default | Description |
|---|---|---|---|---|
| APIKey | string? | Read-only | The apiKey argument | API key of the stack, sent as the api_key header. |
| ManagementToken | string? | Read-only | The managementToken argument | Management token, sent as the authorization header. |
| BranchUid | string? | Read-only | The branchUid argument | Branch UID, sent as the branch header. |
Method Index
The first group needs a Stack without an API key. Every other group needs a Stack with one.
Work across your account. Available on client.Stack() with no API key.
| Method Name | Returns | Description |
|---|---|---|
| GetAll | The API response with the stacks your account owns or shares. | Lists the stacks of your account. |
| GetAllAsync | The API response with the stacks your account owns or shares. | Lists the stacks of your account asynchronously. |
| Create | The API response with the created stack. | Creates a stack in an organization. |
| CreateAsync | The API response with the created stack. | Creates a stack asynchronously. |
Manage the stack. Available on client.Stack("<API_KEY>").
| Method Name | Returns | Description |
|---|---|---|
| Fetch | The API response with the requested stack. | Gets the details of the stack. |
| FetchAsync | The API response with the requested stack. | Gets the details of the stack asynchronously. |
| Update | The API response with the updated stack. | Changes the name and description. |
| UpdateAsync | The API response with the updated stack. | Changes the name and description asynchronously. |
| TransferOwnership | The API response with the transfer notice. | Invites a user to own the stack. |
| TransferOwnershipAsync | The API response with the transfer notice. | Invites a user to own the stack asynchronously. |
Manage collaborators. Available on client.Stack("<API_KEY>").
| Method Name | Returns | Description |
|---|---|---|
| Share | The API response with the share notice. | Invites users with chosen roles. |
| ShareAsync | The API response with the share notice. | Invites users asynchronously. |
| UnShare | The API response with the unshare notice. | Removes a user from the stack. |
| UnShareAsync | The API response with the unshare notice. | Removes a user asynchronously. |
| UpdateUserRole | The API response with the role update notice. | Replaces the roles of existing users. |
| UpdateUserRoleAsync | The API response with the role update notice. | Replaces user roles asynchronously. |
Manage stack settings. Available on client.Stack("<API_KEY>").
| Method Name | Returns | Description |
|---|---|---|
| Settings | The API response with the stack settings. | Gets the stack settings. |
| SettingsAsync | The API response with the stack settings. | Gets the stack settings asynchronously. |
| AddSettings | The API response with the updated stack settings. | Adds or changes stack settings. |
| AddSettingsAsync | The API response with the updated stack settings. | Adds or changes settings asynchronously. |
| ResetSettings | The API response with the stack settings. | Sends empty settings objects. |
| ResetSettingsAsync | The API response with the stack settings. | Sends empty settings objects asynchronously. |
Get a resource object. Available on client.Stack("<API_KEY>"). These accessors send no request.
| Method Name | Returns | Description |
|---|---|---|
| ContentType | A new content type object. | Works with content types and their entries. |
| GlobalField | A new global field object. | Works with global fields. |
| Asset | A new asset object. | Works with assets and folders. |
| Extension | A new extension object. | Works with custom fields and widgets. |
| Label | A new label object. | Works with labels. |
| Taxonomy | A new taxonomy object. | Works with taxonomies and terms. |
| Locale | A new language object. | Works with languages. |
| Environment | A new environment object. | Works with publishing environments. |
| Branch | A new branch object. | Works with branches. |
| Release | A new release object. | Works with releases. |
| BulkOperation | A new bulk operation object. | Runs bulk publish, delete, and workflow actions. |
| Workflow | A new workflow object. | Works with workflows and publish rules. |
| PublishQueue | A new publish queue object. | Reads and cancels publish queue activities. |
| AuditLog | A new audit log object. | Reads the audit log. |
| Webhook | A new webhook object. | Works with webhooks. |
| Role | A new role object. | Works with roles. |
| VariantGroup | A new variant group object. | Works with variant groups. |
| DeliveryToken | A new delivery token object. | Works with delivery tokens. |
| PreviewToken | A new preview token object. | Works with the preview token of a delivery token. |
| ManagementTokens | A new management token object. | Works with management tokens. |
Class-Level Snippet
The snippet below fetches a stack, lists its languages and environments, and shares it with one user.
using System;
using System.Collections.Generic;
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>");
try
{
ContentstackResponse details = stack.Fetch();
Console.WriteLine(details.OpenJsonObjectResponse().ToJsonString());
ContentstackResponse languages = stack.Locale().Query().Find();
Console.WriteLine(languages.OpenJsonObjectResponse().ToJsonString());
ContentstackResponse environments = stack.Environment().Query().Find();
Console.WriteLine(environments.OpenJsonObjectResponse().ToJsonString());
List<UserInvitation> invitations = new List<UserInvitation>()
{
new UserInvitation() { Email = "<EMAIL>", Roles = new List<string>() { "<ROLE_UID>" } }
};
ContentstackResponse shared = stack.Share(invitations);
Console.WriteLine(shared.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Methods
Each method of the Stack class has its own section below, with its parameters, validation rules, behavior, and examples.
AddSettings
AddSettings adds settings to the stack or changes existing ones.
| Name | Type | Description |
|---|---|---|
| settings (required) | StackSettings | Settings to add to the stack. |
Returns: ContentstackResponse. The API response with the updated stack settings.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack whose settings you change. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if settings is null, because the request body holds the settings.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one POST /stacks/settings request with the body {"stack_settings": {...}}. See Add stack settings in the Content Management API reference.
- Serializes the StackSettings properties as stack_variables, discrete_variables, and rte. A property you leave null stays out of the body.
- The Content Management API reference lists stack variables such as enforce_unique_urls and sys_rte_allowed_tags.
- Set enforce_unique_urls to true to keep entry URLs unique across the stack. Set sys_rte_allowed_tags to a combination of figure, style, and script.
- Returns the raw API response with the stack settings. Read the body with OpenJsonObjectResponse().
Example
Basic usage: keep entry URLs unique across the stack
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
StackSettings settings = new StackSettings()
{
StackVariables = new Dictionary<string, object>() { { "enforce_unique_urls", true } }
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").AddSettings(settings);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Set two stack variables in one request
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
StackSettings settings = new StackSettings()
{
StackVariables = new Dictionary<string, object>()
{
{ "enforce_unique_urls", true },
{ "sys_rte_allowed_tags", "figure, style" }
}
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").AddSettings(settings);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}AddSettingsAsync
AddSettingsAsync adds settings to the stack or changes existing ones, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| settings (required) | StackSettings | Settings to add to the stack. |
Returns: Task<ContentstackResponse>. The API response with the updated stack settings.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack whose settings you change. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if settings is null, because the request body holds the settings.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The client-side checks above run when you call AddSettingsAsync, before it returns the task. An API rejection surfaces when you await the task.
- Otherwise behaves like AddSettings.
Example
Basic usage: keep entry URLs unique across the stack
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
StackSettings settings = new StackSettings()
{
StackVariables = new Dictionary<string, object>() { { "enforce_unique_urls", true } }
};
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").AddSettingsAsync(settings);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Set two stack variables in one request
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
StackSettings settings = new StackSettings()
{
StackVariables = new Dictionary<string, object>()
{
{ "enforce_unique_urls", true },
{ "sys_rte_allowed_tags", "figure, style" }
}
};
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").AddSettingsAsync(settings);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Asset
Asset returns a new Asset object that uploads, fetches, updates, publishes, or deletes the assets of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one asset. Omit it for all assets. |
Returns: Asset. A new asset object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every asset request identifies the stack by its API key.
- The SDK does not check uid. A value that names no asset reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /assets when uid is null, or /assets/<ASSET_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one asset, or no argument to work with all assets. The Asset class page lists the methods for each case.
Example
Basic usage: fetch one asset
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Asset("<ASSET_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all assets with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Asset().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}AuditLog
AuditLog returns a new AuditLog object that lists or fetches the audit log items of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one audit log item. Omit it for all audit log items. |
Returns: AuditLog. A new audit log object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every audit log request identifies the stack by its API key.
- The SDK does not check uid. A value that names no audit log reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /audit-logs when uid is null, or /audit-logs/<AUDIT_LOG_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one audit log, or no argument to work with all audit log items. The AuditLog class page lists the methods for each case.
Example
Basic usage: fetch one audit log
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").AuditLog("<AUDIT_LOG_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all audit log items with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").AuditLog().FindAll();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Branch
Branch returns a new Branch object that creates, fetches, lists, or deletes the branches of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one branch. Omit it for all branches. |
Returns: Branch. A new branch object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every branch request identifies the stack by its API key.
- The SDK does not check uid. A value that names no branch reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /stacks/branches when uid is null, or /stacks/branches/<BRANCH_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one branch, or no argument to work with all branches. The Branch class page lists the methods for each case.
- The branchUid you pass to client.Stack() still goes out as a branch header on every request, but the branch a method acts on comes from uid.
Example
Basic usage: fetch one branch
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Branch("<BRANCH_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all branches with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Branch().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}BulkOperation
BulkOperation returns a new BulkOperation object that publishes, unpublishes, or deletes many entries and assets in one request. It also updates workflow stages and release items in bulk.
This method takes no parameters.
Returns: BulkOperation. A new bulk operation object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every bulk request identifies the stack by its API key.
Behavior
- Sends no request. The returned object sends one when you call a method on it, such as Publish or JobStatus.
- Takes no UID. One object serves every bulk method, and each method takes its own details object.
- The BulkOperation class page, in the Bulk Operations folder of this reference, lists the methods and the detail classes each one takes.
Example
Basic usage: check the status of a bulk job
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").BulkOperation().JobStatus("<JOB_ID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Check a bulk job with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
BulkOperation bulk = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").BulkOperation();
ContentstackResponse response = bulk.JobStatus("<JOB_ID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}ContentType
ContentType returns a new ContentType object that works with the content types of the stack and the entries in them.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one content type. Omit it for all content types. |
Returns: ContentType. A new content type object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every content type request identifies the stack by its API key.
- The SDK does not check uid. A value that names no content type reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /content_types when uid is null, or /content_types/<CONTENT_TYPE_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one content type, or no argument to work with all content types. The ContentType class page lists the methods for each case.
- Reach the entries of a content type through the returned object, for example stack.ContentType("<CONTENT_TYPE_UID>").Entry("<ENTRY_UID>").
Example
Basic usage: fetch one content type
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ContentType("<CONTENT_TYPE_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all content types with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").ContentType().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Create
Create creates a new stack in an organization.
| Name | Type | Description |
|---|---|---|
| name (required) | string | Name of the new stack. |
| masterLocale (required) | string | Master language code, such as en-us. |
| organisationUid (required) | string | UID of the organization that owns the stack. |
| description | string? | Description of the new stack. |
Returns: ContentstackResponse. The API response with the created stack.
Validation
- Throws InvalidOperationException if the Stack has an API key, because Create makes a new stack, and an API key names an existing one. Create it with client.Stack().
- Throws ArgumentNullException if name, masterLocale, or organisationUid is null or empty, because the API needs all three to create a stack.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one POST /stacks request. See Create stack in the Content Management API reference.
- Sends organisationUid in the organization_uid header, and name, description, and masterLocale in the body as {"stack": {"name", "description", "master_locale"}}.
- Leaves description out of the body when it is null or empty.
- The Content Management API reference allows one new stack per minute in an organization.
- The master language cannot change after the API creates the stack. The Update method changes only the name and the description.
- Create does not store the new stack's API key on this Stack. Read the API key from the response, then call client.Stack("<API_KEY>") to work with the new stack.
- The parameter name uses the British spelling organisationUid. Write organisationUid: if you pass it as a named argument.
- On a Stack created with an empty string as the API key, Create sends PUT /stacks, the Update stack request, instead. Create the Stack with client.Stack() and no arguments.
Example
Basic usage: create a stack
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack().Create("Company Website", "en-us", "<ORGANIZATION_UID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: create a stack with a description, using named arguments
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack().Create(
name: "Company Website",
masterLocale: "en-us",
organisationUid: "<ORGANIZATION_UID>",
description: "Content for the public website");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Edge case: a missing master language throws before any request
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack().Create("Company Website", "", "<ORGANIZATION_UID>");
}
catch (ArgumentNullException e)
{
// Thrown because masterLocale is empty
Console.WriteLine(e.Message);
}CreateAsync
CreateAsync creates a new stack in an organization, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| name (required) | string | Name of the new stack. |
| masterLocale (required) | string | Master language code, such as en-us. |
| organisationUid (required) | string | UID of the organization that owns the stack. |
| description | string? | Description of the new stack. |
Returns: Task<ContentstackResponse>. The API response with the created stack.
Validation
- Throws InvalidOperationException if the Stack has an API key, because Create makes a new stack, and an API key names an existing one. Create it with client.Stack().
- Throws ArgumentNullException if name, masterLocale, or organisationUid is null or empty, because the API needs all three to create a stack.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The client-side checks above run when you call CreateAsync, before it returns the task. An API rejection surfaces when you await the task.
- Otherwise behaves like Create.
Example
Basic usage: create a stack
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack().CreateAsync("Company Website", "en-us", "<ORGANIZATION_UID>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: create a stack with a description
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack().CreateAsync("Company Website", "en-us", "<ORGANIZATION_UID>", "Content for the public website");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}DeliveryToken
DeliveryToken returns a new DeliveryToken object that creates, fetches, updates, or deletes the delivery tokens of the stack. A delivery token authenticates Content Delivery API requests for the published content of an environment.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one delivery token. Omit it for all delivery tokens. |
Returns: DeliveryToken. A new delivery token object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every delivery token request identifies the stack by its API key.
- The SDK does not check uid. A value that names no delivery token reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path stacks/delivery_tokens when uid is null, or stacks/delivery_tokens/<DELIVERY_TOKEN_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one delivery token, or no argument to work with all delivery tokens. The DeliveryToken class page lists the methods for each case.
- The returned object lives in the Contentstack.Management.Core.Models.Token namespace. Add using Contentstack.Management.Core.Models.Token; to declare a variable of its type.
Example
Basic usage: fetch one delivery token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Token;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").DeliveryToken("<DELIVERY_TOKEN_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all delivery tokens
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Token;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").DeliveryToken().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Environment
Environment returns a new Environment object that adds, fetches, updates, or deletes the publishing environments of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | Name of one environment. Omit it for all environments. |
Returns: Environment. A new environment object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every environment request identifies the stack by its API key.
- The SDK does not check uid. A value that names no environment reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /environments when uid is null, or /environments/<ENVIRONMENT_NAME> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one environment, or no argument to work with all environments. The Environment class page lists the methods for each case.
- Pass the environment name as uid. The Content Management API identifies an environment by its name in the request path.
Example
Basic usage: fetch one environment
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Environment("<ENVIRONMENT_NAME>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all environments with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Environment().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Extension
Extension returns a new Extension object that uploads, creates, fetches, updates, or deletes the extensions (custom fields and custom widgets) of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one extension. Omit it for all extensions. |
Returns: Extension. A new extension object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every extension request identifies the stack by its API key.
- The SDK does not check uid. A value that names no extension reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /extensions when uid is null, or /extensions/<EXTENSION_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one extension, or no argument to work with all extensions. The Extension class page lists the methods for each case.
Example
Basic usage: fetch one extension
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Extension("<EXTENSION_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all extensions with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Extension().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Fetch
Fetch gets the details of the stack whose API key you passed to client.Stack().
| Name | Type | Description |
|---|---|---|
| parameters | ParameterCollection? | Query parameters to add to the request. |
Returns: ContentstackResponse. The API response with the requested stack.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack to fetch. Create it with client.Stack("<API_KEY>").
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one GET /stacks request with the API key in the api_key header. See Get a single stack in the Content Management API reference.
- Adds each entry of parameters to the query string. The Content Management API reference lists include_collaborators, include_stack_variables, include_discrete_variables, and include_count for this request.
- Returns the raw API response with the details of the stack. Read the body with OpenJsonObjectResponse().
- Does not send an organization_uid header. The Content Management API reference requires that header for organizations that enable single sign-on.
Example
Basic usage: fetch the stack
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: fetch the stack with collaborators and stack variables
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ParameterCollection parameters = new ParameterCollection();
parameters.Add("include_collaborators", true);
parameters.Add("include_stack_variables", true);
parameters.Add("include_discrete_variables", true);
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Fetch(parameters);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}FetchAsync
FetchAsync gets the details of the stack whose API key you passed to client.Stack(), without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| parameters | ParameterCollection? | Query parameters to add to the request. |
Returns: Task<ContentstackResponse>. The API response with the requested stack.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack to fetch. Create it with client.Stack("<API_KEY>").
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The client-side checks above run when you call FetchAsync, before it returns the task. An API rejection surfaces when you await the task.
- Otherwise behaves like Fetch.
Example
Basic usage: fetch the stack
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").FetchAsync();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: fetch the stack with collaborators and stack variables
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ParameterCollection parameters = new ParameterCollection();
parameters.Add("include_collaborators", true);
parameters.Add("include_stack_variables", true);
parameters.Add("include_discrete_variables", true);
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").FetchAsync(parameters);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}GetAll
GetAll gets every stack that your account owns or that other users share with your account.
| Name | Type | Description |
|---|---|---|
| parameters | ParameterCollection? | Query parameters to add to the request. |
Returns: ContentstackResponse. The API response with the stacks your account owns or shares.
Validation
- Throws InvalidOperationException if the Stack has an API key, because GetAll lists the stacks of your account, and an API key selects one stack. Create it with client.Stack().
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one GET /stacks request without an api_key header. See Get all stacks in the Content Management API reference.
- Adds each entry of parameters to the query string. The Content Management API reference lists include_collaborators, include_stack_variables, include_discrete_variables, and include_count for this request.
- Returns the raw API response with every stack that your account owns or that other users share with it. Read the body with OpenJsonObjectResponse().
- Does not send an organization_uid header. The Content Management API reference requires that header for organizations that enable single sign-on.
- To list the stacks of one organization, use the GetStacks method of Organization.
Example
Basic usage: list your stacks
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack().GetAll();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: list stacks with collaborators, stack variables, and a count
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ParameterCollection parameters = new ParameterCollection();
parameters.Add("include_collaborators", true);
parameters.Add("include_stack_variables", true);
parameters.Add("include_count", true);
try
{
ContentstackResponse response = client.Stack().GetAll(parameters);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Edge case: call GetAll on a Stack that has an API key
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").GetAll();
}
catch (InvalidOperationException e)
{
// Thrown because GetAll needs a Stack without an API key
Console.WriteLine(e.Message);
}GetAllAsync
GetAllAsync gets every stack that your account owns or that other users share with your account, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| parameters | ParameterCollection? | Query parameters to add to the request. |
Returns: Task<ContentstackResponse>. The API response with the stacks your account owns or shares.
Validation
- Throws InvalidOperationException if the Stack has an API key, because GetAll lists the stacks of your account, and an API key selects one stack. Create it with client.Stack().
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The client-side checks above run when you call GetAllAsync, before it returns the task. An API rejection surfaces when you await the task.
- Otherwise behaves like GetAll.
Example
Basic usage: list your stacks
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack().GetAllAsync();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: list stacks with collaborators, stack variables, and a count
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Queryable;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
ParameterCollection parameters = new ParameterCollection();
parameters.Add("include_collaborators", true);
parameters.Add("include_stack_variables", true);
parameters.Add("include_count", true);
try
{
ContentstackResponse response = await client.Stack().GetAllAsync(parameters);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}GlobalField
GlobalField returns a new GlobalField object that creates, fetches, updates, or deletes the global fields of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one global field. Omit it for all global fields. |
| apiVersion | string? | Value of the api_version header for every request. |
Returns: GlobalField. A new global field object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every global field request identifies the stack by its API key.
- The SDK does not check uid. A value that names no global field reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /global_fields when uid is null, or /global_fields/<GLOBAL_FIELD_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one global field, or no argument to work with all global fields. The GlobalField class page lists the methods for each case.
- When you pass apiVersion, every request from the returned object, including Query().Find(), carries it as the api_version header. With null, the SDK sends no api_version header. The GlobalField class page describes the versions the API accepts.
Example
Basic usage: fetch one global field
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").GlobalField("<GLOBAL_FIELD_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: fetch a global field with an API version header
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").GlobalField("<GLOBAL_FIELD_UID>", "<API_VERSION>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}List all global fields with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").GlobalField().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Label
Label returns a new Label object that creates, fetches, updates, or deletes the labels that group the content types of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one label. Omit it for all labels. |
Returns: Label. A new label object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every label request identifies the stack by its API key.
- The SDK does not check uid. A value that names no label reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /labels when uid is null, or /labels/<LABEL_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one label, or no argument to work with all labels. The Label class page lists the methods for each case.
Example
Basic usage: fetch one label
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Label("<LABEL_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all labels with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Label().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Locale
Locale returns a new Locale object that adds, fetches, updates, or deletes the languages (locales) of the stack.
| Name | Type | Description |
|---|---|---|
| code | string? | Code of one language, such as fr-fr. Omit it for all languages. |
Returns: Locale. A new language object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every language request identifies the stack by its API key.
- The SDK does not check code. A value that names no language reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /locales when code is null, or /locales/<LOCALE_CODE> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one language, or no argument to work with all languages. The Locale class page lists the methods for each case.
Example
Basic usage: fetch one language
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Locale("<LOCALE_CODE>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all languages with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Locale().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}ManagementTokens
ManagementTokens returns a new ManagementToken object for the management tokens of the stack. A management token authenticates Content Management API requests for one stack.
Known issue The returned object builds its request path from /delivery_tokens, not from stacks/management_tokens, the path the Content Management API reference gives for management tokens. Requests from it do not reach the management token endpoints. Manage management tokens through the Content Management API directly.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one management token. Omit it for all management tokens. |
Returns: ManagementToken. A new management token object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every management token request identifies the stack by its API key.
- The SDK does not check uid. A value that names no management token reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /delivery_tokens when uid is null, or /delivery_tokens/<MANAGEMENT_TOKEN_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one management token, or no argument to work with all management tokens. The ManagementToken class page lists the methods for each case.
- The method name is plural, ManagementTokens, and the class it returns is singular, ManagementToken, in the Contentstack.Management.Core.Models.Token namespace.
Example
Basic usage: fetch one management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Token;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens("<MANAGEMENT_TOKEN_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all management tokens
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Token;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ManagementTokens().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}PreviewToken
PreviewToken returns a new PreviewToken object that creates or deletes the preview token of one delivery token.
| Name | Type | Description |
|---|---|---|
| deliveryTokenUid (required) | string | UID of the delivery token that owns the preview token. |
Returns: PreviewToken. A new preview token object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every preview token request identifies the stack by its API key.
- The SDK does not check deliveryTokenUid. A null, empty, or unknown value builds a request path with no valid delivery token, and the API rejects the Create or Delete call that follows.
Behavior
- Sends no request. The returned object sends one when you call Create, CreateAsync, Delete, or DeleteAsync on it.
- Builds the request path stacks/delivery_tokens/<DELIVERY_TOKEN_UID>/preview_token from deliveryTokenUid. The path holds no preview token UID, so Delete needs none.
- The returned object lives in the Contentstack.Management.Core.Models.Token namespace, together with PreviewTokenModel.
Example
Basic usage: create a preview token for a delivery token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Token;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
PreviewTokenModel model = new PreviewTokenModel() { Name = "Staging preview" };
try
{
ContentstackResponse response = client.Stack("<API_KEY>").PreviewToken("<DELIVERY_TOKEN_UID>").Create(model);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Delete the preview token of a delivery token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
using Contentstack.Management.Core.Models.Token;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").PreviewToken("<DELIVERY_TOKEN_UID>").Delete();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}PublishQueue
PublishQueue returns a new PublishQueue object that lists, fetches, or cancels the publish, unpublish, and release deployment activities of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one publish queue activity. Omit it for all publish queue activities. |
Returns: PublishQueue. A new publish queue object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every publish queue request identifies the stack by its API key.
- The SDK does not check uid. A value that names no publish queue reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /publish-queue when uid is null, or /publish-queue/<PUBLISH_QUEUE_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one publish queue, or no argument to work with all publish queue activities. The PublishQueue class page lists the methods for each case.
Example
Basic usage: fetch one publish queue
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").PublishQueue("<PUBLISH_QUEUE_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all publish queue activities with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").PublishQueue().FindAll();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Release
Release returns a new Release object that creates, fetches, updates, deploys, or deletes the releases of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one release. Omit it for all releases. |
Returns: Release. A new release object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every release request identifies the stack by its API key.
- The SDK does not check uid. A value that names no release reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /releases when uid is null, or /releases/<RELEASE_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one release, or no argument to work with all releases. The Release class page lists the methods for each case.
Example
Basic usage: fetch one release
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Release("<RELEASE_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all releases with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Release().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}ResetSettings
ResetSettings sends empty settings objects to the stack settings endpoint.
Known issue ResetSettings does not reset the stack settings. It sends POST /stacks/settings, the Add stack settings request, with empty settings objects, instead of POST /stacks/settings/reset, the Reset stack settings request. The current settings stay in place. To change a setting, pass its new value to the AddSettings method.
This method takes no parameters.
Returns: ContentstackResponse. The API response with the stack settings.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack whose settings you send. Create it with client.Stack("<API_KEY>").
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one POST /stacks/settings request with the body {"stack_settings": {"stack_variables": {}, "discrete_variables": {}, "rte": {}}}.
- Returns the raw API response with the stack settings. Read the body with OpenJsonObjectResponse().
Example
Basic usage: call ResetSettings
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").ResetSettings();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Set a stack variable back to a chosen value with AddSettings
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
StackSettings settings = new StackSettings()
{
StackVariables = new Dictionary<string, object>() { { "enforce_unique_urls", false } }
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").AddSettings(settings);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}ResetSettingsAsync
ResetSettingsAsync sends empty settings objects to the stack settings endpoint, without blocking the calling thread.
Known issue ResetSettings does not reset the stack settings. It sends POST /stacks/settings, the Add stack settings request, with empty settings objects, instead of POST /stacks/settings/reset, the Reset stack settings request. The current settings stay in place. To change a setting, pass its new value to the AddSettings method.
This method takes no parameters.
Returns: Task<ContentstackResponse>. The API response with the stack settings.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack whose settings you send. Create it with client.Stack("<API_KEY>").
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The client-side checks above run when you call ResetSettingsAsync, before it returns the task. An API rejection surfaces when you await the task.
- Otherwise behaves like ResetSettings.
Example
Basic usage: call ResetSettingsAsync
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ResetSettingsAsync();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Set a stack variable back to a chosen value with AddSettingsAsync
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
StackSettings settings = new StackSettings()
{
StackVariables = new Dictionary<string, object>() { { "enforce_unique_urls", false } }
};
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").AddSettingsAsync(settings);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Role
Role returns a new Role object that creates, fetches, updates, or deletes the roles of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one role. Omit it for all roles. |
Returns: Role. A new role object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every role request identifies the stack by its API key.
- The SDK does not check uid. A value that names no role reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /roles when uid is null, or /roles/<ROLE_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one role, or no argument to work with all roles. The Role class page lists the methods for each case.
Example
Basic usage: fetch one role
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Role("<ROLE_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all roles with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Role().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Settings
Settings gets the configuration settings of the stack.
This method takes no parameters.
Returns: ContentstackResponse. The API response with the stack settings.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack whose settings you read. Create it with client.Stack("<API_KEY>").
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one GET /stacks/settings request. See Get stack settings in the Content Management API reference.
- Returns the raw API response with the settings of the stack. Read the body with OpenJsonObjectResponse().
- When your organization has Disable Fallback Publishing turned on, the Content Management API reference states that the response includes the disable_fallback_publish key.
- To change settings, use the AddSettings method.
Example
Basic usage: read the stack settings
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Settings();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Read the stack settings and check the status code
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Settings();
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}SettingsAsync
SettingsAsync gets the configuration settings of the stack, without blocking the calling thread.
This method takes no parameters.
Returns: Task<ContentstackResponse>. The API response with the stack settings.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack whose settings you read. Create it with client.Stack("<API_KEY>").
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The client-side checks above run when you call SettingsAsync, before it returns the task. An API rejection surfaces when you await the task.
- Otherwise behaves like Settings.
Example
Basic usage: read the stack settings
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").SettingsAsync();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Read the stack settings and check the status code
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").SettingsAsync();
Console.WriteLine((int)response.StatusCode);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Share
Share invites users to collaborate on the stack, with the roles you choose.
| Name | Type | Description |
|---|---|---|
| invitations (required) | List<UserInvitation> | Users to invite and the role UIDs for each. |
Returns: ContentstackResponse. The API response with the share notice.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack to share. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if invitations is null, because the request body lists the users.
- The SDK reads Email and Roles from each item while it builds the request body, before the request leaves the SDK:
- Throws ArgumentNullException if an item has no Email.
- Throws NullReferenceException if an item has no Roles list.
- Throws ArgumentException if two items have the same Email.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one POST /stacks/share request with the body {"emails": ["<EMAIL>"], "roles": {"<EMAIL>": ["<ROLE_UID>"]}}. See Share a stack in the Content Management API reference.
- Reads only Email and Roles from each UserInvitation. The SDK ignores Uid here.
- To change the roles of a user who already has access, use the UpdateUserRole method.
Example
Basic usage: share the stack with one user
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
List<UserInvitation> invitations = new List<UserInvitation>()
{
new UserInvitation() { Email = "<EMAIL>", Roles = new List<string>() { "<ROLE_UID>" } }
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Share(invitations);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Share the stack with two users in one request
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
List<UserInvitation> invitations = new List<UserInvitation>()
{
new UserInvitation() { Email = "<EMAIL>", Roles = new List<string>() { "<ROLE_UID>" } },
new UserInvitation() { Email = "<SECOND_EMAIL>", Roles = new List<string>() { "<ROLE_UID>", "<SECOND_ROLE_UID>" } }
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Share(invitations);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}ShareAsync
ShareAsync invites users to collaborate on the stack, with the roles you choose, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| invitations (required) | List<UserInvitation> | Users to invite and the role UIDs for each. |
Returns: Task<ContentstackResponse>. The API response with the share notice.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack to share. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if invitations is null, because the request body lists the users.
- The SDK reads Email and Roles from each item while it builds the request body, before the request leaves the SDK:
- Throws ArgumentNullException if an item has no Email.
- Throws NullReferenceException if an item has no Roles list.
- Throws ArgumentException if two items have the same Email.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The API key check and the null list check run when you call ShareAsync, before it returns the task. An API rejection surfaces when you await the task.
- The exceptions the SDK throws while it builds the request body, for a missing Email or Roles or a repeated Email, surface when you await the task.
- Otherwise behaves like Share.
Example
Basic usage: share the stack with one user
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
List<UserInvitation> invitations = new List<UserInvitation>()
{
new UserInvitation() { Email = "<EMAIL>", Roles = new List<string>() { "<ROLE_UID>" } }
};
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ShareAsync(invitations);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Share the stack with two users in one request
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
List<UserInvitation> invitations = new List<UserInvitation>()
{
new UserInvitation() { Email = "<EMAIL>", Roles = new List<string>() { "<ROLE_UID>" } },
new UserInvitation() { Email = "<SECOND_EMAIL>", Roles = new List<string>() { "<ROLE_UID>", "<SECOND_ROLE_UID>" } }
};
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").ShareAsync(invitations);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Taxonomy
Taxonomy returns a new Taxonomy object that creates, fetches, updates, imports, exports, or deletes the taxonomies of the stack and reaches their terms.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one taxonomy. Omit it for all taxonomies. |
Returns: Taxonomy. A new taxonomy object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every taxonomy request identifies the stack by its API key.
- The SDK does not check uid. A value that names no taxonomy reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /taxonomies when uid is null, or /taxonomies/<TAXONOMY_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one taxonomy, or no argument to work with all taxonomies. The Taxonomy class page lists the methods for each case.
Example
Basic usage: fetch one taxonomy
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Taxonomy("<TAXONOMY_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all taxonomies with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Taxonomy().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}TransferOwnership
TransferOwnership invites another user to take over the ownership of the stack.
| Name | Type | Description |
|---|---|---|
| email (required) | string | Email address of the user who receives ownership. |
Returns: ContentstackResponse. The API response with the transfer notice.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack to transfer. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if email is null or empty, because the API sends the ownership invitation to that address.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one POST /stacks/transfer_ownership request with the body {"transfer_to": "<EMAIL>"}. See Transfer stack ownership to other users in the Content Management API reference.
- The API emails an invitation to the user. Ownership moves to that user when they accept the invitation through the link in the email, and not before.
- This SDK has no method that accepts an ownership invitation.
- To transfer the ownership of an organization instead, see the TransferOwnership method of Organization.
Example
Warning After the user accepts the invitation, the current owner loses every permission on the stack.
Basic usage: invite a user to own the stack
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").TransferOwnership("<EMAIL>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Edge case: an empty email address throws before any request
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").TransferOwnership("");
}
catch (ArgumentNullException e)
{
// Thrown because email is empty
Console.WriteLine(e.Message);
}TransferOwnershipAsync
TransferOwnershipAsync invites another user to take over the ownership of the stack, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| email (required) | string | Email address of the user who receives ownership. |
Returns: Task<ContentstackResponse>. The API response with the transfer notice.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack to transfer. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if email is null or empty, because the API sends the ownership invitation to that address.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The client-side checks above run when you call TransferOwnershipAsync, before it returns the task. An API rejection surfaces when you await the task.
- Otherwise behaves like TransferOwnership.
Example
Warning After the user accepts the invitation, the current owner loses every permission on the stack.
Basic usage: invite a user to own the stack
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").TransferOwnershipAsync("<EMAIL>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Edge case: an empty email address throws before any request
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").TransferOwnershipAsync("");
}
catch (ArgumentNullException e)
{
// Thrown because email is empty
Console.WriteLine(e.Message);
}UnShare
UnShare removes a user from the collaborators of the stack.
| Name | Type | Description |
|---|---|---|
| email (required) | string | Email address of the user to remove. |
Returns: ContentstackResponse. The API response with the unshare notice.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack to unshare. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if email is null, because the request body names the user to remove.
- The SDK does not check for an empty string. An empty email reaches the API.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one POST /stacks/unshare request with the body {"email": "<EMAIL>"}. See Unshare a stack in the Content Management API reference.
- The API removes the user from the collaborators of the stack. The user can no longer see the stack in their account.
Example
Warning The API removes the user's access to the stack. To give it back, share the stack again with the Share method.
Basic usage: remove a user from the stack
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").UnShare("<EMAIL>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Edge case: a null email address throws before any request
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
string email = null;
try
{
ContentstackResponse response = client.Stack("<API_KEY>").UnShare(email);
}
catch (ArgumentNullException e)
{
// Thrown because email is null
Console.WriteLine(e.Message);
}UnShareAsync
UnShareAsync removes a user from the collaborators of the stack, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| email (required) | string | Email address of the user to remove. |
Returns: Task<ContentstackResponse>. The API response with the unshare notice.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack to unshare. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if email is null, because the request body names the user to remove.
- The SDK does not check for an empty string. An empty email reaches the API.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The client-side checks above run when you call UnShareAsync, before it returns the task. An API rejection surfaces when you await the task.
- Otherwise behaves like UnShare.
Example
Warning The API removes the user's access to the stack. To give it back, share the stack again with the Share method.
Basic usage: remove a user from the stack
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").UnShareAsync("<EMAIL>");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Edge case: a null email address throws before any request
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
string email = null;
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").UnShareAsync(email);
}
catch (ArgumentNullException e)
{
// Thrown because email is null
Console.WriteLine(e.Message);
}Update
Update changes the name and the description of the stack whose API key you passed to client.Stack().
| Name | Type | Description |
|---|---|---|
| name (required) | string | New name of the stack. |
| description | string? | New description of the stack. |
Returns: ContentstackResponse. The API response with the updated stack.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack to update. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if name is null or empty, because Update always sends a name.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one PUT /stacks request with the body {"stack": {"name", "description"}}. See Update stack in the Content Management API reference.
- Leaves description out of the body when it is null or empty. Pass the current name again when you want to change only the description.
- Changes only the name and the description. The Content Management API reference states that the master language cannot change after you create the stack.
Example
Basic usage: rename the stack
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Update("Company Website (EU)");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: rename the stack and change its description
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Update("Company Website (EU)", "Content for the EU website");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}UpdateAsync
UpdateAsync changes the name and the description of the stack whose API key you passed to client.Stack(), without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| name (required) | string | New name of the stack. |
| description | string? | New description of the stack. |
Returns: Task<ContentstackResponse>. The API response with the updated stack.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack to update. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if name is null or empty, because Update always sends a name.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The client-side checks above run when you call UpdateAsync, before it returns the task. An API rejection surfaces when you await the task.
- Otherwise behaves like Update.
Example
Basic usage: rename the stack
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").UpdateAsync("Company Website (EU)");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}All parameters: rename the stack and change its description
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").UpdateAsync("Company Website (EU)", "Content for the EU website");
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}UpdateUserRole
UpdateUserRole replaces the roles of existing users of the stack.
| Name | Type | Description |
|---|---|---|
| usersRole (required) | List<UserInvitation> | Users and the role UIDs to give each one. |
Returns: ContentstackResponse. The API response with the role update notice.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack whose users you update. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if usersRole is null, because the request body lists the users.
- The SDK reads Uid and Roles from each item while it builds the request body, before the request leaves the SDK:
- Throws ArgumentNullException if an item has no Uid.
- Throws NullReferenceException if an item has no Roles list.
- Throws ArgumentException if two items have the same Uid.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Sends one POST /stacks/users/roles request with the body {"users": {"<USER_UID>": ["<ROLE_UID>"]}}. See Update User Role in the Content Management API reference.
- The API replaces the roles of each user with the roles you pass. A role you leave out is no longer assigned to that user.
- Reads only Uid and Roles from each UserInvitation. The SDK ignores Email here.
- An empty list sends {"users": {}}.
Example
Warning The API replaces the roles of each user you list. Include every role the user keeps.
Basic usage: give a user one role
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
List<UserInvitation> usersRole = new List<UserInvitation>()
{
new UserInvitation() { Uid = "<USER_UID>", Roles = new List<string>() { "<ROLE_UID>" } }
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").UpdateUserRole(usersRole);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Update the roles of two users in one request
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
List<UserInvitation> usersRole = new List<UserInvitation>()
{
new UserInvitation() { Uid = "<USER_UID>", Roles = new List<string>() { "<ROLE_UID>", "<SECOND_ROLE_UID>" } },
new UserInvitation() { Uid = "<SECOND_USER_UID>", Roles = new List<string>() { "<ROLE_UID>" } }
};
try
{
ContentstackResponse response = client.Stack("<API_KEY>").UpdateUserRole(usersRole);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}UpdateUserRoleAsync
UpdateUserRoleAsync replaces the roles of existing users of the stack, without blocking the calling thread.
| Name | Type | Description |
|---|---|---|
| usersRole (required) | List<UserInvitation> | Users and the role UIDs to give each one. |
Returns: Task<ContentstackResponse>. The API response with the role update notice.
Validation
- Throws InvalidOperationException if the Stack has no API key, because the API key selects the stack whose users you update. Create it with client.Stack("<API_KEY>").
- Throws ArgumentNullException if usersRole is null, because the request body lists the users.
- The SDK reads Uid and Roles from each item while it builds the request body, before the request leaves the SDK:
- Throws ArgumentNullException if an item has no Uid.
- Throws NullReferenceException if an item has no Roles list.
- Throws ArgumentException if two items have the same Uid.
- Throws ContentstackErrorException when the API rejects the request.
Additional Resource Refer to Content Management API Errors for the full error code list.
Behavior
- Returns a task. The API key check and the null list check run when you call UpdateUserRoleAsync, before it returns the task. An API rejection surfaces when you await the task.
- The exceptions the SDK throws while it builds the request body, for a missing Uid or Roles or a repeated Uid, surface when you await the task.
- Otherwise behaves like UpdateUserRole.
Example
Warning The API replaces the roles of each user you list. Include every role the user keeps.
Basic usage: give a user one role
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
List<UserInvitation> usersRole = new List<UserInvitation>()
{
new UserInvitation() { Uid = "<USER_UID>", Roles = new List<string>() { "<ROLE_UID>" } }
};
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").UpdateUserRoleAsync(usersRole);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}Update the roles of two users in one request
using System;
using System.Collections.Generic;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
List<UserInvitation> usersRole = new List<UserInvitation>()
{
new UserInvitation() { Uid = "<USER_UID>", Roles = new List<string>() { "<ROLE_UID>", "<SECOND_ROLE_UID>" } },
new UserInvitation() { Uid = "<SECOND_USER_UID>", Roles = new List<string>() { "<ROLE_UID>" } }
};
try
{
ContentstackResponse response = await client.Stack("<API_KEY>").UpdateUserRoleAsync(usersRole);
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}VariantGroup
VariantGroup returns a new VariantGroup object that lists the variant groups of the stack or links content types to one variant group.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one variant group. Omit it for all variant groups. |
Returns: VariantGroup. A new variant group object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every variant group request identifies the stack by its API key.
- The SDK does not check uid. A value that names no variant group reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /variant_groups when uid is null, or /variant_groups/<VARIANT_GROUP_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one variant group, or no argument to work with all variant groups. The VariantGroup class page lists the methods for each case.
Example
Basic usage: list the variant groups
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").VariantGroup().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List the variant groups with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").VariantGroup().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Webhook
Webhook returns a new Webhook object that creates, fetches, updates, or deletes the webhooks of the stack.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one webhook. Omit it for all webhooks. |
Returns: Webhook. A new webhook object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every webhook request identifies the stack by its API key.
- The SDK does not check uid. A value that names no webhook reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /webhooks when uid is null, or /webhooks/<WEBHOOK_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one webhook, or no argument to work with all webhooks. The Webhook class page lists the methods for each case.
Example
Basic usage: fetch one webhook
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Webhook("<WEBHOOK_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all webhooks with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Webhook().Query().Find();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}Workflow
Workflow returns a new Workflow object that creates, fetches, updates, enables, disables, or deletes the workflows of the stack and reaches their publish rules.
| Name | Type | Description |
|---|---|---|
| uid | string? | UID of one workflow. Omit it for all workflows. |
Returns: Workflow. A new workflow object.
Validation
- Throws InvalidOperationException if the stack has no API key, because every workflow request identifies the stack by its API key.
- The SDK does not check uid. A value that names no workflow reaches the API with the first request the returned object sends, and the API rejects that request.
Behavior
- Sends no request. The returned object sends one when you call a method on it.
- Builds the request path /workflows when uid is null, or /workflows/<WORKFLOW_UID> when you pass a value. The path stays fixed, even if you set the object's Uid property later.
- Pass a value to work with one workflow, or no argument to work with all workflows. The Workflow class page lists the methods for each case.
Example
Basic usage: fetch one workflow
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient("<AUTHTOKEN>");
try
{
ContentstackResponse response = client.Stack("<API_KEY>").Workflow("<WORKFLOW_UID>").Fetch();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
// Thrown when the API rejects the request
Console.WriteLine($"Request failed: {(int)e.StatusCode} {e.ErrorCode} {e.ErrorMessage}");
}List all workflows with a management token
using System;
using Contentstack.Management.Core;
using Contentstack.Management.Core.Exceptions;
using Contentstack.Management.Core.Models;
ContentstackClient client = new ContentstackClient();
try
{
ContentstackResponse response = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>").Workflow().FindAll();
Console.WriteLine(response.OpenJsonObjectResponse().ToJsonString());
}
catch (ContentstackErrorException e)
{
Console.WriteLine(e.ErrorMessage);
}