How correctly use request header with API data requests? How correctly use request header with API data requests? r r

How correctly use request header with API data requests?


You are not specifying the header correctly. add_headers(...) requires a named list.

library(httr)    # for GET(...)library(rjson)   # for fromJSON(...)query <- "https://api.appannie.com/v1/accounts/1000/sales?break_down=application+dat&start_date=2012-01-01&end_date=2012-02-01&currency=USD&countries=US&page_index=1"getdata<-GET(url=query, add_headers(Authorization="bearer <your api key>"))fromJSON(content(getdata,type="text"))# $code# [1] 403# # $error# [1] "Invalid connection account"

This "works" in the sense that I don't get the 401 error. In my case the account 1000 does not exist.

Regarding the http/https issue from the comment, http is despreciated and will no longer be accepted as of 2014-04-01, so you might as well start using https.