Scripted REST API - How to send 404 http error code response for url with wrong endpoint in scripted rest api?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 01:23 AM
Hi,
I want to return 404 HTTP status code when user enters url with wrong endpoint for a Scripted REST API.
eg: Correct url: "https://<instance.service-now.com>/api/name_space/correct_endpoint".
Incorrect url: "https://<instance.service-now.com>/api/name_space/wrong_endpoint" should return 404 HTTP status code.
I am getting HTTP status code 400 now.
Any suggestions?
Thanks,
Leo
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 01:50 AM
Hi,
I don't believe you are able to update this standard 400 response. From the docs:
https://docs.servicenow.com/bundle/quebec-application-development/page/app-store/good_practices/scripted-rest/concept/scripted-rest-good-practices.html
Status codes in the 400 range indicate a client error, such as 400 for invalid request syntax.
The scenario you mention with the incorrect endpoint; will return a 400.
Can you not just update your calling app/code to handle a 400 as opposed to the 404 that you want?
Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 02:41 AM
Hi Geoff,
Thanks for the reply, I'm not sure if this can be handled in the script part of the api due to the wrong endpoint.
Let me know if there is any other workaround for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2021 02:48 AM
Hi,
if the endpoint is incorrect then it won't reach ServiceNow itself and the Scripted REST API won't trigger.
the 3rd party application consuming the endpoint will automatically receive 404 error for invalid request URI or URL
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2021 05:11 AM
Hey
I understood the point that an incorrect endpoint will not reach Servicenow.
But the 3rd party application consuming the endpoint is responding with a 400 status code, and I want it to respond with 404 status code.
Is there any way in Servicenow where I can set the HTTP status code for scripted REST API request with invalid url?
Thanks,
Leo