0

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.

7
  • 2
    The variable $id is not being expanded because it is inside single quotes. Commented Mar 13, 2015 at 15:44
  • I just updated it and I still have the same issue. Commented Mar 13, 2015 at 15:55
  • Your 2nd edit suggests you're doing -I instead of -i. Commented Mar 13, 2015 at 16:09
  • I copied and pasted the code snippet into a new file and it worked. If I want to read up on why where would you suggest I go? Commented Mar 13, 2015 at 16:28
  • As I said above, the warning from curl suggested that you were using -I (make a HEAD request) rather than -i (include response headers). An HTTP request cannot be both a HEAD request and a POST request. Commented Mar 13, 2015 at 16:30

2 Answers 2

1

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/
Sign up to request clarification or add additional context in comments.

Comments

0

Your -d argument is surrounded by ' single quotes which dont allow variable interpolation. Use double quotes "args $id "

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.