Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Scripted REST resource doesn't parse json when request contains Content-type headers with vendor tree

morgan_r
Kilo Explorer

RFC 6838 - Media Type Specifications and Registration Procedures
According to RFC-6838 media type can include a vendor tree. A content-type of 'application/vnd.{vendor}+json' should be valid however ServiceNow is returning "message": "Invalid content-type. Supported request media types for this service are: [application/json, application/xml, text/xml]" when encountered.

IMHO, serviceNow should apply the json parser to it as the media type is valid according to the spec.

Because I'm working in a scoped app, I can't access the response body's datastream (streams are not allowed) and I can't control the content-type being sent in the request. Without moving to a scoped app, is there a way to access the request body when using a content type with a vendor tree? I'm using a scripted REST resource to catch a webhook from another service (helsinki). Is there better way to approach this problem?

Thanks in advance!

4 REPLIES 4

NickBain
Tera Contributor

If you are using a scripted REST service then you have the option to overwrite the accepted content-types, by default 'application/json,application/xml,text/xml' are accepted.



Check the 'Override default supported request formats' field shown below and enter the content types you need.



screenshot.png


vendor-tree-error.png



no-vendor-tree.png



No effect, I can change the 'supported request formats' to */* and it will accept the request but that won't parse the body as json and the body stream is still unavailable so I'm still unable to process the webhook.



star-slash-star-error.png



no-datastream.png


Can you get the data string and convert that to a JSON object?



var obj = JSON.parse(request.body.dataString);


return obj.some_value;


Sorry for the confusion, I mentioned the json in the text but the examples are trying to use the datastring.


{


  "error": {


      "detail": "",


      "message": "com.glide.rest.domain.ServiceException: Server error: attempt to access operations that are not allowed when request content is not one of ServiceNow default content types"


  },


  "status": "failure"


}