API Client Introduction
The Content Island API client is a JavaScript library that allows you to interact with the REST API. It provides a simple and easy-to-use interface to fetch all projects and content in your Content Island account. The library is designed for use in web and mobile applications and is compatible with modern browsers and Node.js.
Installation
You can install the Content Island API client using your preferred package manager:
npm install @content-island/api-clientpnpm add @content-island/api-clientyarn add @content-island/api-clientRequirements
- Node.js 18.x or higher.
TypeScript is optional, but recommended for the best development experience. The Content Island API client is written in TypeScript and provides types for all functions and exposed objects.
Usage
Once installed, follow these steps to set up and use the Content Island API client:
-
Create an instance of the API client using your project’s
access token. You can find the access token in the General tab.import { createClient } from '@content-island/api-client';const client = createClient({ accessToken: "YOUR_ACCESS_TOKEN" }); -
You can now use the client to interact with the Content Island API. For example, to fetch all content from your project:
const contents = await client.getContentList(); -
To fetch content from a specific model you’ve defined, such as the
postmodel:const posts = await client.getContentList<Post>({ contentType: 'post' });
For more information on how to retrieve content from your project, see the getContentList and getContent methods.
Write methods
The client can also create, modify and upload content, and manage the project’s schema. These methods require a Write Token as the accessToken — a read token is not enough and will return 403 Forbidden.
Content:
- createContent — create a new content entry.
- updateContentFieldValue — update (or upsert) a single field value.
- publishContent — publish an entry so it becomes visible to read-token consumers.
- uploadMedia — upload a file (image, video, …) to your project’s storage.
Schema (models & enums):
- createModel — create an Entity (content type) with a field list.
- updateModel — update an Entity’s name and fields.
- deleteModel — delete an Entity and all of its content.
- createEnum — create an Enum (closed list of values).
- updateEnum — update an Enum’s name and values.
- deleteEnum — delete an Enum.
Handling errors
Every client method throws a typed ApiClientError when the request fails — covering server-side failures (UNAUTHORIZED, NOT_FOUND, VALIDATION_ERROR, …) and client-side ones (NETWORK_ERROR). See Handling errors for the recommended try / catch pattern and the migration guide from v0.20.x.