logo

NJP

How to Use GraphQL in ServiceNow & Service Portal

Import · Nov 03, 2020 · article

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

incident(queryConditions: "active=true") {fragment user on GlideRecord_ReferenceFieldType_sys_user {

Further Reading

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

View original source

https://serviceportal.io/graphql-in-servicenow/