I am using fiddler 4 as a frond-end service for elasticsearch.
I'm trying to store a document into index using API following this.
Here's my sample json as request body:
{
"fruit": "Apple",
"size": "Large",
"color": "Red"
}
API : http://localhost:9200/food/fruit
method :POST HTTP/1.1
Here's the response:
As mentioned in their doc., "Starting from Elasticsearch 6.0, all REST requests that include a body must also provide the correct content-type for that body." adding content-type: application/json in the request solved the issue.
Related
I want to extract json part in a message with node red
I receive the message in node red but I can't extract the data
exemple of a message:
POST / HTTP/1.1
Host: xxx.xx.xxx.5:9000
User-Agent: libcurl-agent/1.0
Content-type: application/json
Accept: application/json
Content-Length: 526
{
"timestamp": 1571997083,
"data": {
"temperature": 20.613545532227,
"humidity": 61.3828125,
"battery": 3.47
},
"frame": "814962xxxx16a1dc5",
"gatewayID": "AA555Axxxx0xx964",
"othersGW": [],
"clientID": "xxxx",
"DevAddr": "011xxxxb",
"DevEUI": "8cf9xxx000000xxx",
"sensorInstallId": "8cf95xxx0000xxxx",
"loraPort": 8,
"fcnt": 1607,
"rxpk": {
"tmst": 2380181019,
"time": "2019-10-25T09:51:23.472998Z",
"chan": 0,
"rfch": 0,
"freq": 867.1,
"stat": 1,
"modu": "LORA",
"datr": "SF7BW125",
"codr": "4/5",
"lsnr": 9,
"rssi": -72,
"size": 22,
"data": "xxxxxxxxxxxxxxxx/YxWg=="
}
}
so I would like to have data of temperature etc...
and I don't know the node I have to use
Thanks a lot
Having got a better view of what you are trying to do from the comments.
Using the TCP-in node is probably not the right approach for this. You will do much better using the HTTP-in/HTTP-out nodes as these will handle dealing with all the HTTP-header and sending a proper response to the client so the connection gets closed.
The HTTP-in node takes a path e.g. /input which will be appended to the Node-RED URL giving something like http://localhost:1880/input. It also takes a HTTP verb which in this case would be POST. You can find more details and lots of examples in the Node-RED cookbook here.
You will need to update the client to point to the correct path and port.
You will need JSON node to convert the message string into an object.
Nodered has a very good documentation and hands on examples.
See below for some help:
This is great example how to to use the json node
This
describes how to work with JSON data
Below code is for POST API:
{
"request": {
"method": "GET",
"urlPattern": "/identity/v2/users/7983739"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body" : "{ 'language': 'en‐US', 'phoneNumbers': [{'type': 'home','value': 8059662323}, {'type': 'office','value': 8053088006},{'type': 'mobile','value': 6502229400}],'addresses': [{‘address1': '419 State St’,’address2': '2nd Floor’,’city': 'Santa Barbara’,’state': ‘CA’,’postalCode': 93101,’country': ‘US’,’type': ‘shipping'}] }"
}
}
Now, I want to update the body with the below data:
"body" : "{'language':'en‐US','phoneNumbers':[{'type':'home','value':8059662323},{'type':'home','value':6502229400}],'addresses':[{'address1':'419 State St','address2':'2nd Floor','city':'Santa Barbara','state':'CA','postalCode':93101,'country':'US''type':'shipping'}]}"
Can someone tell me how to do it using Jmeter...
Here are the steps:
Add HTTP Request Sampler to your Test Plan
Configure host, port, URL, etc.
Select "PUT" from "Method" dropdown
Switch from "Parameters" to "Body Data" section
Provide new JSON value there
You might also need to add HTTP Header Manager to send at least Content-Type header with the value of application/json.
See Testing SOAP/REST Web Services Using JMeter article for detailed information on how to get started with API testing using JMeter
you can have the entire body in a variable and then user it here with ${variable}
you can also check here http://fabiouechi.blogspot.com/2011/03/jmeter-posting-json-data-to-web-service.html
I'm using play/scala for a webapp and a scala API, currently running simply on two different ports on localhost:9000 and localhost:8080 respectively. I have the basic page from the fine-uploader.com website docs, and a simple test page build in Play. (FWIW, i don't think much of the above is relevant)
When i post a file, chunked or not, Fine uploader receives a 200 from the API and valid JSON, but JSON.parse returns a failure. The logging from fine-uploader is below. If i take this output and run it through (in the console)
JSON.parse(JSON.stringify(json))
a valid object is returned. I can't just JSON.parse(json) directly in the browser tools b/c its already an object. I have checked the types by console.log'ing typeOf json in the qq.parseJson method and it returns string, so no conversion should be required, though i have tried it with the same results.
fine-uploader console logs:
[Fine Uploader 5.5.1] Sending simple upload request for 0 fine-uploader.js:251
[Fine Uploader 5.5.1] xhr - server response received for 0 fine-uploader.js:251
[Fine Uploader 5.5.1] responseText = {"code":"UPLOAD_COMPLETE","response":{"MediaModel":{"id":1103,"publicUri":"http://localhost:8080/media/Archive.zip","fileLocation":"/src/services/api/src/main/webapp/media/Archive.zip","mediaDate":{"year":2016,"month":2,"day":28},"mediaOrder":1,"viewName":"","caption":"","altText":"","isPublic":1,"fileSize":1107080,"created":"2016-02-28T14:58:43Z"},"UserMediaModel":{"id":1,"userId":24,"mediaId":3,"created":"2016-02-17T12:48:18Z"}},"errors":[]} fine-uploader.js:251
[Fine Uploader 5.5.1] Received response status 200 with body: {"code":"UPLOAD_COMPLETE","response":{"MediaModel":{"id":1103,"publicUri":"http://localhost:8080/media/Archive.zip","fileLocation":"/src/services/api/src/main/webapp/media/Archive.zip","mediaDate":{"year":2016,"month":2,"day":28},"mediaOrder":1,"viewName":"","caption":"","altText":"","isPublic":1,"fileSize":1107080,"created":"2016-02-28T14:58:43Z"},"UserMediaModel":{"id":1,"userId":24,"mediaId":3,"created":"2016-02-17T12:48:18Z"}},"errors":[]} fine-uploader.js:251
[Fine Uploader 5.5.1] Simple upload request failed for 0
The server is responding with a 200 per the API logs and i can see the exact response object in the Response tab of Chrome Dev tools.
I added a custom error handler, but not more more information was provided, just that the error is the text output
Error on file number 0 - Archive.zip. Reason: {"code":"UPLOAD_COMPLETE",....same as above
Lastly, all rows are propery inserted into the database as you see from the id's created above. And all logging points to an equally successful action.
Thanks for any pointers. I've also put this output in http://jsonlint.com/ and it parses fine.
Thanks! (sorry for the lack of JSON formatting, i can change it, but this seemed long enough already)
EDIT
It seems that i have satisfied the requirements stated in the other question with "success":true and Content-Type=text/plain. The following, per request is the JSON output and the headers
Headers:
Key: Access-Control-Allow-Origin Value: http://localhost:9000
Key: Date Value: Mon, 29 Feb 2016 00:55:19 GMT
Key: Access-Control-Allow-Credentials Value: true
Key: Content-Type Value: text/plain; charset=UTF-8
{
"code": "UPLOAD_COMPLETE",
"response": {
"MediaModel": {
"id": 1169,
"publicUri": "http://localhost:8080/media/Archive.zip",
"fileLocation": "/src/services/api/src/main/webapp/media/Archive.zip",
"mediaDate": {
"year": 2016,
"month": 2,
"day": 28
},
"mediaOrder": 1,
"viewName": "",
"caption": "",
"altText": "",
"isPublic": 1,
"fileSize": 1107080,
"created": "2016-02-29T00:55:19Z"
},
"UserMediaModel": {
"id": 1,
"userId": 24,
"mediaId": 3,
"created": "2016-02-17T12:48:18Z"
}
},
"errors": [],
"success": true
}
I'm sure this will end up being something silly, so i appreciate the input.
Based on the error reported by Fine Uploader, your response is not properly formatted. If you look closely at the response in your browser's network tab (such as with Chrome dev tools), you'll likely see a JSON string that, once parsed using JSON.parse results in another JSON string instead of a JavaScript object containing the expected properties. I can't confirm this as you haven't posted the exact response from your server, but I'm certain that this is the case. This is most likely caused by an encoding issue server-side. For example, your server should return this: {"foo": "bar", "success": true} instead of this: "{\"foo\": \"bar\", \"success\": true}". I suspect your server is returning the latter.
I'm trying to formulate a body for my load job (multipart) into Bigquery. Following the example on https://cloud.google.com/bigquery/loading-data-post-request#multipart:
-foo_bar_baz
Content-Type: application/json; charset=UTF-8
{
"configuration": {
"load": {
"sourceFormat": "NEWLINE_DELIMITED_JSON",
"schema": {
"fields": [
{"name":"word","type":"STRING"},
{"name":"word_count","type":"INTEGER"},
{"name":"corpus","type":"STRING"},
{"name":"corpus_date","type":"INTEGER"}
]
},
"destinationTable": {
"projectId":"myproject",
"datasetId":"mydataset",
"tableId":"mytable"
}
}
}
}
--foo_bar_baz
Content-Type: */*
[MY-JSON-DATA]
--foo_bar_baz--
But I get the message from google saying:
"message": "Job configuration must contain exactly one job-specific configuration object (e.g., query, load, extract, spreadsheetExtract), but there were 0: "
If I look at the docs at https://cloud.google.com/bigquery/docs/reference/v2/jobs#configuration.load it seems that the sourceUris[] is required but the example doesn't include it. My data is not in the google cloud storage but in the request. Why doesn't it detect my load details?
Thanks for any help. //Leif
Based on the message - looks like you are missing below
Content-Type: multipart/related; boundary="foo_bar_baz"
You were right. I had an extra space in my header for Content-Type, I saw it using fiddler and it looked like this:
`Content-Type : multipart/related; boundary="foo_bar_baz"
Thanks for your support.
I have very simple controller with the following method:
def createNewWidgetVersion() {
println request.JSON
render status: OK
}
I'm sending the following request:
POST /CMSAdmin/widgetVersion/createNewWidgetVersion HTTP/1.1 Host:
localhost:8080
Content-Type: application/json
Cache-Control: no-cache
{ "htmlText":"33", "javaScript":
"document.getElementById('ffsdfdsfsfsfsd')", "comments":"SUCCESS",
"widgetId": "1", "type": "LIVE" }
and when debugging, IDE shows that request.JSON is empty. Controller doesn't extend RestfullController but I think it doesn't have to in this particular siutation. Could you please give a hint what I'm doing wrong? Spent few hours dealing with this. Thanks!
UPD1
I added the following to UrlMappings.groovy:
"/widgetVersion/"(controller: "widgetVersion", parseRequest:true){
action = [POST:'createNewWidgetVersion']
}
is there any way to avoid this? Thanks!