Hi all. I’m new to using APIs in R, so please forgive me for this likely simple question; however, I’m pulling my hair out trying to get this to work.
I’m not going to post my API key here, but suffice it to say that it is saved in R and it’s called in the code. I keep receiving the same error.
url ← “https://api.ipums.org/extracts/?collection=nhgis&version=v1”
mybody ← '{
“datasets”: {
“2016_2020_ACS5a”: {
“data_tables”: [“B15003”],
“geog_levels”: [“county”]
}
},
“geographic_instances”: [“010”],
“data_format”: “csv_no_header”,
“description”: “test_b15003”
}’
mybody_json ← fromJSON(mybody, simplifyVector = FALSE)
result ← POST(url, add_headers(Authorization = my_key), body = mybody_json, encode = “json”, verbose())
res_df ← content(result, “parsed”, simplifyDataFrame = TRUE)
my_number ← res_df$number
my_number
The error is below.
→ POST /extracts/?collection=nhgis&version=v1 HTTP/1.1
→ Host: api.ipums.org
→ User-Agent: libcurl/7.64.1 r-curl/4.3.2 httr/1.4.4
→ Accept-Encoding: deflate, gzip
→ Accept: application/json, text/xml, application/xml, /
→ Content-Type: application/json
→ Authorization: 59cba10d8a5da536fc06b59d17125ffa0b114a2cb3f2f546cec95a68
→ Content-Length: 173
→{“datasets”:{“2016_2020_ACS5a”:{“data_tables”:[“B15003”],“geog_levels”:[“county”]}},“geographic_instances”:[“010”],“data_format”:“csv_no_header”,“description”:“test_b15003”}
← HTTP/1.1 500 Internal Server Error
← Content-Length: 0
← Content-Type: text/html; charset=UTF-8
← Date: Thu, 06 Oct 2022 22:39:31 GMT
← Server: nginx/1.18.0 + Phusion Passenger(R) 6.0.15
← Status: 500 Internal Server Error
← Vary: Origin
← X-Powered-By: Phusion Passenger(R) 6.0.15
← X-Ratelimit-Limit: -1
← X-Ratelimit-Remaining: 0
← X-Ratelimit-Reset: 0
← X-Request-Id: a28802ed-ab31-4cec-aa07-70d77b4f284f
← X-Runtime: 0.059476
←res_df ← content(result, “parsed”, simplifyDataFrame = TRUE)
my_number ← res_df$number
my_number
NULL