How to Use GraphQL in ServiceNow & Service Portal

Overview

GraphQL is an open-source data query and manipulation language for APIs. GraphQL offers many benefits over REST API’s, including:

  • Fetching data across multiple sources from a single API call
  • Returns only the data that is requested
  • Supports validation and type checking
  • Autogenerating API documentation

In this video, I’ll show you how to construct a sample GraphQL query to fetch data in ServiceNow and then how we can use GraphQL inside of a ServicePortal widget.

GraphiQL

To start, I would recommend you download GraphiQL, a GUI for editing and testing GraphQL queries and mutations. You can download it here: https://www.electronjs.org/apps/graphiql

The GraphQL Endpoint is: https://instance-name.service-now.com/api/now/graphql

Documentation

In order to use the documentation and auto-completion, you’ll need to enable the glide.graphql.introspection_enabled system property.

Service Portal Widget

You can download the widget update set here:

It’s compressed as a ZIP file, so remember to uncompress before uploading.

Example GraphQL Query

Further Reading

If you have any questions or comments, please don’t hesitate to comment below.

3 comments

  1. Hi Nathan, great video.
    “glide.graphql.introspection_enabled” is no longer a maint-only property and can now be enabled by admins as well.

  2. Hi Nathan.

    1. I tried to import the widget XML but it’s not importing. (Unzipped and imported but no luck).
    2. I cant able to connect my instance with the GraphQL tool (https://www.electronjs.org/apps/graphiql).
    3. Can you explain in detail how can we use the GraphQL Query on the service portal widget. (I can’t able to connect with GraphQL API)

Leave a Reply

Your email address will not be published. Required fields are marked *