Back to Content Management API

contentAddSectionsBulk

Adds sections to several pages, articles, blogs, product pages, or collection pages at once, in a background job. Unlike the per-type *AddSectionsBulk mutations, the items can be of different types.

content and input are paired by position: the sections in input[0] are added to content[0], and so on, so both lists must be the same length. New sections go after the item's existing sections, and sections already on the item are skipped. The items are saved as drafts.

Arguments

  • Name
    content
    Type
    [ContentInput!]!
    Description

    The items to add sections to.

    • id: String!
    • type: ContentType! page, article, blog, product, or collection.
  • Name
    input
    Type
    [ContentAddSectionsInput!]!
    Description

    The sections to add to each item, in the same order as content.

    • sectionIds: [ID!]! The IDs of the sections to add.
    • strategy: DuplicateSectionStrategy! clone adds a new copy of each section; link adds the existing section, shared with the content it already appears on.

Returns

  • Name
    Job
    Type
    Job
    Description

    The id of the background job. There's no query to check a job's status; the change appears once the job finishes.

Request

import { PackClient } from '@pack/client'
const packClient = new PackClient({
  token: 'YOUR-PACK-SECRET-TOKEN'
});

const query = `
  mutation ContentAddSectionsBulk($content: [ContentInput!]!, $input: [ContentAddSectionsInput!]!) {
    contentAddSectionsBulk(content: $content, input: $input) {
      id
    }
  }
`;

const variables = {
  content: [
    { id: 'YOUR-PAGE-ID', type: 'page' },
    { id: 'YOUR-ARTICLE-ID', type: 'article' }
  ],
  input: [
    { sectionIds: ['YOUR-SECTION-ID'], strategy: 'link' },
    { sectionIds: ['YOUR-SECTION-ID'], strategy: 'clone' }
  ]
};
const response = await packClient.fetch(query, { variables: variables });
console.log(response.data);

Response

{
    "data": {
        "contentAddSectionsBulk": {
            "id": "YOUR-JOB-ID"
        }
    }
}

Was this page helpful?