SERVICENOW Library

The SERVICENOW Library is an importable library containing functions to connect, authenticate, and interact with the ServiceNow API. This library is used in the .

On import, typically only the SERVICENOWclient module needs to be required in order to create the client and access the API methods.

require "SERVICENOW.SERVICENOWclient"

The SERVICENOW Library:

Use the Translator’s built in help to review how to use each function:

Sets up the ServiceNow Adapter framework, adding the method modules to a metatable and storing the configurations from the custom fields in a table to call the API.

SERVICENOWcustom takes in any API requests and parameters to make the API call and return the response.

  • First, the function checks if the token key exists or is still valid (based on the key_expiry). If not, it calls SERVICENOWauth to perform the OAuth2.0 authentication workflow to obtain the token to be used in subsequent requests.

  • Uses the passed configurations API request parameters - the method (ex. post), ServiceNow API endpoint (ex. 'now/table/') and parameters for the call (ex. the incident ticket) - to build and carry out the appropriate HTTP request.

The SERVICENOWauth function builds and makes the HTTP POST token request to obtain the access token required for any resource requests against the FHIR Server.

A separate SERVICENOWcreateJWT function creates the JSON Header and Payload components of the JWT and calls SERVICENOWjwt to sign and return the JWT required for the token request.

If the token requests is successful (HTTP 200 response), the token and token expiry returned are stored in the adapter object (key and key_expiry) and saved in an encrypted file via SERVICENOWencrypt.

SERVICENOWencrypt provides localized https://interfaceware.atlassian.net/wiki/x/EQCeqg functionality via save and load functions that encrypt and decrypt the provided API token and expiry time in an external file. This allows the token to be reused for subsequent API calls.

SERVICENOWjwt provides localized functionality. It takes the provided JWT header, JWT payload, signing algorithm, and private key to generate and sign the JWT token.

Â