Scripted REST API - How to send 404 http error code response for url with wrong endpoint in scripted rest api?

leo17
Giga Contributor

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

5 REPLIES 5

Geoff_T
Mega Sage

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

leo17
Giga Contributor

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

 

@Ankur Bawiskar @Chuck Tomasi @Brad Tilton @Pradeep Sharma @Mark Roethof @asifnoor Please Help

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

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

Hey @Ankur Bawiskar ,

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