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.

5 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)

  3. Awesome video & content Nathan.!
    I’m trying to do this, except with an external graphQL endpoint instead of a ServiceNow one. Is there anything else I have to do besides update the url in the $htttp.post? I did this and it doesn’t work.

  4. Hi Nathan,

    Thank you very much for this ultra useful resource!

    Might you please provide an example for a mutation (INSERT, UPDATE and DELETE)?

    This would helps us a lot to adopt GraphQL.

Leave a Reply to Mohammad Abdul Waheed Cancel reply

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