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

DScroggins
Kilo Sage

Hi Shane,

 

Is your API method configured as POST?

Yes,  I'm sorry if I did not make that clear, but the Scripted REST Resource is setup with a POST HTTP Method.  This is why the error makes no sense to me.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Shane,

why not use Attachment API?

https://docs.servicenow.com/integrate/inbound_rest/reference/r_SamplePOSTMultipart.html

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

There are 2 reasons:

  1. As I mentioned, the vendor cannot utilize any ServiceNow information (like a sys_id) when sending the submission, so they are unable to provide the required details to use the Attachment API.
  2. Not all of the parts of the multipart/form-data are to be attachments.  At least one of the parts will be application/json data that will need to be parsed to coalesce the record and populate fields on the target record.