I am trying to pull data with Lending Club's API with R: https://www.lendingclub.com/developers/lc-api.action
but I am unsure how to do it. This is what I have now but I keep getting an unauthorized error. I called Lending Club for API support because it did not specify where to put the API Key, unfortunately they do not have any support for their API. They said all the information is on the website.
I have an account with Lending Club and an API Key.
This is my code, I added an "&api-key=" because I have used something similar for a different API.
library(rjson)
library(RCurl)
library(jsonlite)
apikey <- "pP0tK321JWldXCMYHJ8VmIhMHuM="
url <- "https://api.lendingclub.com/api/investor/v1/loans/listing"
url <- paste0(url,"&api-key=",apikey)
getURL(url)
fromJSON(url)
output:
> getURL(url)
Error in function (type, msg, asError = TRUE) :
SSL certificate problem: self signed certificate in certificate chain
> fromJSON(url)
Error in download_raw(txt) : client error: (401) Unauthorized
If anyone has worked with Lending Club's API with R please give me some guidance. Thank you!
EDIT//
Thanks it works, I have another question regarding the "query" argument. I added a query "showall", but how do I add TRUE?
If you click the following link it will show the query options.
https://www.lendingclub.com/developers/listed-loans.action
rr <- GET("https://api.lendingclub.com/api/investor/v1/loans/listing",
add_headers(Authorization="key"), query = "showall")
Getting SSL stuff properly configured with
RCurl
can be kind of messy. I recommendhttr
.Rather than an API key, it looks like the service requires an authorization header. Follow the info on that page to generate one for your account.
Then, when you have the Authortization value, you can make your request like
Since I don't have an account, i'm not sure what the response will be, but you should be able to access it with
I wrote a package to work with the Lending Club API which should make this problem easier for you. Try this:
You can see a few more examples by reading the vignette: