0

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")
EboMike
  • 76,846
  • 14
  • 164
  • 167
NoVice
  • 43
  • 5
  • im trying to get access to the "Summary" but they are asking for a - I have tried using the Account Number on the control panel but it still fails... any idea where to find the ? – Trevor Daniel Apr 27 '15 at 06:50

2 Answers2

1

I wrote a package to work with the Lending Club API which should make this problem easier for you. Try this:

install.packages("LendingClub")
library(LendingClub)
LC_CRED<- MakeCredential(investorID, APIkey)
ListedLoans(showAll=TRUE)$content

You can see a few more examples by reading the vignette:

vignette("LendingClub")
kuhnrl30
  • 21
  • 4
0

Getting SSL stuff properly configured with RCurl can be kind of messy. I recommend httr.

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

library(httr)
rr <- GET("https://api.lendingclub.com/api/investor/v1/loans/listing", 
    add_headers(Authorization="Vkqakl1lAygRyXRwlKCOyHWG4DE"))

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

content(rr)
MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Thanks it works I have another question about the query. I edited my original post with the question. Please see above. – NoVice Feb 28 '15 at 06:04
  • You really shouldn't edit existing posts with "new" questions. If you have a new problem after a question has been answered, you should start a new question. There was an example of `query=` on the `?GET` help page. Did you check that? You typically pass a list object to query, ie `query=list(showall="TRUE")` – MrFlick Feb 28 '15 at 06:26