Authentication tab shows 'Send as me' option only in Rest API Explorer. If I want to send request with another user , I do not find any option.

User205031
Tera Contributor

Hi All,

Authentication tab shows 'Send as me' option only in Rest API Explorer. If I want to send request with another user , I do not find any option.

find_real_file.png

Please help!

4 REPLIES 4

Vinayak Belgaon
Mega Guru
Mega Guru

As the description already mentions if you want to test it with other user you can copy the code format from the below "code samples" of the rest api explorer. for servicenow script you can use the below and change the user and password variable as per your requirement.

 

var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://yourinstnace.service-now.com/api/now/table/<yourapi>?sysparm_limit=1');
request.setHttpMethod('GET');

//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'admin';
var password = 'admin';

request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");

var response = request.execute();
gs.log(response.getBody());

 

Kindly mark helpful/correct if this resolved your query.

 

Regards

Vinayak

Hi Vinayak,

I am using REST API to submit a catalog request. I found that 'Service Catalog API' and 'Buy Item (POST)' resource is used to submit the request. So in order to send request using a different user, do I need to use the above script in the scripted rest resource of 'Buy Item'?

Please let me know.

Thanks!

You need to specify the parameter "sysparm_also_request_for" in the body of the api along with quantity.

Check documentation here Service Catalog API | ServiceNow Developers

 

Also there are some restrictions that you may  have to look at.

Request body parameters (XML or JSON)
Name Description
sysparm_also_request_for Comma-separated string of user sys_ids of other users for which to order the specified item. User sys_ids are located in the User [sys_user] table.
  • You cannot specify more than 50 additional users to receive the item.
  • If any person in the list doesn't qualify for the item, the entire request is rejected.
  • If the associated item does not have the requested_for variable set, the request is rejected.
  • If the associated item has the requested_for variable set, but the Enable also Request for variable is not configured, or the calling user doesn’t have the proper roles, the request is rejected.
sysparm_quantity Required. Quantity of the item. Cannot be a negative number.

Data type: Number

variables Name-value pairs of all mandatory cart item variables. Mandatory variables are defined on the associated form.

Data type: String

 

Regards

Vinayak

Hi @Vinayak Belgaon ,

Where should I paste this script? 

thanks 

bharat