I am getting 401 error for an REST API Message call in workflow (Classic) the REST API is OAuth 2.0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hello Team,
I have an API from IVM where Auth Type is OAuth 2.0 . This completely works fine in DEV & TEST env.
Where as in PROD i get 401 error on calling the API in workflow classic
Checks done :
1.)OAuth profile client secret & PWD is manually typed and manually created in PROD and its exactly same in DEV & TEST
2.)Under Rest Message Get OAuth Token is Successfull and the HTTP header test is giving the required response and code is 200
3.)Calling that API from background scripts is working as expected and getting required output
4.)RITM Workflow context started is by the requestor ID both in DEV and TEST as well
I am totally confused if its working in REST Message test & on Background script in PROD why not in workflow editor(Classic) i feel its vierd
var r = new sn_ws.RESTMessageV2('IVM_Vending_Machine_API', 'Fetch_Inventory_ByMachine');
r.setStringParameterNoEscape('machineID', '2816');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();The script used is above
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
In Prod, Do you have MID server set for your integration. Ensure that is up.
Can you share the outbound http request log.
Also try with it. Refer: KB0820703 Outbound REST call with Oauth authentication fails with http 401 - Invalid Access Token
Cause
To identify the root cause:
- set the "HTTL log level" to "All" from the "Related links" on the Rest message method you are calling from the script.
- Reproduce the issue
- Navigate to Outbound HTTP logs and find the failed request
- In the Request tab check the Request headers you will see Authorization=Bearerxxxxxxxxxxxxxxxxxxxx without a space after the Bearer causing the failure
Resolution
Update the script where this call is built to include a space after "Bearer" before adding the token.
r.setRequestHeader('Authorization', 'Bearer ' + accessToken);
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti