Jai
Jai

Reputation: 365

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.

Upvotes: 0

Views: 2985

Answers (2)

Tomàs
Tomàs

Reputation: 26

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.

Upvotes: 1

Murad Tagirov
Murad Tagirov

Reputation: 816

Please try to change following line:

--data $payload

to

--data '$payload'

Upvotes: 1

Related Questions