Retrive Oauth Token from script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 05:40 AM
Hi community,
I am trying to get the access token from script as follows:
var r = new sn_ws.RESTMessageV2();
r.setEndpoint('https://<INSTANCE NAME>.service-now.com/oauth_token.do');
r.setHttpMethod('POST');
r.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
r.setRequestBody('grant_type=password&username=ABC&password=123&client_id=xxxxx&client_secret=yyyyyy');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
//***Return Response and httpStatus
var res = {};
res.httpStatus = httpStatus.toString();
res.responseBody = JSON.parse(responseBody);
This is the result:
*** Script: { "httpStatus": "401", "responseBody": { "error_description": "access_denied", "error": "server_error" } }
From Postman it works just fine.
Can someone help me?
Thanks
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 06:38 AM
error 401 means incorrect username/password
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2023 06:57 AM
From Postman with the same values it works fine. The format of the body is correct?
Thanks