@vtex/client-cms
Version:
A client to fetch data from VTEX CMS.
60 lines (42 loc) • 1.26 kB
Markdown
# client-cms
This package is responsible for fetching data from VTEX CMS.
## Installation
To install `@vtex/client-cms` in your project, just run:
```
npm instal @vtex/client-cms
```
## Client Instance
To create a new ClientCMS instance you should use the ClientCMS class:
```javascript
const client = new ClientCMS({
tenant: '',
builder: '',
workspace: '',
host: '',
});
```
Where `tenant` is your store's account name and `workspace` is the VTEX IO workspace being used. Usually you won't to set this option, being `master` the default. You can use `builder` to specify a different source of data on the CMS, using 'faststore' as default.
### Querying data
With the client instance you should use the main three methods to query data:
To gets ids from all Content Types.
```javascript
const contentTypeIds = await client.getAllContentTypeIds();
```
To gets data from all pages of a given Content Type.
```javascript
const paginatedCMSPages = await client.getCMSPagesByContentType(
'contentTypeId',
{
page: 1,
perPage: 3,
}
);
```
To gets all data from a given page.
```javascript
const CMSPage = await client.getCMSPage({
contentType: '',
documentId: '',
versionId: '',
});
```