how to pass arguments in curl command - shell

i am getting the below error while executing the curl command in unix. Not sure if this is the right way to put the arguments in curl. Can you please advise on this?
curl -X POST -H Authorization:'Bearer AAEAAJ6ZNfGbzJkSuJ1o5rXLBec5Q' -H 'Content-Type: application/json' -d {"Filter": {"ClientName": "ABC","WorkflowName": "sk_lask"},"SortingName": "StartDate","SortingOrder": "Desc"} http://someaddress.com/api/status/search HTTP/1.1
error
curl: (3) [globbing] unmatched brace at pos 13
curl: (6) Could not resolve host: ABC,WorkflowName; Unknown error
curl: (3) [globbing] unmatched close brace/bracket at pos 9
curl: (6) Could not resolve host: StartDate,SortingOrder; Unknown error
curl: (3) [globbing] unmatched close brace/bracket at pos 5

You need to quote your header, payload and also remove HTTP/1.1 from end as this command:
curl -X POST -H 'Authorization: Bearer AAEAAJ6ZNfGbzJkSuJ1o5rXLBec5Q' \
-H 'Content-Type: application/json' \
-d '{"Filter": {"ClientName": "ABC","WorkflowName": "sk_lask"},"SortingName": "StartDate","SortingOrder": "Desc"}' \
'http://someaddress.com/api/status/search'

Related

parse error: Invalid numeric literal at line 1, column 7

I am trying to call an API using Curl. The request was timing out after 60 secs due to TCP Timeout. I added "-H "Connection: keep-alive" -H "Keep-Alive: timeout=90, max=100" to the existing code.
curl -s -X POST -u $regressionTestAuthToken -H Content-Type: application/json -H Accept: application/json -H "Connection: keep-alive" -H "Keep-Alive: timeout=90, max=100" $URL -d#"${WORKSPACE}"/tmp.json > "${WORKSPACE}"/out.json
After adding the Connection Keep-Alive, I am getting a parse error
parse error: Invalid numeric literal at line 1, column 7
Can someone help me to triage this issue?

Why does curl see several parameters? [duplicate]

