Skip to content

prezly/javascript-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b802363 · Apr 11, 2025
Jul 19, 2024
Apr 10, 2025
Oct 19, 2022
Jun 21, 2023
Dec 11, 2023
Nov 19, 2019
Nov 21, 2019
Oct 31, 2023
Dec 8, 2022
Oct 19, 2022
Apr 10, 2025
Dec 11, 2023

Repository files navigation

Prezly JavaScript SDK

Getting started

npm install --save @prezly/sdk
# or yarn
yarn add @prezly/sdk

Using the code

Using ES Modules:

import { createPrezlyClient } from '@prezly/sdk';

const prezlyClient = createPrezlyClient({
    accessToken: 'your-access-token',
});

Or Using CommonJS:

const { createPrezlyClient } = require('@prezly/sdk').default;

const prezlyClient = createPrezlyClient({
    accessToken: 'your-access-token',
});

Requirements

API token

At this moment, the UI does not support issuing API tokens. Please contact support to issue one for you.

fetch API support

@prezly/sdk is using fetch to create requests. We assume that the environment running the code supports it.

We understand that some of the environments, such as node.js or old browsers, do not support fetch. This can be resolved by including a polyfill.

Polyfilling in browsers using whatwg-fetch

npm install --save whatwg-fetch
# or yarn
yarn add whatwg-fetch
import 'whatwg-fetch';
// ...
import { createPrezlyClient } from '@prezly/sdk';

We recommend referring to the official whatwg-fetch module documentation for more information.

Polyfilling in browsers using node-fetch

npm install --save node-fetch
# or yarn
yarn add node-fetch
global.fetch = require('node-fetch');
// ...
const { createPrezlyClient } = require('@prezly/sdk');

We recommend referring to the official node-fetch module documentation for more information.

Platform-agnostic polyfill using cross-fetch

npm install --save cross-fetch
# or yarn
yarn add cross-fetch

Using ES Modules:

import 'cross-fetch/polyfill';
// ...
import { createPrezlyClient } from '@prezly/sdk';

Or Using CommonJS:

require('cross-fetch/polyfill');
// ...
const { createPrezlyClient } = require('@prezly/sdk');

We recommend referring to the official cross-fetch module documentation for more information.

Custom fetch implementation

Additionally, you can initialize the API client with your own implementation of fetch:

import { createPrezlyClient } = from '@prezly/sdk';

const prezlyClient = createPrezlyClient({
    accessToken: 'your-access-token',
    fetch: customFetch,
});