How to get Request Status Code in a Scripted REST API

Sai kumar123
Tera Expert

There is an Inbound Integration I am working on, In my case I had written a Scripted Rest API with POST Method, when 

the client hits my custom API , i am able to modify data in certain table in my instance.

Now i need to get the satus code of the Request I recieved at my end , so that i can use it my API code to make certain conditions work

 

How to access Request Status Code, I tried with request.getStatusCode() , but its giving undefined

7 REPLIES 7

Ankush13
Kilo Guru

Request will not have a status code since its a request initially.

Only response would have it since the necessary action has been taken.

rambo1
Tera Guru

Hi @Sai kumar123 @request will have only the body that’s sent by external tool , it will not have status code . Could you please explain your requirement in detail

yeah got it my requirement is like, we are expecting a client to hit instance, as per the story i had created a scripted REST API with POST as method in it, so that with the response i get i can update data in a certain table

this is the overall use case, in it there is a particular condition mentioned like if the incomming request is success then respose should be in a certain format, and if the incomming request is a failure , then response should be something different, here success and failure in the sense they are represnting in the form of codes like 200 is success and 500 is failure, thats why i asked wether there is a way to access the status of request

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Sai kumar123 

status code means http code?

it's meant for external systems to know. ServiceNow is the provider so the consumer i.e. external system when hits the endpoint will know the status code

If your request is success it can be determined by if you were successfully able to update data in your instance

If yes then perform some extra conditions

That's the only way you can handle it

If my response helped please mark it correct and close the thread so that it benefits future readers.

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