I have tried posting data in curl using this command:
curl -X POST http://x.x.x.x:1111/send --data [{'virtual':'5555'}]
Then I am getting a response in node like this:
{ '{virtual:5555}': '' }
How to convert this to array? I have tried JSON.parse() and JSON.stringify() but I get an Unexpected token o error as result.
Any idea how to post the json data in curl command?
I also tried with:
curl ... -H "Accept: application/json" -H "Content-Type: application/json"
Try with:
curl -X POST -H "Content-Type: application/json" -d '[{"virtual":"5555"}]' "http://x.x.x.x:1111/send"
Then you should receive the raw body as '[{"virtual":"5555"}]':
var body = JSON.parse(req.body);
or, already parsed (if you use a middleware). And you can use it:
console.log(body.length); // 1
console.log(body[0].virtual); // '5555'
Related
I'm trying to send Jenkins build data to Datadog via cURL command but it fails with Invalid JSON structure error. I've validated that the JSON payload I'm sending is valid.
I'm sending metric by run shell in my Jenkins groovy file that runs a curl command.
Groovy:
sh """curl -X POST "${uriDataDog}" -H "Content-type: application/json" -H "DD-API-KEY: ${DD_API_KEY}" -d '${finalPayload}' """
This is executed as:
curl -X POST https://api.datadoghq.com/api/v2/series -H 'Content-type: application/json' -H 'DD-API-KEY: ****' -d '{"series":[{"metric":"jenkins.step.duration","type":0,"points":[{"value":8,"timestamp":1655186740}],"tags":{"stage":"post_always"}}]}'
But it errors out with the following error:
`{"errors":["Invalid JSON structure: json: cannot unmarshal object into Go value of type []json.RawMessage"]}`
Have validated the same with the Datadog documentation and nothing seems wrong.
I've also tried using alternatives to this as
sh(script: "curl -X POST $uriDataDog -H \"Content-type: application/json\" -H \"DD-API-KEY: $DD_API_KEY\" -d '$finalPayload'")
and
["curl", "-X", "POST", "${uriDataDog}", "-H", "DD-API-KEY: ${DD_API_KEY}","-H", "Content-Type: application/json", "-d", "'${finalPayload}'"].execute().text
but even this doesn't work.
I want to pass the request body, but it doesn’t work out for me, maybe I wrote it wrong
curl -H "Content-Type: application/json" -X POST "{"time": "2019-12-27T09:50:02.000+0000", "unread:" "true", "message": "hello","from":"Vadim"}" localhost:8080/api/save
You need to escape the json body or use single quote to wrap your json
curl -XPOST -H "Content-type: application/json" -d '{"time": "2019-12-27T09:50:02.000+0000", "unread:" "true", "message": "hello","from":"Vadim"}' 'localhost:8080/api/save'
Or on windows
curl -X POST -H "Content-type: application/json" -d "{'time': '2019-12-27T09:50:02.000+0000', 'unread': 'true', 'message': 'hello','from':'Vadim'}"
You can get the crul command from the postman
click on the code from drop down get the cURL which will give the cur command from that you can run
refrence link : https://learning.getpostman.com/docs/postman/sending-api-requests/generate-code-snippets/
If you have swagger enabled for you Spring Boot APP from that also you can able to see crul command
-X POST "{"time": "2019-12-27T09:50:02.000+0000", "unread:" "true", "message": "hello","from":"Vadim"}"
Your JSON is invalid. {"unread:" "true"} should be {"unread":"true"}.
After that you need to escape the JSON's double quotes:
-d "{\"time\":\"2019-12-27T09:50:02.000+0000\",\"unread\":\"true\",\"message\":\"hello\",\"from\":\"Vadim\"}"
Obviously I can't test your curl command, but I think this should work for you.
How do I can send JSON object to solr collection usinc cUrl
I'm using Windows 10.
curl -X POST -H "Content-Type:application/json" "http://localhost:8983/solr/solr_sample/update/json/docs" --data-binary "{'id': '1','title':'Doc 1'}"
When I'm using this format I'm getting some kind of warning message:
curl -X POST -H 'Content-Type:application/json' 'http://localhost:8983/solr/sorl_sample/update/json/docs' --data-binary '{"id": "1","title":"Doc 1"}'
curl: (1) Protocol "'http" not supported or disabled in libcurl
curl: (3) [globbing] unmatched close brace/bracket in column 14
I resolved it using " " insted of ' '
When I send the request using the first url I'm getting this response:
{
"responseHeader":{
"status":0,
"QTime":112}}
But when I try to get some result by searching I can't see any object in docs[]
curl -X GET "http://localhost:8983/solr/solr_sample/select?q=*:*"
Result:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"*:*"}},
"response":{"numFound":0,"start":0,"docs":[]
}}
When I'm using Solr UI I can add JSON objects without any problems, also to see the result in terminal
You have to commit the update. Add commit true or commitWithin 1000 to the request, e. g.
curl -X POST -d '{"add":{"doc":{"id":"delete.me","title":"change.me"},"commitWithin":1000}}' -H "Content-Type: application/json" http://localhost:8983/solr/solr_sample/update
Does also work:
curl -X POST -d '{"add":{ "doc":{"id":"delete.me","title":"change.me"}}}' -H "Content-Type: application/json" http://localhost:8983/solr/solr_sample/update?commit=true
I try trigger below script and send notification to mobile using parse. Below is my script.
curl -X POST \
-H "X-Parse-Application-Id:app-id-here" \
-H "X-Parse-REST-API-Key:rest-key-here" \
-H "Content-Type: application/json" \
-d '{ "data": {"alert": "A test notification from Parse!"}}' \
https://api.parse.com/1/push
and i got error as below:
curl: (6) Could not resolve host: \ {"code":107,"error":"invalid json: { data: {alert:A"}
whats wrong with my json data?
So the main issue is that the 'script' needs to be on multiple lines if the backslash marks (\) are present, and there cannot be any spaces after backslashes. I've edited your question to format it correctly, and it works.. returning a better error.
{"code":115,"error":"Missing the push channels."}
You just need to alter the JSON to include a channel or a query to push to, based on the docs here: https://parse.com/docs/push_guide#sending-channels/REST
curl -X POST \
-H "X-Parse-Application-Id:app-id-here" \
-H "X-Parse-REST-API-Key:rest-key-here" \
-H "Content-Type: application/json" \
-d '{ "channels": ["Giants"], "data": {"alert": "A test notification from Parse!"}}' \
https://api.parse.com/1/push
I am trying to upload a JSON file using Parse's REST API with no success so far.
The request I am trying to make is the following:
curl -X POST \
-H "X-Parse-Application-Id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "X-Parse-REST-API-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type: application/json" \
-d '{ "name" : "myName" }' \
https://api.parse.com/1/files/test.json
The reponse is as follows:
{"code":1,"error":"internal error"}
I believe my request is correct, the JSON is valid, my Application ID and REST API Key are also correct.
To top it off, I can successfully upload an invalid JSON. For example, the same request with an invalid JSON:
curl -X POST \
-H "X-Parse-Application-Id: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "X-Parse-REST-API-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-H "Content-Type: application/json" \
-d '#{ "name" : "myName" }' \
https://api.parse.com/1/files/test.json
Returns a correct reponse JSON:
{
"url":"http://files.parsetfss.com/e88af32e-2e48-400b-aa1c-2f167f3d2785/tfss-550782bd-718c-46b1-bac1-9e366f957d7a-test.json",
"name":"tfss-550782bd-718c-46b1-bac1-9e366f957d7a-test.json"
}
Has anyone had similar problems, or could anyone point me what I am doing wrong?
[]'s!