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

@Sai kumar123 

Hope you are doing good.

Did my reply answer your question?

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

Runjay Patel
Giga Sage

Hi @Sai kumar123 ,

 

You cannot directly access the HTTP status code of the incoming request because the framework does not expose this information in the request object. The request object is primarily used to access details like headers, query parameters, body content, etc.

 

Status code concept applies to responses sent back to the client, not the request itself. The server (ServiceNow) is responsible for determining and setting the response status code based on the logic implemented in your API.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

Hi @Sai kumar123 ,


Thank you for marking my solution as helpful! If my answer addressed your query, feel free to accept it to help others in the community benefit as well.