购买二级市场票据的LendingClub.com API 500错误

时间:2016-07-26 06:48:05

标签: php json rest lending-club-api

我已经能够很好地与其他端点发出API请求,但是用于购买的端点似乎根本不起作用。看起来这是他们最终的服务器错误,但我想我会在这里问,以防万一我犯了一个粗心的错误。

我已经编写了我的函数的多个版本,但这是一个:

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);
}

这是他们的documentation

  

此子资源提供投资者账户的摘要。

     

操作:GET

     

网址:https://api.lendingclub.com/api/investor/v1/accounts/[investor   ID] /交易/

     

网址参数:投资者ID - 可以从帐户中获取   用户登录时Lending Club网站的摘要部分。

     

查询参数:无。

     

支持的格式:购买笔记的JSON请求

     

请求/响应标头:名称类型无法使用说明   Aid String No代表合作伙伴的投资者的ID   请求为笔记购买一个或多个笔记数组否一个数组   或更多说明loanId String否贷款的数字标识符   请求购买订单的备注字符串否数字标识符   note noteId String No注释的数字标识符   bidPrice String否美元($)和美分的正数值   表示笔记样本请求所需的购买价格: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}
     

]       }

     

示例回复 -

{     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“         }}

当我在Postman中测试时会发生这种情况 发布数据:

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}
    ]
} 

我尝试使用GET,就像他们的文档说的那样。

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

提前致谢!

1 个答案:

答案 0 :(得分:0)

我明白了!事实证明LendingClub的文档信息不正确(超级令人沮丧!)。

我的解决方案是将操作更改为POST而不是GET,并且端点不正确。

他们有网址:https://api.lendingclub.com/api/investor/v1/accounts/[investor ID] /交易/,应该是网址:https://api.lendingclub.com/api/investor/v1/accounts/ /交易/购买 (这实际上更有意义,因为他们的API销售终点以/交易/卖出结束。

我希望LendingClub的一些开发人员阅读并编辑API文档,我确信我并不孤单!