Query examples for management operations

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

RequestResponse
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

RequestResponse
{
  "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

RequestResponse
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

RequestResponse
{
  "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

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

Result

RequestResponse
{
  "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

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

Result

RequestResponse
{
  "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

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

Result

RequestResponse
{
  "data": {
    "publishingStatus": {
      "state": "RUNNING",
      "isDone": false,
      "isFailed": false,
      "languages": [
        {
          "name": "en"
        }
      ],
      "processed": 1,
      "targetDatabase": {
        "name":
"experienceedge"
      }
    }
  }
}

Query locked items

You can check to see which items are locked and who is locking them. Items are locked when a content author edits them in the Content Editor.

Query

RequestResponse
lock{
      isLocked
      lockedBy
      user(username: <username>) {
        canLock
        hasLock
        canUnlock
      }
    }

Result

RequestResponse
{
  "data": {
    "item": {
      "lock": {
        "isLocked": true,
        "lockedBy": "sitecore\\[email protected]",
        "user": {
          "canLock": false,
          "hasLock": true,
          "canUnlock": true
        }
      }
    }
  },
  "extensions": {}
}

Check publishing permissions for an item

You can use the canPublish field with the item query to get publishing permissions for an item. You can check all the publishing permissions for the item, or query an individual user to check their permissions for the item.

Query

Query all the publishing permissions of an item:

RequestResponse
query{
  item(where: {path: "<item path>"}) {
      canPublish
  }
}

Query

Query the publishing permission of a specific user for an item:

RequestResponse
query{
  item(where: {path: "<item path>"}) {
    access(username:"<username>"){
      canPublish
    }
  }
}

Result

RequestResponse
{
  "data": {
    "item": {
      "access": {
        "canPublish": false
      }
    }
  },
  "extensions": {}
}

Do you have some feedback for us?

If you have suggestions for improving this article,