UNPKG

@openfin/servicenow

Version:

Connect OpenFin Container with ServiceNow

38 lines (37 loc) 2.83 kB
import { ApiRequestHeaders, HttpMethod } from '@openfin/oauth'; import { ServiceNowEntities, ServiceNowRestApiResponse } from '../rest-api/rest-api.types'; /** * A connection to a ServiceNow instance. * * @group Types */ export type ServiceNowConnection = { /** ID of the registered OAuth application that was used for authorization. */ clientId: string; /** The user that the application has been authorized to act on behalf of. */ currentUser: ServiceNowEntities.Core.User; /** Terminates the connection and cleans up utilized resources. */ disconnect: () => Promise<void>; /** * Executes a request to the specified endpoint of the ServiceNow REST API. * * For `POST`/`PATCH` requests, `Content-Type` header is set to "application/json" by default and so `data` parameter can simply be set to an object. * * Note: depending on which endpoint is being requested, you may need to include additional {@link https://docs.servicenow.com/bundle/utah-platform-security/page/administer/security/concept/rest-api-auth-scope.html | auth scopes} when {@link connect | connecting}. * * @typeParam T - A type that describes the requested data. This API includes a number of {@link ServiceNowEntities | entity types} for use with this function. * @param apiEndpoint - The relative REST API endpoint being requested (e.g. `/api/now/v2/table/sn_customerservice_case`). * @param httpMethod - The HTTP Method to use when making the request (defaults to `GET`). * @param data - Optionally include data in the request body (for `POST`/`PATCH` requests). * @param suppressResponseBody - By default, REST API responses typically include relevant body content. Set this parameter to true to suppress the response body if it is not required. * @param headers - Optionally set additional request headers. Important: do not attempt to set the `Authorization` header manually as the API will include it automatically (as long as `includeAuthorization` is not set to `false`). * * @returns A {@link ServiceNowRestApiResponse | response object} containing the HTTP response status code and requested data (if relevant). * * @throws {@link ApiRequestError} if an error occurred when sending the request, or if the REST API responded with an error HTTP response code. * @throws {@link AuthTokenExpiredError} if the current access token has expired and cannot be renewed. In this instance, you must {@link connect | re-connect} before continuing to use this API. */ executeApiRequest<T = unknown>(apiEndpoint: string, httpMethod?: HttpMethod, data?: any, suppressResponseBody?: boolean, headers?: ApiRequestHeaders): Promise<ServiceNowRestApiResponse<T>>; /** The URL of the ServiceNow instance. */ instanceUrl: string; };