Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kentico/kontent-management

Package Overview
Dependencies
Maintainers
9
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kentico/kontent-management

Official Kentico kontent Content management API SDK

  • 1.0.0-next.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
442
increased by39.87%
Maintainers
9
Weekly downloads
 
Created
Source

Kontent Management Javascript SDK

Javascript SDK for the Kontent Management. Helps you manage content in your Kentico Kontent projects. Supports both node.js and browsers.

npm version Build & Test CircleCI npm Known Vulnerabilities GitHub license Gzip bundle

Getting started

To get started, you'll first need to have access to your Kentico Kontent project where you need to enable Content management API and generate access token that will be used to authenticate all requests made by this library.

Installation

npm i @kentico/kontent-management --save

Using a standalone version in browsers

If you'd like to use this library directly in browser, place following script tags to your html page. You may of course download it and refer to local versions of scripts.

<script src="https://cdn.jsdelivr.net/npm/rxjs/bundles/rxjs.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@kentico/kontent-management/_bundles/kontent-management.umd.min.js"></script>

Making the first request

The following code example shows how to create new content item in your Kentico Kontent project.

import { ManagementClient } from '@kentico/kontent-management';

const client = new ManagementClient({
        projectId: 'xxx', // id of your Kentico Kontent project
        apiKey: 'yyy', // Content management API token
    });

    client.addContentItem()
        .withData(
            {
                name: 'New article',
                type: {
                    codename: 'article' // codename of content type
                }
            }
        )
        .toPromise()
        .subscribe((response) => {
            // work with response
        },
        (error) => {
            // handle error
        });

If you are using UMD bundles directly in browsers, you can find this library under KontentManagement global variable.

<!DOCTYPE html>
<html>
<head>
    <title>Kontent management | jsdelivr cdn</title>
    <script src="https://cdn.jsdelivr.net/npm/rxjs/bundles/rxjs.umd.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/@kentico/kontent-management/_bundles/kontent-management.umd.min.js"></script>
</head>
<body>
    <script type="text/javascript">
        var KontentManagement = window['KontentManagement'];

		var client = new KontentManagement.ManagementClient({
			projectId: 'xxx',
	                // using CM API key in browser is NOT safe. If you need to use SDK in browsers
			// you should use proxy server and set authorization header there rather than here
			apiKey: 'yyy'
		});

		client.addContentItem()
            .withData(
                {
                    name: 'New article',
                    type: {
                        codename: 'article'
                    },
                }
            )
            .toPromise()
            .subscribe((response) => {
                // work with response
            },
            (error) => {
                // handle error
            });
	</script>
</body>
</html>

Configuration

The ManagementClient contains several configuration options:

const client = new ManagementClient({
    // configuration options
});
OptionDefaultDescription
projectIdN/ARequired - Id of your Kentico Kontent project
apiKeyN/ARequired - Content management API Token
baseUrlhttps://manage.kontent.ai/v2/projectsBase URL of REST api. Can be useful if you are using custom proxy or for testing purposes
retryStrategyundefinedRetry strategy configuration. If not set, default strategy is used.
httpServiceHttpServiceUsed to inject implementation of IHttpService used to make HTTP request across network. Can also be useful for testing purposes by returning specified responses.

Handling Managemeng Errors

try {
    const client = await new ManagementClient({
        projectId: 'x',
        apiKey: 'y'
    });
    await client.viewContentItem().byItemCodename('invalid codename').toPromise();
} catch (err) {
    if (err instanceof SharedModels.ContentManagementBaseKontentError) {
        // Error message provided by API response and mapped by SDK
        const message = err.message;
    } else {
        // handle generic error however you need
    }
}

Cancelling Requests

const client = await new ManagementClient({
    projectId: 'x',
    apiKey: 'y'
});

// prepare cancel token
const cancelTokenRequest = client.createCancelToken();

client
    .listContentItems()
    .withCancelToken(cancelTokenRequest)
    .toPromise()
    .then((x) => {
        // will not be executed as request was cancelled before network
        // request got a chance to finish
    })
    .catch((err) => {
        // error with your custom message 'Request manually cancelled'
    });

// cancel request right away
cancelTokenRequest.cancel('Request manually cancelled');

Testing

If you want to mock http responses, it is possible to use external implementation of configurable Http Service as a part of the client configuration.

Troubleshooting & feedback

If you have any issues or want to share your feedback, please feel free to create an issue in this GitHub repository.

Contributions

Contributions are welcomed. If you have an idea of what you would like to implement, let us know and lets discuss details of your PR.

Keywords

FAQs

Package last updated on 26 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc