Get non file body from multipart/form-data using AWS API Gateway and Lambda - forms

I am trying to get the form data from a multipart/form-data POST to my ASW Lambda web service via API Gateway.
The HTTP POST has Content-Type "multipart/form-data" and body that is URL encoded. File data is also sent in this post (hence the multipart, I guess).
The web service needs to integrate with a thirdparty service, so changing the format of the POST isn't really an option.
I have seen this thread talking about converting the URL encoded data to JSON object for use in Lambda, but this doesn't do the trick.
I have also tried setting the Integration Request -> Mapping Templates for content type multipart/form-data to Input passthrough. This didn't help either.
I did come across another question about uploading a file using multipart/form-data, but since I'm not interested in the file, just the body, that answer didn't help.
Below find screenshot (sorry) of the captured post via runscope.

If the goal is to use Lambda, you'll need to pass valid JSON to the function. Currently there isn't a way to JSON-ify data inside Api Gateway that comes in as non-JSON data.
Our short term fix (on our backlog) is to provide a variable in the mapping templates to grab the raw input of the request. That way you could do a simple JSON conversion using a template like:
{
"body" : "$input.body"
}
or something like that.
Check out the mapping template reference for more info: http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html
Edit 4/7 - feature has been released as $input.body

Related

Talend tREST component cookie extract

I'm working on a pretty straight forward proof of concept to log-in via a POST action using Talend.
From the application side, I use a POST with a body to then receive a cookie. However, I'm at a loss for how to get the cookie details from the response of the endpoint.
In my forum lurking, there appear to be two approaches: one using tREST, the other using tRESTClient.
Using tREST, I can successfully post to the endpoint, but I can not appear to retrieve the response header or body:
This is the tREST component properties:
The cookie passed from this call needs to be recycled into subsequent calls in order for them to authenticate.
I'm hoping to understand how to get the Cookie out and passed along, either with tREST or tRESTClient. My issue with tRESTClient is that I do not have a way to pass the body to that component.
Any thoughts?
On your last point - you can pass the body to tRestClient by having a flow going into tRestClient. That flow can have a "string" field containing the body in json format, and that field will need to map to the "string" column in the component input schema.
If, in your case, you do not already have a flow containing the body, you can generate it by using the tFixedFlowInput component.

Node-Red HTTP Input verify json

this might be a stupid question but I was unable to find a solution, also no luck with search.
My Node-Red flow gets triggered by a HTTP Input because I want to create a REST Webservice. It works fine so far but I wonder how to verify the content someone send to me.
As I see right now, I can pass any kind of content. There is no verification if the content matches to the content I want as input.
If I set content-type to application/json, it only accepts json data. That's great but I also want to ensure, users can post only a specific json string.
If someone sends data I'm unable to proceed (not the json object I expected), I want to send HTTP 400 as response.
I'm pretty new to Node-Red and also to json. I'm more an old-school programmer using classic webservices and soap. What I'm missing is some kind of WSDL (not sure if it exists when using REST) and some kind of payload validation.
It would be great if someone can point me the way to go.
Best regards
Patrick
There are some nodes available for doing schema validation on JSON objects.
For example, node-red-contrib-json-schema-validator - which uses ajv as the validation engine under the covers. Unfortunately this node doesn't come with much in the way of help. Essentially it lets you provide your schema and if a message fails to validate, it logs an error which can be handled with a Catch node if you want.
I found the issue. It was too bad.
I just forgotten to set HTTP Header content-type to application/json.
node-red-contrib-json-schema-validator works like a charm if content type is set corret

Cloudinary Error: "Missing required parameter - file" via REST API

I'm just getting started with Cloudinary, and I'm attempting to Uploading with a direct call to the API. Using the DHC REST Client (chrome extension), I put my request together per the instructions found here at Creating API authentication signatures. Here's a screenshot of that request and response.
I also tried...
adding quotes around all values except timestamp as shown in the example
making the request a multi-part request and attaching the image to the body as a "file"
deleting timestamp, api_key, and signature and instead replacing them with upload_preset to try and upload an unsigned image (yes, I created the preset)
And finally, I did try adding public_id even though it says it would assign one if not provided.
In all cases, I get the same error response... Missing required parameter - file
Can anyone tell me what I'm missing?
Ok, figured it out. These name/value pairs need to be added to the body of the request rather than the header. Here's what that would look like in the DHC client. Note that the upload_preset will not work for you... I only created it to test with. Also note that doing a signed request is accomplished the same way but with different parameters.

How to deal with this situation building a REST API?

I got this problem, I have built a rest api and I don't know how to deal with this:
When the javascript client (Marionette.js) is in charge of making the views, I don't have problems, because as it is known, it just requests an url (e.g. example.com/user/37), the server retrieves a json with {id:'37', name:'Peter', age:'24'} (there is one controller class named User) and Marionette shows that data in the view. But if the user enter to example.com/user/37 by the browser it will show just {id:'37', name:'Peter', age:'24'} without any view. What can I do if I want to see the same view in both cases?
If you're trying to serve up HTML or JSON from the same endpoint then your server should be making that decision based on the request's Accept header. If the request's Accept header is application/json then your server should return just the JSON ortherwise return the HTML.
You can see that SoundCloud uses the same technique for returning XML or JSON from their API:
Resources are returned as XML by default, or JSON if a .json extension is appended to the resource URI. We encourage you to use JSON. You can also send an appropriate Accept header specifying the format you would like. For example, a request with the header Accept: application/json will return resources represented as a JSON document.
What you are trying to do is pratically impossible.
why ?
When your first enter the url example.com it's the server that responds with all the artifacts that compose your application (html, js, css ...) and the browser display it.
Now, when you enter ther url example.com/user/37 the server only sends the JSON data without any html, js or css, so the browser display the raw data he received.
What you are trying to do is to force the server to give two responses (JSON or html/js/css) depending on the user request.
You can do it, but it would be so complicated that's not worth the efforts.

RESTful post in Oracle Service Bus

Does anyone know how to create a proxy service that will handle this sort of thing?
What I'm looking for is a path parameter and a post body being formatted similar to this:
POST www.myurl.com/{123}
Post body:
myId=1&myOtherId=2
I am currently passing in an XML document and I'm doing an insert on the http:relative-URI element in the transport. This seems to work.
I am also currently doing an insert on the http:query-parameters for my post body name/value pairs.
I am inserting these on the outbound variable. When I debug, both are showing up and I'm contacting the REST service. I am getting a 400 -- Bad Request error. This happens when the post body is not configured correctly.
Any ideas how to do this?
If you are just Posting an XML, then while creating Proxy Service, Select Service Type as Any XML.