Skip to main content

getOAuthToken

A Workflow Engine function that adds an OAuth2.0 authorization header to an outbound exportViaRest, sendViaRest or getViaRest request. getOAuthToken must precede these other actions and will make any necessary calls to the supplied OAuth endpoint in order to retrieve the authorization token.

This function is available as a feature of the Add-ons v2.6 download and later.

This function is available for alert and Situation workflows.

Back to Workflow Engine Functions Reference.

Arguments

Workflow Engine function getOAuthToken takes the following arguments:

Name

Required

Type

Description

oauthEndpointName

yes

string

The name of the OAuth endpoint to use.

Example

The following example demonstrates typical use of Workflow Engine function getOAuthToken.

We have a REST endpoint that we wish to send alert data to using the sendViaRest action that requires OAuth using a password grant type and client credentials. We create a REST Endpoint and a Payload map in the usual way but specify no authentication mechanism in the Rest Endpoint. Instead we create a OAuth Endpoint targeting the authorization endpoint and precede the sendViaRest action with a getOAuthToken action.

We have the following integrations defined:

Integration

Config

REST Endpoints

Endpoint Name: ticketing

URL: https://example.com/ticketing

Method: POST

Payloads

Map Name: createTicket

OAuth Endpoints

Endpoint Name: authorization

URL: https://example.com/token

Parameters:

  • Grant Type: password

  • Username: <user>

  • Password: <password>

  • Client Id: <client_id>

  • Client Secret: <client_secret>

Our workflow would then consist of the following three actions:

Action Name

Get payload

Function

getPayload

Argument

{"mapName":"createTicket"}

Forwarding Behavior

Stop This Workflow

Action Name

Get authorization token

Function

getOAuthToken

Argument

{"oauthEndpointName":"authorization"}

Forwarding Behavior

Stop This Workflow

Action Name

Create ticket

Function

sendViaRest

Argument

{"endpointName":"ticketing"}

Forwarding Behavior

Always Forward

The getOAuthToken call will use the parameters in the authorization OAuth Endpoint to fetch an authorization token. If successful, will return true and create an authorization header that will be added to the outbound request generate by the sendViaRest call. If unsuccessful, it will return false to allow the workflow to be aborted.