using the query = list in the GET() function to acquire API

The following code works for me

My_Data <- GET(url = "https://api.census.gov/data/timeseries/intltrade/exports/hs?get=CTY_CODE,CTY_NAME,ALL_VAL_MO&key=my_autho_key&YEAR=2017&MONTH=04")

I was wondering if there is anyway to acquire the above data by using the query = list in the GET() function. Any help or guidance would be appreciated.

Thanks, M

HI @mustafghan,
You can do this:

library(httr)
GET("http://google.com/", path = "search", query = list(q = "green eggs and ham"))

So, I assume that you could do something like this:

GET("https://api.census.gov/data/timeseries/intltrade/exports/hs?get=CTY_CODE,CTY_NAME,ALL_VAL_MO", 
      query = list(key = "my_autho_key",
                   YEAR = "2017",
                   MONTH = "04"))

But, of course, I can't test it.
HTH

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

I had tried something similar which didn't work. But thanks.