Workflows: Use HTTP Request to authenticate to OAuth endpoint

I am trying to create service request from Identity now to Servicenow. When I try to use Manage Service ticket in workflow I am getting error with no detailed message . Going through developer form articles I tried using HTTP action which is working when I use basic but when I am trying to use OAuth/Custom Authorization by generating token from Http Request and trying to capture it another http request which is failing error with no detailed message.
Could you please let me know how you did work on this?
Try to use ā€˜Define Variableā€™ operator but I didnt get any information how to use that in action and how variable is defained as its failing with no error
Usecaseworkflow.json (5.1 KB)

Hey!

I also have not been able to make the HTTP Action work with OAuth. I am getting ā€œ401 Unauthorizedā€ error.

If you download the report from the execution of the workflow, what error-message do you get in the csv-file? (Usually you can see more data here).

@colin_mckibben Do you have an idea as to why Oauth HTTP Requests in workflows arenā€™t working? It seems like a Bearer token is never passed automatically. To my understanding it should pass the token by default and defining variable to pass it in a 2nd http request should not be required, right?

Hi Yamini,

Please donā€™t use ā€œDefine Variableā€ at this time. It is still in very early access and not suitable for use in a Workflow yet.

As for your authorization question, I am not familiar with the ServiceNow API. Can you share a cURL request that you would use to obtain a ServiceNow access token? This will better help me understand how an authorization request is formed and how that might translate to the HTTP action.

1 Like

Hi Colin,

ā€˜POST https://xxxx.service-now.com/oauth_token.doā€™ would be used for generating token . Content-Type: application/x-www-form-urlencoded. Also, grant_type ā€˜passowrdā€™, username , client id and client secret has to be mentioned to generate token for ServiceNow.

Hi,
I see an interesting thing, I am initially sending Basic Authentication http request with token url and then OAuth with Request URL to token URL its working fine , But If I change Request URL to ā€˜URL for ticket creationā€™ its then showing error with no detailed message. I am not getting any csv report, not sure how that can be accessed.

If you click on the workflow and then on the ā€œExecutionsā€ tab you can download a report for each executed workflow. Download the report and see if you get a better error message.

2 Likes

Also Yamini, could you send the working workflow json here so I can try it myself? :smiley:

1 Like

It seems my own problem had to do with the response-body not being JSONā€¦
HTTP Requests via workflow seem to only accept JSON response bodies.
Sadfaceā€¦ :frowning:

Is there anyway to parse whatever response body we recieve to JSON?
Tried adding an Accept header like:
Accept: /

Workflows can only accept and parse JSON at this time. This is a known gap and there is a ticket in the backlog to work on it.

2 Likes

Hi Sebastian,

I have two http requests for our requirement. I have to mention basic and OAuth credentials as ServiceNow requires client credentials. Attaching workflow which worked for me.

SNworkflow.json (4 KB)

Please check this workflow on how its working for me with http basic.
If we can make it to use OAuth token for authorization (while triggering servicenow urlā€™s to create ticket/incident) instead of basic after initial authentication. I did try from workflow isnā€™t working that way for ServiceNow . Thank you.