title: R httr POST of JSON returns status 400
body: <p>I'm working on a few functions to get data from <a href="http://www.statistikbanken.dk/statbank5a/" rel="nofollow">StatBank</a> Denmark, and their <a href="http://www.dst.dk/da/Statistik/statistikbanken/api.aspx" rel="nofollow">API</a>. They have made a <a href="http://api.statbank.dk/console" rel="nofollow">console</a> to test JSON calls and I know the basic_request I parse to JSON in the function dst_get_data works, as I have tested it in the console.</p>
  
  <p>I get a "status 400" error and an error message that says that I should "supply object when posting". </p>
  
  <p>The code below should make reproducible example. It is the third function (dst_get_data) where I am stuck.</p>
  
  <pre><code>dst_meta &lt;- function(table, ..., lang = "en"){
    require(jsonlite)
    require(httr)
  
    dkstat_url &lt;- "http://api.statbank.dk/v1/tableinfo"
  
    params &lt;- list("lang" = lang,
                   "table" = table,
                   "format" = "JSON")
  
    meta &lt;- POST(url=dkstat_url, body=params, multipart=FALSE)
    meta &lt;- jsonlite::fromJSON(txt=content(meta, as="text"),simplifyDataFrame=TRUE)
    #meta &lt;- RJSONIO::fromJSON(content=content(meta),asText=TRUE, simplify=TRUE, simplifyWithNames=TRUE)
  
    return(meta)
  }
  
  dst_meta_parse &lt;- function(meta, lang){
  
    basics_names &lt;- c("id", "text", "description", 
                      "unit", "updated", "footnote")
  
    basics &lt;- meta[names(meta) %in% basics_names]
  
    variables &lt;- meta[["variables"]][,c("id", "text")]
  
    values &lt;- meta[["variables"]][,"values"]
    names(values) &lt;- variables$id
  
    if(lang == "en"){
      test &lt;- grepl(pattern="Tid", names(values))
      if(sum(test) &gt; 0){
        values$Tid$id &lt;- sub(pattern="Q", replacement="K", x=values$Tid$id)
      }
    }
  
    ## Create basic_request for the data_post file
    basic_request &lt;- vector(mode="list", length=length(variables$id))
    for(variable in 1:length(variables$id)){
  
      var_name &lt;- variables$id[variable]
  
      if(var_name == "Tid"){
        basic_request[[variable]] &lt;- list("code" = var_name,
                                         "values" = as.character(values[[var_name]]$id[length(values[[var_name]]$id)]))
      } else {
        basic_request[[variable]] &lt;- list("code" = var_name,
                                         "values" = as.character(values[[var_name]]$id[1]))
      }
    }
    return(list("basics" = basics, "variables" = variables, "values" = values, "basic_request" = basic_request))
  }
  
  dst_get_data &lt;- function(request, table,..., lang = "en", format = "CSV", value_presentation = "Default"){
    require(httr)
    require(jsonlite)
  
    dst_url &lt;- "http://api.statbank.dk/v1/data"
  
    final_request &lt;- list("table" = table,
                          "lang" = lang,
                          "format" = format,
                          "valuePresentation" = value_presentation,
                          "variables" = request)
  
    final_request &lt;- jsonlite::toJSON(x=final_request, .escapeEscapes=TRUE, asIs=TRUE)
    print(validate(final_request))
    data &lt;- POST(url=dst_url, body=final_request, multipart=FALSE)
  
    return(data)
  }
  
  test &lt;- dst_meta(table="folk1")
  
  test2 &lt;- dst_meta_parse(meta = test, lang = "en")
  
  test3 &lt;- dst_get_data(request = test2$basic_request, table = "folk1", format="JSON")
  #test3 &lt;- dst_get_data(request = test2$basic_request, table = "folk1", format="JSON")
  </code></pre>