- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 01:58 AM
I have to pass these 3 key/values:
i tried to do this:
var body = {
client_id: 'SNIT0da4-b027-4a81-a4e7-c6352a315759',
client_secret: '3K72Yv6F7_zLS7zZZc4LW3wHsG4s9Vc1XO7rSfkM',
grant_type: 'client_credentials'
};
var toSend = JSON.stringify(body)
//restMessage......
setRequestBody(toSend)
but it doesn't work
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 03:41 AM
@Fabrizio Joaqui Please remove the query params you added and try below in script itself. It should work 100%.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 02:13 AM
@Fabrizio Joaqui Can you please post the screen shot of full code?
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 02:17 AM
var token;
var body = {
client_id: 'SNIT0da4-b027-4a81-a4e7-c6352a315759',
client_secret: '3K72Yv6F7_zLS7zZZc4LW3wHsG4s9Vc1XO7rSfkM',
grant_type: 'client_credentials'
};
var toSend = JSON.stringify(body);
gs.info(toSend);
var r = new sn_ws.RESTMessageV2('Frida.api.dev','POSTtoken');
r.setRequestBody(toSend);
var response = r.execute();
var responseBody = JSON.parse(response.getBody());
var httpStatus = response.getStatusCode();
gs.info(JSON.stringify(responseBody));
if( httpStatus === 200){
gs.info('Token: ' + responseBody);
gs.info( 'http status: '+ httpStatus);
}else{
gs.info('Error Token: ' + responseBody);
gs.error(' http status: '+httpStatus);
}
token = responseBody.access_token;
gs.info(token);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 02:21 AM
@Fabrizio Joaqui The code looks good.
But can you please try the below once.
r.setRequestBody(body);
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 02:28 AM
thanks but it doesn't works, this is my rest message:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 02:37 AM
@Fabrizio Joaqui Oh the content-type is url encoded thats why its not working.
You need to pass the parameters in the end point like query parameters.
Please check this below link:
https://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023