title: Using RCurl postForm to gather JSON data
body: <p>I am trying to extract time series data from the <a href="http://www.bls.gov/developers/" rel="nofollow noreferrer">BLS API</a> using <code>RCurl</code>. </p>
  
  <p>The BLS supplies the following sample code for command line extraction: </p>
  
  <pre><code>curl -i -X POST -H 'Content-Type: application/json' 
       -d '{"seriesid":["LEU0254555900", "APU0000701111"],
          "startyear":"2002", "endyear":"2012"}' 
          http://api.bls.gov/publicAPI/v1/timeseries/data/ 
  </code></pre>
  
  <p>I have also confirmed that the specified files (i.e. series ids) are both present as the following both yield a JSON formatted object: </p>
  
  <pre><code>require(RCurl)
  bls.content_test1 &lt;- getURLContent("http://api.bls.gov/publicAPI/v1/timeseries/data/LEU0254555900")
  bls.content_test2 &lt;- getURLContent("http://api.bls.gov/publicAPI/v1/timeseries/data/APU0000701111")
  </code></pre>
  
  <p>Based on a variety of posts with the <code>RCurl</code> tag (and this <a href="https://stackoverflow.com/questions/24387119/how-to-postform-with-header">post</a> in particular), I have ported the command line script to the following chunk of code: </p>
  
  <pre><code>require(RJSONIO)
  
  jsonbody &lt;- toJSON(list("seriesid"=paste('"["CFU0000008000"', '[LEU0254555900"]"')
                          ,"startyear"="2012"
                          ,"endyear"="2013"))
  
  httpheader &lt;- c(Accept="application/json; charset=UTF-8",
                  "Content-Type"="application/json")
  
  bls.content &lt;- postForm("http://api.bls.gov/publicAPI/v1/timeseries/data/"
                          ,.opts=list(httpheader=httpheader
                                      ,postfields=jsonbody))
  </code></pre>
  
  <p>Which yields: </p>
  
  <pre><code>[1] "{\"status\":\"REQUEST_FAILED\",\"responseTime\":0,\"message\":[\"Your request has failed, please check your input parameters and try your request again.\"],\"Results\":null}"
  attr(,"Content-Type")
                                charset 
  "application/json"            "UTF-8"
  </code></pre>
  
  <p>Does this appear to be a problem with my implementation of <code>RCurl</code> or does this appear to be a problem with the BLS API?</p>