This question already has answers here:
When to wrap quotes around a shell variable?
(5 answers)
Closed last year.
I want to send a message to a slack app in a script:
...
declare -a models=("TR10"
"TR100"
"TR1000")
for i in "${models[#]}"
do
#Send Message
if [ $use_slack_app ]
then
message="Starting model $i ($c of $lenght)!"
data=''\''{"text":"'"$message"'"}'''\'
echo $data
curl -X POST -H 'Content-type: application/json' --data $data $slack_app_url
echo "curl -X POST -H 'Content-type: application/json' --data $data $slack_app_url"
fi
#Counter
((c=c+1))
done
...
return of echo $data:
'{"text":"Starting model TR10 (1 of 3)!"}'
curl message:
curl: (3) unmatched close brace/bracket in URL position 5:
3)!"}'
^
curl: (6) Could not resolve host: model
curl: (6) Could not resolve host: TR10
curl: (6) Could not resolve host: (1
curl: (6) Could not resolve host: of
invalid_payload
It looks like it sees the string as several parameters, but I don't understand why. If I echo the line out, and run it in the terminal it works. I don't have much experience with bash scripting, so I don't understand what the problem here is.
Quote the variable expansions to ensure values with spaces are sent as one word: "$var" vs. $var.
Get rid of the single quotes (''\') surrounding $data.
data='{"text":"'"$message"'"}'
curl -X POST -H 'Content-Type: application/json' --data "$data" "$slack_app_url"

Curl "(6) Could not resolve host: http"

I am trying to run this command
curl -XPUT -H "Content-Type: application/json" https://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
But this results in this error
curl: (6) Could not resolve host: http
curl: (3) unmatched close brace/bracket in URL position 5:
null}'
I got this command from here
https://stackoverflow.com/a/50609418/3259896
I'm am not yet very familiar with curl nor elasticseach, so I'm not sure how to pinpoint the error
If it makes a difference, I am using Windows.
I also tried
$ curl -X PUT -H "Content-Type: application/json" https://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
Edit2:
I tried
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d '{"index.blocks.read_only_allow_delete": null}'
But now get this error
{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput#446f2dd5; line: 1, column: 2]"}],"type":"json_parse_exception","reason":"Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput#446f2dd5; line: 1, column: 2]"},"status":400}curl: (3) unmatched close brace/bracket in URL position 5:
null}'
^
I then tried
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d "{"index.blocks.read_only_allow_delete": null}"
And I got
{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Unexpected character ('i' (code 105)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput#696b36d3; line: 1, column: 3]"}],"type":"json_parse_exception","reason":"Unexpected character ('i' (code 105)): was expecting double-quote to start field name\n at [Source: org.elasticsearch.transport.netty4.ByteBufStreamInput#696b36d3; line: 1, column: 3]"},"status":400}
First off, in that other SO question, the ES node was a live one so its URL included https.
Your localhost ist almost certainly not going to have https so change it to http:
curl -XPUT -H "Content-Type: application/json" \
http://localhost:9200/_all/_settings \
-d '{"index.blocks.read_only_allow_delete": null}'
Other than that, everything looks okay, provided that your ES is running.
When successful, you should receive a simple message:
{"acknowledged":true}
Edit: go with
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_all/_settings -d "{\"index.blocks.read_only_allow_delete\": null}"

adding snapshot to elasticsearch Windows

I have two snapshots that I want to insert into elasticsearch in path:
C:\Users\name\Downloads\book_backup\agg_example
C:\Users\name\Downloads\book_backup\search_example
which I properly listed in elasticsearch.yml
path.repo: ["C:\\Users\\olulo\\Downloads\\book_backup\\agg_example", "C:\\Users\\olulo\\Downloads\\book_backup\\search_example"]
my elasticsearch starts fine and creating a new index works too.
Now when I try to insert snapshot into my elasticsearch so I can work on it:
curl -XPUT "http://localhost:9200/movies/" -d '{"type":"fs", "settings":{"location":"C:\\Users\\name\\Downloads\\book_backup\\search_example", "compress":true}}'
It gives me:
curl: (1) Protocol "'http" not supported or disabled in libcurl
curl: (3) [globbing] unmatched brace in column 10
curl: (3) [globbing] unmatched close brace/bracket in column 14
In https://www.elastic.co/guide/en/elasticsearch/reference/5.2/modules-snapshots.html it seems like they've added a name at the end of path in location so I did
curl -XPUT "http://localhost:9200/movies/" -d '{"type":"fs", "settings":{"location":"C:\\Users\\name\\Downloads\\book_backup\\search_example\\test", "compress":true}}'
but still gives me same error.
following https://superuser.com/questions/1322567/http-not-supported-or-disabled-in-libcurl I've change everything to double quotes:
curl -XPUT "http://localhost:9200/_snapshot/javacafe" -d "{"type":"fs", "settings":{"location":"C:\\Users\\olulo\\Downloads\\book_backup\\search_example", "compress":true}}"
giving me :
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}
Tried adding curl option as suggested Content-Type header [application/x-www-form-urlencoded] is not supported on Elasticsearch by
curl -XPUT "localhost:9200/_snapshot/javacafe" -H 'Content-Type: application/json' -d "{
"type":"fs",
"settings"{"location":"C:\\Users\\olulo\\Downloads\\book_backup\\search_example\\test", "compress":true}
}"
which outputs similar error with added statement at the end:
{"error":"Content-Type header [application/x-www-form-urlencoded] is not supported","status":406}curl: (6) Could not resolve host: application
SOLVED : for windows you need to use backslash infront of double quotation mark inside {}:
curl -XPUT "localhost:9200/_snapshot/javacafe" -H "Content-Type: application/json" -d "{
\"type\":\"fs\",
\"settings\"{\"location\":"C:\\Users\\olulo\\Downloads\\book_backup\\search_example\\test", \"compress\":true}
}"
From my understanding windows use \ to consider " as it is. If so why not add backslash to all curl commands as well?
Try this:
curl -XPUT "localhost:9200/_snapshot/javacafe" -H 'Content-Type: application/json' -d '{
"type":"fs",
"settings" : {
"location":"C:\\Users\\olulo\\Downloads\\book_backup\\search_example\\test",
"compress":true
}
}'

How to execute CURL post command in bash?

I am trying to execute curl post command through a bash script and I am facing lot of issues.
Here is the bash code I have:
#!/bin/bash
url='http://slc760.us.oracle.com:10601/crmCommonApi/resources/latest'
Content='Content-Type:application/vnd.oracle.adf.batch+json'
user="sales_representative"
payload='{ "parts": [{"id": "part1","path": "/latest/__ORACO__Inventory_c","operation": "create","payload": {"__ORACO__Product_Id2_c":204,"__ORACO__Facing_c":"20","__ORACO__Product_Id1_c":204,"__ORACO__Product_c": "Ghirardelli White Choco","__ORACO__ShelfStock_c":"10","__ORACO__Location_c" : "Aisle 2","Organization_Id___ORACO__Account_Inventory":"300100051199355"}},{"id": "part1","path": "/latest/__ORACO__Inventory_c","operation": "create","payload": {"__ORACO__Product_Id2_c":204,"__ORACO__Facing_c":"3","__ORACO__Product_Id1_c":204,"__ORACO__Product_c": "Ghirardelli White Chocolcate","__ORACO__ShelfStock_c":"4","__ORACO__Location_c" : "Aisle 2","Organization_Id___ORACO__Account_Inventory":"300100051199355"}}]}'
curl -X POST -H "Content-Type:application/vnd.oracle.adf.batch+json" \
--data $payload \
$url \
--user $user
When run throws bunch of errors:
curl: (6) Could not resolve host: "parts"
curl: (3) [globbing] bad range specification in column 2
curl: (6) Could not resolve host: "part1","path"
curl: (6) Could not resolve host: "
curl: (6) Could not resolve host: "create","payload"
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: "Ghirardelli
curl: (6) Could not resolve host: White
curl: (6) Could not resolve host: Choco","__ORACO__ShelfStock_c"
curl: (7) Failed to connect to port 80: Connection refused
curl: (6) Could not resolve host: "Aisle
curl: (3) [globbing] unmatched close brace/bracket in column 66
curl: (6) Could not resolve host: "part1","path"
curl: (6) Could not resolve host: "
curl: (6) Could not resolve host: "create","payload"
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Could not resolve host: "Ghirardelli
curl: (6) Could not resolve host: White
curl: (6) Could not resolve host: Chocolcate","__ORACO__ShelfStock_c"
curl: (7) Failed to connect to port 80: Connection refused
curl: (6) Could not resolve host: "Aisle
curl: (3) [globbing] unmatched close brace/bracket in column 66
org.codehaus.jackson.JsonParseException: Unexpected end-of-input: expected close marker for OBJECT (from [Source: weblogic.servlet.internal.ServletInputStreamImpl#10514b51; line: 1, column: 0])
When executed seperated through command-line the command seems to work but same when I try to execute it in CURL throws the above error.I know I am missing with relative to the quotes/syntax.
Please try to change following line:
--data $payload
to
--data '$payload'
Try putting double quotes on your payload:
curl -X POST -H "Content-Type:application/vnd.oracle.adf.batch+json" \
--data "$payload" \
$url \
--user $user
That should work.

Resources