Back to Content Management API

articleUpdate

Updates an article.

Arguments

  • Name
    id
    Type
    ID!
    Description

    The ID of the article you want to update.

  • Name
    input
    Type
    ArticleUpdateInput!
    Description

    An object.

    • title: String
    • handle: String
    • firstPublishedAt: DateTime
    • firstPublishedAtTimezone: String
    • description: String
    • seo: SEOInput
    • template: String The title of the template to attach.
    • sectionIds: [ID!]
    • blogId: String The ID of the blog the article belongs to.
    • author: String
    • category: String
    • tags: [String!]
    • excerpt: String
    • bodyHtml: String
    • templateId: ID The ID of the template to attach. Takes precedence over template.
    • sectionOverrides: JSON Section overrides for this content, as JSON.
    • draftId: ID Legacy, from the drafts system that Content Releases replaced. To read or write a release's changes, send the X-Pack-Release-Id header instead. See Content Releases.

Returns

  • Name
    Article.*
    Type
    Article
    Description

    Any requested field from the Article object.

Request

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

const query = `
  mutation ArticleUpdate($id: ID!, $input: ArticleUpdateInput!) {
    articleUpdate(id: $id, input: $input) {
      id
      title
      handle
      description
      author
      category
      tags
      sections {
        nodes {
          id
          title
        }
      }
    }
  }
`;  

const variables = {
  "id": "1",
  "input": {
    "title": "Updated Article Title",
    "handle": "updated-article-title",
    "description": "Updated article description.",
    "seo": {
      "title": "Updated SEO Title",
      "description": "Updated SEO Description",
      "keywords": ["Updated", "SEO", "Keywords"]
    },
    "template": "updated-template",
    "sectionIds": ["section-id-1", "section-id-2"]
  }
};

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

console.log(response.data);

Response

{
    "data": {
        "articleUpdate": {
            "id": "1",
            "title": "Updated Article Title",
            "handle": "updated-article-title",
            "description": "Updated article description.",
            "author": "John Doe",
            "category": "Uncategorized",
            "tags": [
                "tag1",
                "tag2"
            ],
            "sections": {
                "nodes": [
                    {
                        "id": "section-id-1",
                        "title": "Section 1"
                    },
                    {
                        "id": "section-id-2",
                        "title": "Section 2"
                    }
                ]
            }
        }
    }
}

Was this page helpful?