Author Topic: Lending Club API questions.  (Read 4938 times)

ernst20020530

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Lending Club API questions.
« on: April 23, 2015, 05:00:57 PM »
I have really confused about the new API. I am new guy for python, then I tried following


 req = urllib2.Request('https://api.lendingclub.com/api/investor/v1/accounts/111111/summary')  #111111 is my account ID
    try: response = urllib2.urlopen(req)
    except urllib2.URLError as e:
        print e.reason

But the code always failed with error code  "Unauthorized ".

what's wrong with the code.

Fred93

  • Hero Member
  • *****
  • Posts: 2245
    • View Profile
Re: Lending Club API questions.
« Reply #1 on: April 23, 2015, 05:30:30 PM »
You need an authentication header, as described here...

https://www.lendingclub.com/developers/authentication.action

kbenson99

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Lending Club API questions.
« Reply #2 on: April 23, 2015, 07:01:48 PM »
Since you are using python, I'd suggest using the "requests" module; install using "pip install requests".

Use a requests.Session instance, add the authorization header {''Authorization': 'your api key'} to the session header and then call the get method on the session instance with the url value.

ernst20020530

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Lending Club API questions.
« Reply #3 on: April 23, 2015, 09:22:00 PM »
You need an authentication header, as described here...

https://www.lendingclub.com/developers/authentication.action

I have got that, but I have no idea how to use it. Lending club does not have any description to use it.
Do you know how to use it?


thanks

ernst20020530

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Lending Club API questions.
« Reply #4 on: April 23, 2015, 09:23:25 PM »
Since you are using python, I'd suggest using the "requests" module; install using "pip install requests".

Use a requests.Session instance, add the authorization header {''Authorization': 'your api key'} to the session header and then call the get method on the session instance with the url value.


Thank you for your suggestion. I will try it.

Booleans

  • Jr. Member
  • **
  • Posts: 74
    • View Profile
    • Email
Re: Lending Club API questions.
« Reply #5 on: April 24, 2015, 09:07:41 AM »
My C# code looks something like this.

Code: [Select]
var httpWebRequest = (HttpWebRequest)WebRequest.Create(postURL);
httpWebRequest.Headers.Add("Authorization:cPSkWjTkYkUzMgBFX8uY=");
httpWebRequest.ContentType = "application/json; charset=utf-8";
httpWebRequest.Method = "POST"; 

As others have mentioned, you need an authorization header.

ernst20020530

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Lending Club API questions.
« Reply #6 on: April 24, 2015, 09:26:22 AM »
s = requests.Session()
s.headers.update({'Authorization':'zCdTrv+LoQ5w2J2Z5Y5BYRo22eM='})
r = s.get('https://api.lendingclub.com/api/investor/v1/accounts/910322/summary',auth=('heimlich22004@gmail.com','huahua1QA2WS3ED'))
    print(r.status_code)

I tried this, but the error code is 401. I cannot figure out the reason.
« Last Edit: April 24, 2015, 10:15:34 AM by ernst20020530 »

kbenson99

  • Full Member
  • ***
  • Posts: 111
    • View Profile
    • Email
Re: Lending Club API questions.
« Reply #7 on: April 24, 2015, 10:32:48 AM »
With the authorization header added to the request Session instance, you do not need the "auth" parameter to be passed to the session instance's get method.  I "think", not sure, if you pass the auth parameter, it overrides the authorization header.

For your session instance, with no auth param, s.get(url) should work.  With the response instance from the session get call, the json() method will return your result.   :)

jheizer

  • Sr. Member
  • ****
  • Posts: 483
    • View Profile
    • LC Tools
Re: Lending Club API questions.
« Reply #8 on: April 24, 2015, 10:53:33 AM »
I'd get a new auth code since you just gave everyone the code and your account number.
Replacement to P2P Quant's Percentile Tool http://lc.geekminute.com