Reputation: 3
I am working on a project using the BLS API.
Reference: http://www.bls.gov/developers/api_unix.htm
My current script follows:
declare id=""
echo -n "Enter id: "
read id
echo -n "enter startyear: "
read startyear
echo -n "enter endyear: "
read endyear
curl -i -X POST -H 'Content-Type: application/json' -d '{"seriesid": ["$id"], "startyear":'$startyear' , "endyear":'$endyear'}' http://api.bls.gov/publicAPI/v2/timeseries/data/
I have edited it and put in the ID by hand like on the reference page and that worked. I cannot seem to read the $id from input and insert it into the curl command. Any assistance with this is greatly appreciated thank you.
edit1:
I updated the code and changed the quotes for the {} for the -d option to double quotes and the same error persists.
edit2:
after updating the file with the code provided in the comments I receive a:
Warning: You can only select one HTTP request!
when I run it.
Upvotes: 0
Views: 52
Reputation: 7880
To clear up any confusion in my comment above, the following should work:
echo -n "Enter id: "
read id
echo -n "enter startyear: "
read startyear
echo -n "enter endyear: "
read endyear
curl -i \
-X POST \
-H 'Content-Type: application/json' \
-d "{\"seriesid\":[\"${id}\"],\"startyear\":\"${startyear}\",\"endyear\":\"${endyear}\"}" \
http://api.bls.gov/publicAPI/v2/timeseries/data/
Upvotes: 1
Reputation: 455
Your -d argument is surrounded by '
single quotes which dont allow variable interpolation. Use double quotes "args $id "
Upvotes: 0