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 sectionUpsertQuery = `
mutation SectionUpsert($input: SectionUpsertInput!) {
  sectionUpsert(input: $input) {
    id
    title
    status
    data
    dataSource
    hasReferences
    publishedAt
    createdAt
    updatedAt
    parentContentType
    runningTests {
      id
      title
      testVariants {
        id
        title
      }
    }
  }
}
`;


const variables = {
  "input": {
    "title": "My Article Image",
    "data": {
      "sectionName": "My Article Image",
      "sectionType": "local",
      "sectionVisibility": "visible",
      "resourceType": "article",
      "_template": "image",
      "image": {
        "alt": "My Article Image",
        "imageDesktop": {
          "src": "https://example.com/image.jpg"
        },
      },
      "section": {
        "maxWidth": "max-w-[90rem]",
        "enablePadding": true
      }
    }
  }
};

const response = await packClient.fetch(query, { variables: variables });
console.log(response.data);

Response

{
    "data": {
        "sectionUpsert": {
            "id": "60f3b1b3b3b3b3b3b3b3b3b3",
            "title": "My Article Image",
            "status": "draft",
            "data": {
                "sectionName": "My Article Image",
                "sectionType": "local",
                "sectionVisibility": "visible",
                "resourceType": "article",
                "_template": "image",
                "image": {
                    "alt": "My Article Image",
                    "imageDesktop": {
                        "src": "https://example.com/image.jpg"
                    }
                },
                "section": {
                    "maxWidth": "max-w-[90rem]",
                    "enablePadding": true
                }
            },
        }
    }
}

Was this page helpful?