Prathamesh Sarang
Prathamesh Sarang

Reputation: 118

Accessing Lending Club Loan listing through their API

I'm trying to get the loan listing from Lending Club through their official API provided here: https://www.lendingclub.com/developers/listed-loans.action

I'm using python 'requests' module to make the call, below is the code that I tried:

    import requests
    header = {'Authorization' : 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Content-Type': 'application/json', 'Accept': 'application/json', "X-LC-LISTING-VERSION":"1.1"}
    resp = requests.get("https://api.lendingclub.com/api/investor/v1/loans/listing", headers= header, params = {'showAll':'true'})

Getting a response:

    resp.status_code
    401

I tried out the solution here through R httr package as mentioned in the stackoverflow question: Lending Club API with R , but getting the same 401 Unauthorized response.

Also did a quick cURL to check whether I was doing something wrong.

    curl -v -i --header "Authorization:xxxxxxxxxxxxxxxxxxxxxxxxxxxx" --header "Accept:application/json" --header "Content-Type:application/json" --header "X-LC-LISTING-VERSION:1.1" -d "{"query": {"showAll": "true"}}" -XGET https://api.lendingclub.com/api/investor/v1/loans/listing

Below is the dump that I get:

    *   Trying 64.48.1.18...
    * Connected to api.lendingclub.com (64.48.1.18) port 443 (#0)
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 1/3)
    * schannel: checking server certificate revocation
    * schannel: sending initial handshake data: sending 200 bytes...
    * schannel: sent initial handshake data: sent 200 bytes
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: failed to receive handshake, need more data
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: encrypted data buffer: offset 4096 length 4096
    * schannel: encrypted data length: 4006
    * schannel: encrypted data buffer: offset 4006 length 4096
    * schannel: received incomplete message, need more data
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: encrypted data buffer: offset 5030 length 5030
    * schannel: encrypted data length: 247
    * schannel: encrypted data buffer: offset 247 length 5030
    * schannel: received incomplete message, need more data
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: encrypted data buffer: offset 541 length 5030
    * schannel: sending next handshake data: sending 190 bytes...
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: encrypted data buffer: offset 6 length 5030
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 2/3)
    * schannel: encrypted data buffer: offset 45 length 5030
    * schannel: SSL/TLS handshake complete
    * schannel: SSL/TLS connection with api.lendingclub.com port 443 (step 3/3)
    * schannel: incremented credential handle refcount = 1
    * schannel: stored credential handle in session cache
    > GET /api/investor/v1/loans/listing HTTP/1.1
    > Host: api.lendingclub.com
    > User-Agent: curl/7.45.0
    > Authorization:xxxxxxxxxxxxxxxxxxxxxxxxxxxx
    > Accept:application/json
    > Content-Type:application/json
    > X-LC-LISTING-VERSION:1.1
    > Content-Length: 24
    >
    * upload completely sent off: 24 out of 24 bytes
    * schannel: client wants to read 16384 bytes
    * schannel: encdata_buffer resized 17408
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: encrypted data got 141
    * schannel: encrypted data buffer: offset 141 length 17408
    * schannel: decrypted data length: 112
    * schannel: decrypted data added: 112
    * schannel: decrypted data cached: offset 112 length 16384
    * schannel: encrypted data buffer: offset 0 length 17408
    * schannel: decrypted data buffer: offset 112 length 16384
    * schannel: schannel_recv cleanup
    * schannel: decrypted data returned 112
    * schannel: decrypted data buffer: offset 0 length 16384
    < HTTP/1.1 401 Unauthorized
    HTTP/1.1 401 Unauthorized
    < Server: Apache-Coyote/1.1
    Server: Apache-Coyote/1.1
    < Content-Length: 0
    Content-Length: 0
    < Date: Thu, 17 Nov 2016 06:38:15 GMT
    Date: Thu, 17 Nov 2016 06:38:15 GMT
    <
    * Connection #0 to host api.lendingclub.com left intact

Seems like there's something that I'm missing out in the API Call or that something is not documented properly in Lending Club API.

Would be great if I could get pointers on how to go about resolving this.

Thanks!

EDIT:

I don't know what happened, but I logged in the Lending Club account --> Refreshed the authentication key and did the API Call and it started working. Quite weird way to get a resolution on this though.

Upvotes: 3

Views: 1777

Answers (1)

Prathamesh Sarang
Prathamesh Sarang

Reputation: 118

Just in case if anyone wants to try out, we can do it using the below:

  1. Using httr in R

    library(httr) result <- GET("https://api.lendingclub.com/api/investor/v1/loans/listing", add_headers(.headers = c("Content-Type"="application/json","Accept"="application/json", "Authorization"="Authentication key"))) Output <- content(result)

  2. Using requests, similar as in the question.

  3. Using curl to check, same cURL implementation as in the question.

But before doing all this, make sure you are logged in through your browser to your Lending Club account.

Upvotes: 1

Related Questions