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
‎12-31-2024 12:08 PM
Request will not have a status code since its a request initially.
Only response would have it since the necessary action has been taken.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 02:38 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-03-2025 05:28 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-31-2024 08:37 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader