Coder Social home page Coder Social logo

colliercz / kontent-management-sdk-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kontent-ai/management-sdk-js

0.0 1.0 0.0 201 KB

SDK for Kentico Kontent Management API

Home Page: https://developer.kenticocloud.com

License: MIT License

JavaScript 2.36% TypeScript 97.64%

kontent-management-sdk-js's Introduction

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 Status 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

This library has a peer dependency on rxjswhich means you need to install it as well. You install it using npm or use it directly in browser using one of the cdn bundles.

npm

npm i rxjs --save
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-core';

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
                }
            }
        )
        .toObservable()
        .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',
			apiKey: 'yyy'
		});

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

Configuration

The ManagementClient contains several configuration options:

const client = new ManagementClient({
    // configuration options
});
Option Default Description
projectId N/A Required - Id of your Kentico Kontent project
apiKey N/A Required - Content management API Token
baseUrl https://manage.kontent.ai/v2/projects Base URL of REST api. Can be useful if you are using custom proxy or for testing purposes
retryAttempts 3 Number of retry attempts when error occures. To disable set the value to 0.
httpService HttpService Used to inject implementation of IHttpService used to make HTTP request across network. Can also be useful for testing purposes by returning specified responses.
retryStatusCodes [500] Array of request status codes that should be retried.

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.

kontent-management-sdk-js's People

Contributors

colliercz avatar enngage avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.