@dotcms/client
@dotcms/client
is the official dotCMS JavaScript library designed to simplify interactions with the DotCMS REST APIs.
This client library provides a streamlined, promise-based interface to fetch pages and navigation API.
Features
- Easy-to-use methods to interact with the DotCMS Page and Navigation APIs.
- Support for custom actions to communicate with the DotCMS page editor.
- Comprehensive TypeScript typings for better development experience.
Installation
Install the package via npm:
npm install @dotcms/client
Or using Yarn:
yarn add @dotcms/client
Usage
First, initialize the client with your DotCMS instance details.
import { dotcmsClient } from '@dotcms/client';
const client = dotcmsClient.init({
dotcmsUrl: 'https://your-dotcms-instance.com',
authToken: 'your-auth-token',
siteId: 'your-site-id'
});
Fetching a Page
Retrieve the elements of any page in your DotCMS system in JSON format.
const pageData = await client.getPage({
path: '/your-page-path',
language_id: 1,
personaId: 'optional-persona-id'
});
console.log(pageData);
Fetching Navigation
Retrieve information about the DotCMS file and folder tree.
const navData = await client.getNav({
path: '/',
depth: 2,
languageId: 1
});
console.log(navData);
API Reference
Detailed documentation of the @dotcms/client
methods, parameters, and types can be found below:
dotcmsClient.init(config: ClientConfig): DotCmsClient
Initializes the DotCMS client with the specified configuration.
DotCmsClient.getPage(options: PageApiOptions): Promise<unknown>
Retrieves the specified page's elements from your DotCMS system in JSON format.
DotCmsClient.getNav(options: NavApiOptions): Promise<unknown>
Retrieves information about the DotCMS file and folder tree.
Contributing
GitHub pull requests are the preferred method to contribute code to dotCMS. Before any pull requests can be accepted, an automated tool will ask you to agree to the dotCMS Contributor's Agreement.
Licensing
dotCMS comes in multiple editions and as such is dual licensed. The dotCMS Community Edition is licensed under the GPL 3.0 and is freely available for download, customization and deployment for use within organizations of all stripes. dotCMS Enterprise Editions (EE) adds a number of enterprise features and is available via a supported, indemnified commercial license from dotCMS. For the differences between the editions, see the feature page.
Support
If you need help or have any questions, please open an issue in the GitHub repository.
Documentation
Always refer to the official DotCMS documentation for comprehensive guides and API references.
Getting Help