Pass the response token from one HTTP Request action to another

Hi All,

I am using the HTTP Request action in workflow to authenticate to the target application. The flow is as follows:

  1. I need to authenticate using a PAT then use credentials token from the response of that API call (This was already configured in the workflow and was working successfully when I tested the workflow)
  2. The response from step 1 looks something like this:
<?xml version='1.0' encoding='UTF-8'?>
<tsResponse xmlns="xxx">
    <credentials token="xxxxxxxxx" estimatedTimeToExpiration="316:18:21">
        <site id="xxxx contentUrl="XXXX"/>
        <user id="xxxxx"/>
    </credentials>
</tsResponse>

I will then need to use the credentials token to pass it to the header to the next HTTP Request action to be able to authenticate. What would be the proper configuration/syntax to get this? And do I put it into a variable by doing a Define Variable step?

Thank you!

Are you not receving the response from token url in JSON format. The access token can be passed in the next request. The token is accessed using
{$.httpRequest.body.access_token}}. You can add a header entry with name as Authorization and value as “Bearer {$.httpRequest.body.access_token}}”

Hi @nileshnikalje,

Tried {{$.httpRequest.body.access_token}} and {{$.hTTPRequest.body.access_token}} in the request header but still getting an unauthorize error.

Not sure if this would help but here is the response mapping from the HTTP Operation:

Here is the header that I need to put in the workflow:

1 Like

This is the result in the workflow logs

> {"displayName":"HTTP Request","result":{"body":"66e8f6d3\"/></credentials></tsResponse>","headers":{},"responseTime":"0.509282 seconds","statusCode":200},"stepName":"hTTPRequest","task":"sp:http","technicalName":"HTTP Request"}

Are you able to get the token response via Postman? Can you share the screenshot of the Postman console for the request/respone (masking the sensitive fields)?

@jasmedina Are you trying to onboard application using web services connector? Or the issue is with the HTTP request operation in Workflows?
The mention screenshots are from web services connector page.

I am configuring the HTTP request action in Workflows. I just showed my configuration in the web service connector since that once was working

Hi @nileshnikaljem, here’s the response body from Postman

In Workflows I don’t think you need to capture the access token from one to other (I may be wrong). In each HTTP operation we need to define the authentication parameters in order to authenticate irrespective of previous operation.

I am getting an authentication error in the workflow step if i dont include the access token in the header

Can you share your HTTP request config? It should look something like this

Here’s the HTTP request config



This is the request header for the bearer token:
{{$.hTTPRequest.body.access_token}}

This looks fine. As the response is in XML, not sure how to use the variables. In the response body, I can see “token” as a variable. Can you try {{$.HTTPRequest.body[‘//credentials/@token’]}}. If not put send email operator after the HTTP request that is being called to get access token and see if you were able to get the access token using {{$.HTTPRequest.body[‘//credentials/@token’]}}

Hi @JackSparrow! I tried the {{$.HTTPRequest.body[‘//credentials/@token’]}} in the Send Email operator but it is throwing an error. I also tried the following but it is not returning anything

{
“Test1.$”:“$.hTTPRequest.body.access_token”,
“Test2.$”:“$.hTTPRequest.body.tsResponse.credentials.access_token”,
“Test3.$”:“$.hTTPRequest.body.tsResponse.credentials.token”
}

Can you just try to send the body i.e $.HTTPRequest.body and see if the token is getting generated in first place?

@colin_mckibben Hi Colin, any help here?

Hi @JackSparrow! I was able to make it work by adding the header Accept application/json to the first HTTP Request (the one that generates the token) to output the response body to JSON instead of XML. I then used {{$.hTTPRequest.body.credentials.token}} in the next HTTP request to retrieve the token.

Thank you so much for your insight, it pointed me to knowing that the response must be in JSON instead of XML. Appreciate the help! :slight_smile:

1 Like