How can I approve or reject an incident via REST API?

sonia7
Tera Contributor

Hi Team,

I am a new user to Service Now, I have created a workflow to automatically set some fields from Incident Table upon approval. Now my concern is, is there a way to approve the incident record via REST API.

1 ACCEPTED SOLUTION

BR is already running on insert/update but if you still want to update then you can update by scripted REST API

View solution in original post

7 REPLIES 7

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi,

it's quite complex to do cause you have to impersonate user through REST API, have a look to the below thread, martin chabarria posted an interesting solution, you should give a try:

https://community.servicenow.com/community?id=community_question&sys_id=534087a1db98dbc01dcaf3231f96...

If I have answered your question, please mark my response as correct and/or helpful.

Thank you very much

Cheers
Alberto

Hi Alberto,

I have a workflow created which I have attached, in this workflow there is a Approve user stage in which a System Administrator needs to approve or reject the Incident request so that the workflow will move forward (I want to do this step via REST API).

( I want to integrate serviceNow with my application in which a person should get all the approval requests and he should be able to either reject or approve the request from my app itself. Now I am able to get a list of all the requests by making a GET call to this endpoint.
https://dev75712.service-now.com/api/now/table/sysapproval_approver?sysparm_query=approver=6816f79cc...^state=requested )

From here, I want to either approve or reject via REST API only. I do not know what endpoint to use and the payload. I am using Service Now trail account, I do not if I am allowed to do this or not.

If I am logged in as a System Administrator in Service Now UI, then I am able to approve/reject the incident record request. I do not know how to do the same (approve/reject) using REST APIs.

Please do help me with this.

Himanshu Dubey
Giga Guru

Hi Sonia,

 

I did this in a past for similar kind of requirement hope this might help

Write after/async business rule: 

var record = current.u_myApproval_data;


var user = current.u_user;


var action = current.u_action;

 

var app = new GlideRecord('sysapproval_approver');


app.get(record);


app .query();


while (app.next()){


if(user == app.approver){

var impersonateUser = gs.getSession().impersonate(user);

 

if(action == 0){ //mark as approved


app.state = 'approved';


app.update();

}

else if (action == 1){ //mark as rejected

 

app.state = 'rejected';

 

app.update();

 

}

}

}

 

Please mark correct and Helpful if it helps

Thanks & Regards

Himanshu Dubey

sonia7
Tera Contributor

Hi Himanshu,

Can I update this business rule using UI or Via any API.. if so please help me with it. I am not running any script, I just need to invoke APIs using POSTMAN.