How to invoke GraphQL API in script to query tables
This content was last updated in 2024. It may still be useful, but could contain outdated information. Please confirm its accuracy before relying on it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2024 10:43 AM
Hi All,
I’m trying to implement GraphQL into project to basically replace GlideRecord queries with GraphQL gueries to retrieve table data.
I have GraphQL API, resolver and mapping and I’m able to test it via GraphQL Explorer but how to make use of it in script include? How can I actually invoke it?
Any help would be appreciated.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2024 08:05 PM
GraphQL is normally being called from client side. However, if you want to call it from a script include, you "potentially" could setup a Rest Message and post your GQL to your instance "/api/now/graphql" endpoint. Please note that I have not tested this but it's an option.
Hope that help.
try {
var r = new sn_ws.RESTMessageV2('YOUR_REST_MESSAGE', 'REST_MESSAGE_METHOD');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}