AWS IoT JSON Error - json

I'm trying to get a Skywire LTE Cat 1 modem (http://nimbelink.com/skywire-4g-lte-cat-1/) to update a thing shadow on AWS IoT. I have the device talking to AWS via HTTP, and am able to execute a GET command per their tutorial.
Now I am trying to execute a POST command to update my thing's shadow. However, whenever I try to send my POST command:
POST /things/AWS_Test_Thing/shadow HTTP/1.1
BODY: {"state":{"reported":{"Temp":55}}}
AWS sends me the following error:
HTTP/1.1 Bad Request
{"message":"Payload contains invalid json","traceId":"e53be1d6-7967f52c-4dd6-d7b95cc20628"}
I've never used JSON before, but from what I can gather,
{"state":{"reported":{"Temp":55}}}
should be valid JSON and complies with AWS IoT documentation (http://docs.aws.amazon.com/iot/latest/developerguide/thing-shadow-document-syntax.html#thing-shadow-example-request-json). What am I missing?

If you are updating the shadow via a POST request, you should have a "desired" statement instead of "reported".

Make sure you have the Content-Length header included as part of the request and signing procedure. The Content-Length must reflect the size of the JSON payload you are sending.

Related

API POST response returning 400 response code in Jmeter

I am trying to create a test plan using jmeter.its for an API Post request, I have a header manager, bodydata, checked for spellings and the syntax seems to be correct. However, Im getting 400 response code with the following error shown in the attached image. Anyone with an idea how I can resolve this? Thank you. the error
Here is the request the request
The user doesn't have to be logged in, i have added a header manager, I have also noticed there header has a cookie value thats hard coded but it appears to be the same in every request. In the UI the API request returns 200 and thats what im expecting with the Jmeter script.
In its current form the question cannot be answered comprehensively.
HTTP Status Code 400 means that
The 400 (Bad Request) status code indicates that the server cannot or
will not process the request due to something that is perceived to be
a client error (e.g., malformed request syntax, invalid request
message framing, or deceptive request routing).
Check that your ${site} and ${csVersion} variables have their respective values using Debug Sampler and View Results Tree listener combination
Cross check headers sent by JMeter and by the "UI", the most important is Content-Type
Use a sniffer tool like Wireshark of Fiddler and capture the requests which are being sent by JMeter and the "UI", the requests must be exactly the same apart from dynamic parameters which need to be correlated
The issues was being caused by an anti-forgery cookie which was hard coded in the request.I used a regex to extract the value from a previous request and used a variable value from the regex to make sure the same value is being passed on to the request that was failing.

Response code: 418 'I'm a teapot' in jmeter

I've been trying to test the API of restful-booker in Jmeter. But whenever I try to create a booking or Get a Booking by id I'm getting the HTTP response:418 'I'm a teapot'.If I try to access the URL in the browser it says the same. But when I run this in postman it does not give any kind of error. Also, it shows the correct response in Code Beautify. Really frustrating. Is there any way to resolve it?
If you're capable of successfully executing the request in postman (or whatever else tool) and not able to do it with JMeter most probably you're sending a different request.
Check out literally everything: URL, headers, body, etc. - all matters.
There are 2 approaches:
Use a 3rd-party sniffer tool like Fiddler or Burp to capture the requests from postman and JMeter and compare them for differences
Or just record the request from Postman using JMeter's HTTP(S) Test Script Recorder, JMeter will capture the request and generate relevant HTTP Request sampler and HTTP Header Manager
Problem is here: you forgot add accept: application/json in jmeter, postman automatically adds this setting.

API call to analyze a custom form

I am trying to make an API call to Microsoft's form recognizer to analyze a form against a custom model and I can't figure out how to do it.
Here is the documentation on the API
https://westus2.dev.cognitive.microsoft.com/docs/services/form-recognizer-api/operations/AnalyzeWithCustomModel
The request body is blank and I don't really know how that ought to be formatted in order to be sent off.
If you look at the POST Train model method, I was able to use that request body to send make that api call work. This indicates that the problem is me and not the API.
I have successfully done this with curl through command line...
curl -X POST "https://formrecognizerbp.cognitiveservices.azure.com/formrecognizer/v1.0-preview/custom/models/[MODEL ID]/analyze" -H "Content-Type: multipart/form-data" -F "form=#\"C:\Temp\Capture1.jpg\";type=image/jpeg" -H "Ocp-Apim-Subscription-Key: [SUBSCRIPTION ID]"
I don't really know/can't figure out how to convert that into a request body similar in format to what the POST Train Model method has.
I keep getting this error because I don't know how to format the request properly.
Internal : Unexpected error Error during Web API HTTP Request
HTTP Status Code: 400
HTTP Response Content: {"value":{"error":{"code":"BadRequest","message":"Could not process incoming request: 'Missing content-type boundary.'. Please ensure that it is well-formed."}},"formatters":[],"contentTypes":[],"statusCode":400}
So I guess formatters and contentTypes are the missing pieces but would that just be the file path and the image/jpeg parts of the curl ?
The /trainCustomModel API expects the data to be present on the Azure Blob storage. The request body to this request needs to contain a valid SAS URL to the training data. Once you successfully create a custom trained model ID, you could use that to analyze the forms. The /AnalyzeWithCustomModel API expects the data to be on your local file storage. Please ensure that you have the replaced the ModelId, API Subscription Key (Note this is not the same as subscription ID) and the local path to the image correctly.
The issue was that I did not realize that the curl script was overwritting the multipart/form-data Content-Type with image/jpeg and when I was trying to build out this call differently I was forcing a multipart/form-data Content-Type on what was a jpeg.

How to use a GET curl in postman?

I have this curl example:
curl -i -X GET -H "Content-Type:application/json" https://dev.ga.coach/intervention/:getworse/ -d '{"user_id": "012ab3", "section_id": "6"}'
When I run it through cygwin it's working properly! When I'm trying to import it in postman then it shows it as POST and I get the following response.
<h1>Not Found</h1>
<p>The requested URL /intervention/ was not found on this server.</p>
When I test https://dev.ga.coach/intervention/:getworse/ through web browser, this is what I see:
cURL allows you to include a payload on a GET request but the HTTP specification says:
A payload within a GET request message has no defined semantics;
sending a payload body on a GET request might cause some existing
implementations to reject the request.
When you try to make the same request with Postman, you are experiencing it "rejecting" the request. In this case, the rejection comes in the form of it converting to a POST request instead.
It would be appropriate to include a JSON payload on a POST request, but since it looks like you are trying to GET information you should move the data to the URL instead.
For example:
https://dev.ga.coach/intervention/012ab3/6/:getworse/
This will require you change your server-side code (which you, presumably, can do since you said I'm developing the rest-apis) to read the data from the new location.

When use AWS Lambda to process mails from mailgun, can't get mails in JSON format

What I am tried to do is to have a lambda function proccess emails forwarded by mailgun.
So far, I have setup mailgun's route so it will forward emails to a AWS api gateway, then the api gateway triggers a lambda function.
The problem comes when I try to process the mail, instead of getting a pretty Json that I am expecting inside the lambda's event.body, I m getting raw post form data like
--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent-Disposition: form-data; name=\"Content-Type\"\r\n\r\nmultipart/mixed; boundary=\"001a1140216cee404d05440c49e7\"\r\n--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent-Disposition: form-data; name=\"Date\"\r\n\r\nTue, 20 Dec 2016 13:40:53 +1300\r\n--cff4e6b3-a3a4-4131-bb8d-90a73f1b4c36\r\nContent ......
My question is, what should I do to get the JSON version of the forwarded emails in lambda?
Not sure if you ever came to a solution, but I have this working with the following settings.
Setup your API Gateway method to use "Use Lambda Proxy integration"
In your lambda (I use node.js) use busboy to work through the multi-part submission from mailgun. (use this post for help with busboy Busboy help)
Make sure that any code you are going to execute after all busboy is complete is executed in the 'finish' portion of the busboy code.
This suggests that your mailgun route is misconfigured and ends with a MIME request:
When you specify a URL of your application as a route destination through a forward() action, Mailgun will perform an HTTP POST request into it using one of two following formats:
Fully parsed: Mailgun will parse the message, transcode it into UTF-8 encoding, process attachments, and attempt to separate quoted parts from the actual message. This is the preferred option.
Raw MIME: message is posted as-is. In this case you are responsible for parsing MIME. To receive raw MIME messages, the destination URL must end with mime
From Receiving Messages via HTTP through a forward() action