06-25-2019 07:50 AM
I’m having trouble correctly formatting multipart form-data to be sent as the body of a REST Post request along with a single file upload.
I’ve managed to get the Post request to correctly send in Postman with the required key/value pairs and a test file:
However, when attempting to replicate this in SnapLogic I am unsuccessful.
I’ve managed to correctly map the key/value pairs in a mapper, and have created the following JSON in a JSON generator using my mapped values:
I’ve used my “entity” object as the HTTP entity in my Post request, and pointed to a local test file for upload in my REST Post snap:
Is my approach to compiling the form-data correct, or no?
05-20-2020 11:08 AM
I’ve resolved the issue with help from another SnapLogic community page. See https://community.snaplogic.com/t/rest-post-with-form-params-in-the-body-of-the-request-giving-error....
I changed the Content-Type to expect: application/x-www-form-urlencoded (rather than multipart/form-data) and I serialized the body using the expression: $.entries().map(e => e[0] + “=” + encodeURIComponent(e[1])).join(“&”), which I passed into the HTTP entity field in the REST Post. I can now make a successful request.