Skip to main content

Getting started with Contensis using the JavaScript Management API

Log in to add to favourites

Setting up your environment ๐ŸŒณ

BASH
1
2
mkdir contensis-js-management-api-project cd contensis-js-management-api-project
BASH
1
npm init -y

Setting up the client ๐Ÿงฐ

BASH
1
npm i contensis-management-api
BASH
1
npm i dotenv
JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
import { Client } from 'contensis-management-api'; const client = Client.create({ clientType: "client_credentials", clientDetails: { clientId: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET }, projectId: process.env.PROJECT_API_ID, rootUrl: `https://cms-${process.env.ALIAS}.cloud.contensis.com` });

Creating our API key ๐Ÿ”‘

The Create a new API key screen in Contensis.
JAVASCRIPT
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.
JAVASCRIPT
1
2
3
PROJECT_API_ID= {yourProjectId} ALIAS= {yourAlias}

Setting up API key roles and permissions ๐Ÿค

Allow Content Type creation permissions ๐Ÿ”

Creating our first Content Type ๐ŸŽจ

JAVASCRIPT
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
const newBookContentType = { id: 'book', projectId: 'website', name: { 'en-GB': 'Book ๐Ÿ“•' }, description: { 'en-GB': 'Use this content type to store information about books.', }, entryTitleField: 'title', entryDescriptionField: 'blurb', fields: [ { id: 'title', name: { 'en-GB': 'Title' }, dataType: 'string', }, { id: 'blurb', name: { 'en-GB': 'Blurb', }, dataType: 'string', editor: { id: 'multiline', }, }, ], defaultLanguage: 'en-GB', supportedLanguages: ['en-GB'], workflowId: 'contensisEntryBasic', dataFormat: 'entry', };
JAVASCRIPT
1
2
3
4
5
6
7
client.contentTypes.create(newBookContentType) .then(result => { console.log('API call result: ', result); }) .catch(error => { console.error('API call fetch error: ', error); });

Creating our first Entry ๐Ÿ“

JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
const newBookEntry = { title: 'How Not to Kill Your Houseplant', blurb: "Your guide to every stage of plant parenting for beginners, from identifying exactly what's in the pot, to helping it flourish and grow! If you wonder what the crispy bits at the leaf edges are, why the stalks are looking spindly, or why your plant looks brown even though you've watered it, How Not to Kill Your Houseplant will explain - and fix - your horticultural woes. Understand how much light, water, heat, and humidity your plant needs with quick tips on what your houseplant does and doesn't like. Learn to spot the danger signs and how to rescue an unhealthy plant, and follow easy advice to pick the top plants for your bathroom, cold rooms, desk, and windowsill to create your own indoor oasis.", sys: { contentTypeId: 'book', projectId: 'website', language: 'en-GB', dataFormat: 'entry', }, };
JAVASCRIPT
1
2
3
4
5
6
7
8
9
client.entries .create(newBookEntry) .then((result) => { console.log('API call result: ', result); }) .catch((error) => { console.log('API call fetch error: ', error); });

Still need help?

New support request