Reputation: 523
I have been able to make API requests with other endpoints just fine, but the endpoint for making buys does not seem to work at all. It seems like it is a server error on their end, but I figured I would ask on here just in case I am making a careless mistake.
I have written multiple versions of my function but this is one:
function getLCInfo($endpoint, $getData = false) {
$api_url = "https://api.lendingclub.com/api/investor/";
$verison = "v1";
$account_id = "12345678";
$ContentType = "application/json";
$url = "$api_url$verison/accounts/$account_id/$endpoint/";
if($getData) {
$url .= "?" . urldecode(http_build_query($getData));
echo $url;
}
$key = "aaaaaaaaaaaaaaaa99999999";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('Authorization: ' . $key,
'Content-type: ' . $ContentType ,
'Accept: ' . $ContentType,
'X-LC-Application-Key: ' . $account_id));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec( $ch );
curl_close( $ch );
return json_decode($output);
}
This is their documentation:
This subresource provides a summary of the investor's account.
Operation: GET
URL: https://api.lendingclub.com/api/investor/v1/accounts/[investor id]/trades/
URL Parameters: Investor Id - This can be obtained from the Account Summary section on Lending Club website when a user is logged in.
Query Parameters: None.
Supported Formats: JSON request for buy notes
Request/ Response Headers: NAME TYPE NULLABLE DESCRIPTION Aid String No The ID of the investor upon whose behalf the partner is requesting to buy one or more notes for notes Array No An array of one or more notes loanId String No Numeric identifier of the loan whose note requested for purchase orderId String No Numeric identifier of the order for the note noteId String No Numeric identifier of the note bidPrice String No Positive numeric value in dollars ($) and cents representing the buy price desired for the note Sample request: JSON —
{ "aid":70654,"notes": [ {"loanId":3349795,"orderId":19979983,"noteId":5730626,"bidPrice":9.79}, {"loanId":707414,"orderId":1369944,"noteId":4154191,"bidPrice":23.84}, {"loanId":1076461,"orderId":2133757,"noteId":7827843,"bidPrice":34.45}
] }
Sample Response—
{ buyNoteConfirmations: [ 3 ] : { loanId: 3349795 noteId: 5730626 bidPrice: 9.79 outstandingAccruedInterest: null outstandingPrincipal: null yieldToMaturity: null executionStatus: [ 1 ] : "
NOTE_DOES_NOT_EXIST " } 1: { loanId: 707414 noteId: 4154191 bidPrice: 23.84 outstandingAccruedInterest: null outstandingPrincipal: null yieldToMaturity: null executionStatus: [ 1 ] : " NOTE_NOT_AVAILABLE " } 2: { loanId: 1076461 noteId: 7827843 bidPrice: 34.45 outstandingAccruedInterest: null outstandingPrincipal: null yieldToMaturity: null executionStatus: [ 1 ] 0: " SUCCESS_PENDING_SETTLEMENT " } }
This is what happens when I test in Postman POSTing data:
POST /api/investor/v1/accounts/87308218/trades/ HTTP/1.1
Host: api.lendingclub.com
Authorization: aaaaaaaaaaa111111
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 68d283a6-08f0-6789-3542-3a1baa554ce7
{
"aid":70654,"notes":
[
{"loanId":3349795,"orderId":19979983,"noteId":5730626,"bidPrice":9.79},
{"loanId":707414,"orderId":1369944,"noteId":4154191,"bidPrice":23.84},
{"loanId":1076461,"orderId":2133757,"noteId":7827843,"bidPrice":34.45}
]
}
and I tried to use GET like their documentation says.
GET /api/investor/v1/accounts/87308218/trades/?aid=12345678&notes[0][loanId]=17213188&notes[0][orderId]=25300948&notes[0][noteId]=48382917&notes[0][bidPrice]=6.77&notes[1][loanId]=17213188&notes[1][orderId]=25300943&notes[1][noteId]=48382538&notes[1][bidPrice]=6.77 HTTP/1.1
Host: api.lendingclub.com
Authorization: aaaaaaaaaaa111111
Cache-Control: no-cache
Postman-Token: b34cb60b-91ea-c82e-349f-d395b01b1dc0
Thanks in advance!
Upvotes: 0
Views: 1537
Reputation: 523
I figured it out! Turns out LendingClub had incorrect info on their documentation (super frustrating!).
My solution was to change the Operation to POST instead of GET and the endpoint was incorrect.
They have URL: https://api.lendingclub.com/api/investor/v1/accounts/[investor id]/trades/, it should be URL: https://api.lendingclub.com/api/investor/v1/accounts//trades/buy (which actually makes much more sense since their API's sell endpoint ends with /trades/sell.
I hope some developer at LendingClub reads this and edits the API documentation, I'm sure I'm not alone with this!
Upvotes: 0