How to get Request Status Code in a Scripted REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 11:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2025 09:30 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 11:41 PM
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
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2025 05:30 AM
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.