Inbound Multipart/form-data via the Scripted REST API (in a scoped application)

Shane-DXC
Tera Expert

Is it possible to accept multipart/form data via the Scripted REST API (in a scoped application)?  A vendor can only send their data and associated attachments using multipart/form-data and they also are unable to utilize any ServiceNow information (like a sys_id) when sending the submission.  Any time I try to POST to the Scripted REST API with a multipart/form-data Content-Type, I am currently receiving an error message stating "com.glide.rest.domain.ServiceException: Service error: attempt to access request body is not allowed when request method is GET or DELETE".

Has anyone successfully parsed an inbound multipart/form data via the Scripted REST API (in a scoped application)?

===============

UPDATE:

Let me add some additional details as it appears the (much appreciated) responses are getting off track.

  • Both the Scripted REST Service and the associated Scripted REST Resource have 'multipart/form-data' added as a value added under the 'Default supported request formats' (with 'Override default supported request formats' checked as TRUE).
  • The Scripted REST Resource has the 'HTTP Method' set as 'POST'

The multipart/form-data contains multiple parts (which are separated by the boundary which is defined in the header), including base64 encoded attachments, binary attachments, and application/json data to be processed.  I will need to use data from the application/json part of the payload to determine if this will be creating a new target record or updating an existing record (a coalesce value is within the JSON).  The remaining parts of the payload will be attachments on the target record (and I know how to create the base64 encoded data as an attachment and have a plan on how to create the attachments from the binary data).  However, I can't even get to start parsing any of the payload if the system won't even allow me to access the request body (based on the error message).

Essentially, the system seems to be providing an invalid error when I am attempting to process a POST request with a multipart/form-data Content-Type, somehow interpreting the submission instead as a GET or DELETE method rather than a POST.

15 REPLIES 15

No - this was never resolved and an answer/solution was never provided.

A workaround i did was using a third party middleman webhook processor (https://pipedream.com/) to forward on the response to SNow.

boz
Tera Expert

Also further to add to this... if you don't want to use a third party middleman api request processor to forward on the the request, i found under "The Solution" in this article, helped me get the data from the request.

*note: as it returns everything as one big string, i had to do some heavy JavaScript manipulations to extract the data content i wanted and then turn it back into an object to parse.

Also don't forget to add multipart/form-data in the Override supported request formats field

 

zmehta
Tera Contributor

Hi Shane,

If the request body format is not of a json or xml subtype, use only the request body dataStream field to access the request body. Using request body data, dataString, nextEntry(), or hasNext() with a non-json or non-xml format results in a 500 error response.

Thanks
Z

Tae Kyung Lee
Tera Expert

I'm also strugglling this problem.

And finally gave up~

I have decided to use iPaaS to redirect call twice(getting sys_id then call attachment api)

I can't understand why SNOW limit API scripting too much.