Back to Content Management API
templates
Returns an array of all your templates in a draft or published state paginated by a cursor.
Arguments
- Name
after- Type
- String
- Description
Returns the elements that come after the specified cursor.
- Name
before- Type
- String
- Description
Returns the elements that come before the specified cursor.
- Name
first- Type
- Int
- Description
Returns up to the first
nelements from the list.
- Name
last- Type
- Int
- Description
Returns up to the last
nelements from the list.
- Name
version- Type
- Version
- Description
The state of the templates you want to retrieve.
- To get the latest content use
CURRENT. - To get the latest published content use
PUBLISHED
- To get the latest content use
- Name
filter- Type
- TemplateFilterInput
- Description
Optional. Narrows the list.
type:TemplateTypeOne ofPAGE,ARTICLE,BLOG,PRODUCT, orCOLLECTION.title:StringMatches templates whose title contains this text, ignoring case.
To get localized content, pass language and country to the @inContext directive on the query instead. See Localization.
Returns
- Name
TemplateConnection.edges- Type
- [TemplateEdge]!
- Description
A list of edges.
- Name
TemplateConnection.nodes- Type
- [Template!]!
- Description
A list of the nodes contained in TemplateEdge.
- Name
TemplateConnection.pageInfo- Type
- PageInfo!
- Description
Information to aid in pagination.
- Name
TemplateConnection.totalCount- Type
- Int
- Description
The total count of items.
Request
import { PackClient } from '@pack/client'
const packClient = new PackClient({
token: 'YOUR-PACK-TOKEN'
});
const query = `
query {
templates(first: 5) {
edges {
cursor
node {
id
title
status
}
}
}
}
`
const response = await packClient.fetch(query);
console.log(response.data);
Response
{
"data": {
"templates": {
"edges": [
{
"cursor": "cursor",
"node": {
"id": "template-id",
"title": "Template Title",
"status": "DRAFT"
}
},
{
"cursor": "cursor",
"node": {
"id": "template-id",
"title": "Template Title",
"status": "PUBLISHED"
}
}
]
}
}
}