1. Sitecore Authoring and Management GraphQL API

Query examples for management operations

Version:

The Authoring and Management GraphQL API allows you to extend Experience Manager with custom dialogs and user interfaces. You can use the API to perform tasks previously possible only through the Sitecore user interface.

You can perform authoring operations using queries and mutations for the following GraphQL types:

  • Archiving

  • Database

  • Indexing

  • Job

  • Language

  • Publishing

  • Security

  • Workflow

  • Rules

For a complete list of available types and operations, refer to the built-in documentation in the GraphQL IDE.

Trigger an index rebuild

You can use the rebuildIndexes mutation to run an index rebuilding operation.

Query

mutation {
  # Rebuild all indexes if indexName input is not specified.
  rebuildIndexes(
    input: { indexNames: ["sitecore_master_index", "sitecore_core_index"] } 
  ) {
    jobs {
      name
      handle
      status {
        total
        messages
        processed
        jobState
      }
      done
    }
  }
}

Result

{
  "data": {
    "rebuildIndexes": {
      "jobs": [
        {
          "name": "Index_Update_IndexName=sitecore_master_index",
          "handle": "3224a43a-0bb1-4be5-ac2f-91e781415be0;2AD160A8BF9F-Default Web Site",
          "status": {
            "total": -1,
            "messages": [
              "Job started: Index_Update_IndexName=sitecore_master_index"
            ],
            "processed": 0,
            "jobState": "RUNNING"
          },
          "done": false
        },
        {
          "name": "Index_Update_IndexName=sitecore_core_index",
          "handle": "e06da2e4-c129-4273-86be-945c5fbb5078;2AD160A8BF9F-Default Web Site",
          "status": {
            "total": -1,
            "messages": [],
            "processed": 0,
            "jobState": "RUNNING"
          },
          "done": false
        }
      ]
    }
  }
}

Check a job status by job name

You can query the job details by the job name or job handle returned from the result using Job API.

Query

query {
  # If both jobName and handle parameters are specified, the jobName parameter is ignored
  job(input: { jobName: "Index_Update_IndexName=sitecore_master_index" }) {
    name
    handle
    status {
      messages
      processed
      jobState
    }
    done
  }
}

Result

{
  "data": {
    "job": {
      "name": "Index_Update_IndexName=sitecore_master_index",
      "handle": "61519bfb-ff49-44bd-8957-9ef4ba4404a2;2AD160A8BF9F-Default Web Site",
      "status": {
        "messages": [
          "Job started: Index_Update_IndexName=sitecore_master_index"
        ],
        "processed": 4630,
        "jobState": "RUNNING"
      },
      "done": false
    }
  }
}

Check a job status using wildcards

You can use a wildcard to get details about available jobs.

You can query by wildcard alone or use the wildcard before or after a job name fragment. Specifically:

  • * - returns the status for all jobs.

  • *myjob - returns the status for jobs where the name ends with myjob.

  • myjob* - returns the status for jobs where the name starts with myjob.

  • *myjob* - returns the status for jobs where the name contains myjob.

Query

query{
  jobs(input: { jobName: "*index" }
){
    nodes {
      name
      handle
      status {
        messages
        processed
        jobState
      }
      done
    }
  }
}

Result

{
  "data": {
    "jobs": {
      "nodes": [
        {
          "name":
"Index_Update_IndexName=sitecore_master_index",
          "handle":
"970372d7-df5a-418f-a603-d6c0b40ed52c;2AD160A8BF9F-Default Web Site",
          "status": {
            "messages": [
              "Job started: Index_Update_IndexName=sitecore_master_index"
            ],
            "processed": 1578,
            "jobState": "RUNNING"
          },
          "done": false
        },
        {
          "name": "Index_Update_IndexName=sitecore_core_index",
          "handle": "b009bb91-aeae-4d86-86b5-fac785f1861d;2AD160A8BF9F-Default Web Site",
          "status": {
            "messages": [
              "Job started: Index_Update_IndexName=sitecore_core_index"        
            ],
            "processed": 307,
            "jobState": "RUNNING"
          },
          "done": false
        }
      ]
    }
  }
}

Publish an item to the edge

You can use the publishItem mutation to publish an item to the edge. If you want to check the operation status, return the operationId property of the publish operation.

Query

mutation{
  publishItem(
    input: {
      rootItemPath: "/sitecore/content/Home"
      languages: "en"
      targetDatabases: "experienceedge"
      publishItemMode: SMART
      publishRelatedItems: false
      publishSubItems: true
    }
  ) {
    operationId
  }
}

Result

{
  "data": {
    "publishItem": {
      "operationId": "cbbcaf09-ec02-42c8-bad6-df60ef05cc42;F497611F492C-Default Web Site"
    }
  }
}

Check the publishing status

You can query the status of a publishing operation using the operation identifier returned by the publishItem mutation.

Query

query {
  publishingStatus(
    publishingOperationId: "cbbcaf09-ec02-42c8-bad6-df60ef05cc42;F497611F492C-Default Web Site"
 ) {
    state
    isDone
    isFailed
    languages {
      name
    }
    processed
    targetDatabase {
      name
    }
  }
}

Result

{
  "data": {
    "publishingStatus": {
      "state": "RUNNING",
      "isDone": false,
      "isFailed": false,
      "languages": [
        {
          "name": "en"
        }
      ],
      "processed": 1,
      "targetDatabase": {
        "name":
"experienceedge"
      }
    }
  }
}
If you have suggestions for improving this article, let us know!