GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - contentstack/contentstack-management-dotnet: The Content Management SDK is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account

BranchesTags
Open more actions menu

Latest commit

 

History

582 Commits
582 Commits

Folders and files

NameName
Last commit message
Last commit date
.cursor/rules
.cursor/rules
 
 
.github
.github
 
 
Contentstack.Management.ASPNETCore
Contentstack.Management.ASPNETCore
 
 
Contentstack.Management.Core.Tests
Contentstack.Management.Core.Tests
 
 
Contentstack.Management.Core.Unit.Tests
Contentstack.Management.Core.Unit.Tests
 
 
Contentstack.Management.Core
Contentstack.Management.Core
 
 
Scripts
Scripts
 
 
build
build
 
 
docfx_project
docfx_project
 
 
skills
skills
 
 
.gitignore
.gitignore
 
 
.talismanrc
.talismanrc
 
 
AGENTS.md
AGENTS.md
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CSManagementSDK.snk
CSManagementSDK.snk
 
 
Contentstack.Management.Core.sln
Contentstack.Management.Core.sln
 
 
Directory.Build.props
Directory.Build.props
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
snyk.json
snyk.json
 
 

Repository files navigation

Contentstack

Contentstack Management .NET SDK

Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. All you have to do is build your application frontend, and Contentstack will take care of the rest. Read More.

This SDK uses the Content Management API (CMA). The CMA is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account. To use the CMA, you will need to authenticate your users with a Management Token or an Authtoken. Read more about it in Authentication.

Note: By using CMA, you can execute GET requests for fetching content. However, we strongly recommend that you always use the Content Delivery API to deliver content to your web or mobile properties.

Prerequisite

You need .NET 10 or above installed on your machine to use the Contentstack .NET CMA SDK.

Migrating from v0.x? Version 1.0.0 replaces Newtonsoft.Json with System.Text.Json and changes several public API signatures (e.g. OpenJObjectResponse() → OpenJsonObjectResponse(), SerializerSettings → SerializerOptions). See the migration guide before upgrading.

Installation

Open the terminal and install the contentstack module via ‘Package Manager’ command

PM> Install-Package Contentstack.Management.Core

And via ‘.Net CLI’

dotnet add package Contentstack.Management.Core

To use the module in your application, you need to first Add Namespace to your class

using Contentstack.Management.Core; // ContentstackClient, ContentstackClientOptions, ContentstackResponse 
using Contentstack.Management.Core.Models; // Stack, ContentType, Entry, Asset

Authentication

To use this SDK, you need to authenticate your users by using the Authtoken, credentials, or Management Token (stack-level token).

Authtoken

An Authtoken is a read-write token used to make authorized CMA requests, and it is a user-specific token.

var options = new ContentstackOptions()
{
    Host = "<API_HOST>",
    Authtoken = "<AUTHTOKEN>"
}
ContentstackClient client = new ContentstackClient(new OptionsWrapper<ContentstackClientOptions>(options));

Login

To Login to Contentstack by using credentials, you can use the following lines of code:

    ContentstackClient client = new ContentstackClient();
    NetworkCredential credentials = new NetworkCredential("<EMAIL>", "<PASSWORD>");

    // Sync call
    ContentstackResponse contentstackResponse = client.Login(credentials);

    // Async call
    client.LoginAsync(credentials).ContinueWith((t) => {
        if (t.IsCompleted && t.Status != System.Threading.Tasks.TaskStatus.Faulted)
        {
            // success
        }
    });
    

Management Token

Management Tokens are stack-level tokens, with no users attached to them.

    Stack stack = client.Stack("<API_KEY>", "<MANAGEMENT_TOKEN>");

Contentstack Management .NET SDK: 5-minute Quickstart

Initializing Your SDK:

To use the .Net CMA SDK, you need to first initialize it. To do this, use the following code:

using Contentstack.Management.Core;

var options = new ContentstackOptions()
    {
        Host = "<API_HOST>",
        Authtoken = "<AUTHTOKEN>"
    }
ContentstackClient client = new ContentstackClient(new OptionsWrapper<ContentstackClientOptions>(options));
For Setting the branch:

If you want to initialize the SDK in a particular branch, use the following code:

using Contentstack.Management.Core

ContentstackClient client = new ContentstackClient();
client.Stack("API_KEY", "MANAGEMENT_TOKEN", "BRANCH");
Proxy Configuration

Contentstack allows you to define HTTP proxy for your requests with the .NET Management SDK. A proxied request allows you to anonymously access public URLs even from within a corporate firewall through a proxy server.

Here is the basic syntax of the proxy settings that you can pass within fetchOptions of the .NET Management SDK:

using System.Net;
var contentstackConfig = new ContentstackClientOptions();
contentstackConfig.ProxyHost = "http://127.0.0.1";
contentstackConfig.ProxyPort = 9000;
contentstackConfig.ProxyCredentials = new NetworkCredential(userName: "username", password: "password");
ContentstackClient client = new ContentstackClient(new OptionsWrapper<ContentstackClientOptions>(options));

OAuth Authentication

As an alternative to Authtoken/Management Token authentication, you can use OAuth 2.0:

ContentstackClient client = new ContentstackClient();
var oauthOptions = new OAuthOptions
{
    AppId = "your-app-id",
    ClientId = "your-client-id",
    RedirectUri = "http://localhost:8184"
};
OAuthHandler oauthHandler = client.OAuth(oauthOptions);

// Get authorization URL
string authUrl = oauthHandler.GetAuthorizationUrl();

// After user authorization, exchange code for tokens
var tokens = await oauthHandler.ExchangeCodeForTokenAsync("authorization_code");

Note: Once authenticated, the SDK automatically refreshes expired OAuth tokens before making API calls — no manual token refresh required.

Branch Management

Use the Branch model to create, fetch, delete, and query branches for a stack:

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");

// Create a branch
BranchModel model = new BranchModel() { Uid = "my-branch", Source = "main" };
ContentstackResponse createResponse = client.Stack("<API_KEY>").Branch().Create(model);

// Fetch a branch
ContentstackResponse fetchResponse = client.Stack("<API_KEY>").Branch("my-branch").Fetch();

// Query all branches
ContentstackResponse queryResponse = client.Stack("<API_KEY>").Branch().Query().Find();

// Delete a branch
ContentstackResponse deleteResponse = client.Stack("<API_KEY>").Branch("my-branch").Delete();

Preview Token

Use PreviewToken to create or delete a Preview Token for a Delivery Token (compatible only with the rest-preview.contentstack.com endpoint):

ContentstackClient client = new ContentstackClient("<AUTHTOKEN>", "<API_HOST>");

// Create a preview token
PreviewTokenModel model = new PreviewTokenModel() { Name = "My Preview Token" };
ContentstackResponse createResponse = client.Stack("<API_KEY>").PreviewToken("<DELIVERY_TOKEN_UID>").Create(model);

// Delete a preview token
ContentstackResponse deleteResponse = client.Stack("<API_KEY>").PreviewToken("<DELIVERY_TOKEN_UID>").Delete();

Multi-region Endpoint Resolution

Use the Endpoint class to resolve Contentstack service URLs for any supported region without hardcoding hosts:

using Contentstack.Management.Core.Endpoints; // Endpoint

// Resolve the Content Management endpoint for a region
string url = Endpoint.GetContentstackEndpoint("us", "contentManagement");

// Strip the https:// scheme — useful when passing the host directly to SDK configuration
var options = new ContentstackClientOptions
{
    Host = Endpoint.GetContentstackEndpoint("eu", "contentManagement", omitHttps: true)
};

Fetch Stack Detail

Use the following lines of code to fetch your stack detail using this SDK:

ContentstackResponse contentstackResponse = client.Stack("<API_KEY>").Fetch();

var response = contentstackResponse.OpenJsonObjectResponse();
string title = response["title"]?.GetValue<string>();
// or
StackResponse model = contentstackResponse.OpenTResponse<StackResponse>();

Create an Entry

You can use the following code to create an entry in a specific content type of a stack through the SDK:

EntryModel entry = new EntryModel() {
   Title: "Sample Entry",
   Url: "/sampleEntry"
}
ContentstackClient client = new ContentstackClient();
Stack stack = client.Stack("API_KEY");
ContentstackResponse contentstackResponse = stack.ContentType("CONTENT_TYPE_UID").Entry().Create(entry);

Upload Assets

Use the following code snippet to upload assets to your stack through the SDK:

ContentstackClient client = new ContentstackClient();
Stack stack = client.Stack("API_KEY");

var path = Path.Combine(Environment.CurrentDirectory, "path/to/file");
AssetModel asset = new AssetModel("Asset Title", path, "application/json");
ContentstackResponse response = stack.Asset().Create(asset);

About

The Content Management SDK is used to manage the content of your Contentstack account. This includes creating, updating, deleting, and fetching content of your account

www.contentstack.com/docs/developers/apis/content-management-api/

Topics

cmscontent-management-systemcontentstackcontentstack-dotnetlibrarysdk

Resources

Readme
MIT license

Security policy

Security policy
Activity
Custom properties

Stars

2 stars

Watchers

8 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.