Hi, I need help with passing Authorization Token to next workflow.
I'm using Orchestrator 8.11.2.21452458. Added a REST host and generated 2 workflows from REST operations:
1. Get authToken
2. Add item
I created a new workflow to link #1 and #2 together.
#1 is able to output authToken (string) and after that in #2, I got error Status Code: 401 (Unauthorized: The request requires user authentication). I was able to run #2 in Postman successfully.
This is the default script generated, I only added the Authorization portion. I suspect something is missing/wrong in this script or I've do it all wrong?
//prepare request
//Do not edit
var inParamtersValues = [];
var request = restOperation.createRequest(inParamtersValues, content);
//set the request content type
request.contentType = "application\/json";
System.log("Request: " + request);
System.log("Request URL: " + request.fullUrl);
//Customize the request here
System.log("authToken: " + authToken);
request.setHeader("Authorization", authToken);
//execute request
Below is the log of the workflow.
Guys, I've fixed it. There are 2 issues:
1. When adding a REST Host, the Host's authentication type I used OAuth 2.0, should be NONE instead since I have a dedicated workflow for authentication.
2. The token generated comes with Quotation mark. (Example Token: "DRjODVlNWQtYjVlNC00N"), should be string but without the Quotation mark. (Example Token: DRjODVlNWQtYjVlNC00N). I discovered the abnormality when using System.log to display the token.
Thanks guys for your responses!
Hi
The simple way to accomplish this would be as follows
1. Modify workflow#1 to store the Authtoken into an Output string
2. Modify workflow#2 to take an Authtoken as an input string
3. Modify your 'wrapper' workflow to have an Variable/Attribute to store the Authtoken and then update the TaskItem for workflow#1 to write the output there. Then modify the TaskItem for workflow#2 to take the stored token as an Input
-HTH
@eoinbyrne Yes, that's exactly what I did. Workflow#2 is able to receive authToken from Workflow#1.
But for some reason Workflow#2 can't use it for authentication.
Maybe the right question should be, how to "apply" Authorization Token in the workflow for REST API?
Usually, Authorization header has a "word" before the Token, for instance:
request.setHeader("Authorization", "Bearer " + authToken);
Are you sure that the API is expecting only the token?
@bdamian Tried the Bearer too, still same result (status code 401).
I just checked my postman settings and noticed there are 8 hidden settings in the header (Refer below screenshot).
Are all those required request.setHeader for each of them? If yes, how do I set for keys like Postman-Token, Content-Length, Host where the value is <calculated when request is sent>? Please advice, thank you.
Guys, I've fixed it. There are 2 issues:
1. When adding a REST Host, the Host's authentication type I used OAuth 2.0, should be NONE instead since I have a dedicated workflow for authentication.
2. The token generated comes with Quotation mark. (Example Token: "DRjODVlNWQtYjVlNC00N"), should be string but without the Quotation mark. (Example Token: DRjODVlNWQtYjVlNC00N). I discovered the abnormality when using System.log to display the token.
Thanks guys for your responses!