Back to Content Management API
sectionUpsert
Creates or modifies an existing section.
Arguments
- Name
input
- Type
- SectionUpsertInput
- Description
An object.
...sectionfields
:...
Returns
- Name
Section.*
- Type
- Section
- Description
Any requested field from the Section object.
Request
import { PackClient } from '@pack/client'
const packClient = new PackClient({
token: 'YOUR-PACK-TOKEN'
});
const query = `
mutation SectionUpsert($input: SectionUpsertInput!) {
sectionUpsert(input: $input) {
id
title
handle
description
seo {
title
description
image
}
fields {
id
type
name
handle
required
localized
validations
settings
}
}
}
`;
const variables = {
"input": {
"title": "My Section",
"handle": "my-section",
"description": "This is my section.",
"seo": {
"title": "My Section",
"description": "This is my section.",
"image": "https://example.com/image.jpg"
},
"fields": [
{
"type": "text",
"name": "Text Field",
"handle": "text-field",
"required": true,
"localized": false,
"validations": {
"required": {}
},
"settings": {
"placeholder": "Enter text here"
}
}
]
}
};
const response = await packClient.fetch(query, { variables: variables });
console.log(response.data);
Response
{
"data": {
"sectionUpsert": {
"id": "section-id",
"title": "My Section",
"handle": "my-section",
"description": "This is my section.",
"seo": {
"title": "My Section",
"description": "This is my section.",
"image": "https://example.com/image.jpg"
},
"fields": [
{
"id": "field-id",
"type": "text",
"name": "Text Field",
"handle": "text-field",
"required": true,
"localized": false,
"validations": {
"required": {}
},
"settings": {
"placeholder": "Enter text here"
}
}
]
}
}
}