How to use REST API in Business Rule?

IG3
Tera Contributor

Hello,

i have created a Scripted REST API, it’s a POST Method to create Changes and when I open it with the REST API Explorer I can submit values und send request.

Now my question: Is it possible to give values with my Business Rule to the Rest API?

13 REPLIES 13

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

your question is not clear.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I try to explain on detail: So my Business Rule had a Condition „when task is closed“ and a Script: create Change Request with the type „whitelist change“. (Whitelist change is when you don’t need approve or something, it goes over the step „approve“ directly to „implement“ step. The Business Rule did also insert values to fields and choose template etc… but not all fields was correctly fill in. So someone of my company created a scripted REST API (POST). With the rest api explorer I give values like „date start“, „date end“, „template“, „CI“… and he create me a Change Request. Well but I want take the process by Business Rule and not on my self to insert the values in the explorer. The Business Rule should take the values of a record from a table and give it to the api where it insert the values. I saw many solutions here and will try it. If you have a another solution for me, I would be happy.

SumanthDosapati
Mega Sage
Mega Sage

Hi,

You can check this code

var req = new sn_ws.RESTMessageV2();
	req.setEndpoint("give your end point");
	req.setHttpMethod("POST"); //give your required method
	req.setBasicAuth("rest_user","123"); //give username and password if basic auth
	req.setRequestHeader("Content-Type","application/json");
	req.setRequestBody(JSON.stringify(body));
	
	var response = req.execute();
        gs.log(response);

 

Mark as correct and helpful if it solved your query.

Regards,

Sumanth

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi IG,

To answer the question, yes, it is possible to call REST API from business rule.

There shouldn't be any problem. If it's not working, would need to see the code.