Back to Content Management API

articleCreate

Creates an article.

Arguments

  • Name
    input
    Type
    ArticleCreateInput!
    Description

    An object with the following fields:

    • title: String!
    • handle: String!
    • description: String
    • seo: SEOInput
    • sectionIds: [ID!]
    • firstPublishedAt: Date
    • firstPublishedAtTimezone: String

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 ArticleCreate($input: ArticleCreateInput!) {
    articleCreate(input: $input) {
      id
      title
      handle
      description
      author
      category
      tags
      excerpt
      bodyHtml
      status
      sections {
        edges {
          node {
            id
          }
        }
      }
      seo {
        title
        description
        image
      }
      publishedAt
      firstPublishedAt
      firstPublishedAtTimezone
      blog {
        id
      }
      user {
        id
      }
      storeId
      createdAt
      updatedAt
    }
  }
`;

const variables = {
  "input": {
      "title": "My Article",
      "handle": "my-article",
      "description": "This is my article.",
      "seo": {
        "title": "My Article",
        "description": "This is my article.",
        "image": "https://example.com/image.jpg"
      },
      "sectionIds": ["sectionId1", "sectionId2"],
      "firstPublishedAt": "2022-01-01T00:00:00Z",
      "firstPublishedAtTimezone": "America/New_York"
  }
};
const response = await packClient.fetch(query, { variables: variables });
console.log(response.data);

Response

{
    "data": {
        "articleCreate": {
            "id": "articleId123",
            "title": "My Article",
            "handle": "my-article",
            "description": "This is my article.",
            "author": "Author Name",
            "category": "Category",
            "tags": ["tag1", "tag2"],
            "excerpt": "This is an excerpt.",
            "bodyHtml": "<p>This is the body.</p>",
            "status": "draft",
            "sections": {
                "edges": [
                    {
                        "node": {
                            "id": "sectionId1"
                        }
                    },
                    {
                        "node": {
                            "id": "sectionId2"
                        }
                    }
                ]
            },
            "seo": {
                "title": "My Article",
                "description": "This is my article.",
                "image": "https://example.com/image.jpg"
            },
            "publishedAt": "2022-01-01T00:00:00Z",
            "firstPublishedAt": "2022-01-01T00:00:00Z",
            "firstPublishedAtTimezone": "America/New_York",
            "blog": {
                "id": "blogId123"
            },
            "user": {
                "id": "userId123"
            },
            "storeId": "storeId123",
            "createdAt": "2024-08-15T12:00:00Z",
            "updatedAt": "2024-08-15T12:00:00Z"
        }
    }
}

Was this page helpful?