Scripted REST: Content-Type: application/octet-stream

Jamsta1912
Tera Guru

Hi all,

I am working on an integration with a third party. They wish to send messages with Content-Type: application/octet-stream to a scripted REST API our side. 

Initially, when I sent messages with that content type to scripted REST API, I got this error:

"message": "Invalid content-type. Supported request media types for this service are: [application/json, application/xml, text/xml]"

I have now updated the 'Supported request formats' field on the 'Content Negotiation' tab in to include 'application/octet-stream'. Now I get this error:

"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"

Can anyone offer any advice on how (or if) in general terms I can modify a scripted REST API to be able to process (as well as accept) messages with  Content-Type: application/octet-stream.

Thank you

Jamie

2 REPLIES 2

Jamsta1912
Tera Guru

I guess what I'm really asking here is: can I convert octet-stream into json, so that I can then do with it all the things I could normally do with json in a scripted API?

 

tim210
ServiceNow Employee
ServiceNow Employee

This part of the docs probably explains the error message:

https://docs.servicenow.com/bundle/kingston-application-development/page/Chunk1267879878.html

Important: If the request body format is not Application/json, Application/xml, or Text/xml, use only the request body dataStream field to access the request body. Using request body data, dataString, nextEntry(), or hasNext() with a non-default format will result in a 500 error response.

I don't know of an easy way to convert octet-stream data into JSON though. You probably would need to base64 encode the octet-stream data as a string, but be aware there are limits to the size of strings in Javascript on ServiceNow (32MB I think).