Skip to main content

Getting started with Contensis using the .Net Management API

Log in to add to favourites

Setting up your environment šŸŒ³

BASH
1
2
mkdir contensis-dot-net cd contensis-dot-net

Using a .Net template šŸ—ļø

BASH
1
dotnet new console

Creating our application šŸ’»

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
using System; using Zengenti.Contensis.Management; using DotNetEnv; namespace CreateEntries { class Program { static void Main() { } } }
C#
1
2
dotnet add package Zengenti.Contensis.Management dotnet add package DotNetEnv

Setting up the client šŸ§°

C#
1
2
3
4
5
6
7
8
9
// Load the .env file into environment variables DotNetEnv.Env.Load(); // Client Initlisation var client = ManagementClient.Create( rootUrl: string.Format("https://api-{0}.cloud.contensis.com", DotNetEnv.Env.GetString("ALIAS")), clientId: DotNetEnv.Env.GetString("CLIENT_ID"), sharedSecret: DotNetEnv.Env.GetString("CLIENT_SECRET") );

Creating our API key šŸ”‘

The Create a new API key screen in Contensis.
C#
1
2
3
CLIENT_ID= {your client ID} CLIENT_SECRET= {your shared secret}

Configuring your PROJECT_API_ID and ALIAS āš™ļø

The General Settings screen in Contensis with the API Name field highlighted.
C#
1
2
3
PROJECT_API_ID= {yourProjectId} ALIAS= {yourAlias}

Setting up API key roles and permissions šŸ¤

Creating our first Content Type šŸŽØ

The Create new content type window in Contensis.
Editing a field name in the Contensis content type editor.

Creating our first Entry šŸ“

C#
1
2
// Retrieve Project var myProject = client.Projects.Get(DotNetEnv.Env.GetString("PROJECT_API_ID"));
C#
1
2
// Create Entry var entryBook = myProject.Entries.New("book");
C#
1
2
// Set Fields entryBook.Set("bookTitle", "How not to kill your houseplants šŸŒ±");
C#
1
2
3
4
5
6
7
8
9
10
11
// Save Entry try { entryBook.Save(); Console.WriteLine("Successfully Created Entry!"); } catch (Exception ex) { Console.WriteLine("An unexpected error occurred: " + ex.Message); }
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System; using Zengenti.Contensis.Management; using DotNetEnv; namespace CreateEntries { class Program { static void Main() { // Load the .env file into environment variables DotNetEnv.Env.Load(); // Client Initlisation var client = ManagementClient.Create( rootUrl: string.Format("https://api-{0}.cloud.contensis.com", DotNetEnv.Env.GetString("ALIAS")), clientId: DotNetEnv.Env.GetString("CLIENT_ID"), sharedSecret: DotNetEnv.Env.GetString("CLIENT_SECRET") ); // Retrieve Project var myProject = client.Projects.Get(DotNetEnv.Env.GetString("PROJECT_API_ID")); // Create Entry var entryBook = myProject.Entries.New("book"); // Set Fields entryBook.Set("bookTitle", "How not to kill your houseplants šŸŒ±"); // Save Entry try { entryBook.Save(); Console.WriteLine("Successfully Created Entry!"); } catch (Exception ex) { Console.WriteLine("An unexpected error occurred: " + ex.Message); } } } }

Still need help?

New support request