Author Topic: LendingClub API OrderSubmitOrders action  (Read 5147 times)

Fudgenut

  • Newbie
  • *
  • Posts: 9
    • View Profile
LendingClub API OrderSubmitOrders action
« on: July 21, 2013, 04:19:23 am »
I am attempting to interface with the LendingClub API using SOAP in PHP. I've generated some classes using wsdl2php. The wsdl file can be found here: https://www.lendingclub.com/ws/1.3?wsdl

I've successfully executed 4 of the 5 API methods, but the submit order method results in the following error:

Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: Violation of encoding rules

Code exert (integer IDs replaced by XXXXXX:
Code: [Select]
$order = new Order();
$order->loanId = XXXXXX;
$order->requestedAmount = 25.00;
$order->portfolioId = XXXXXX;

$order_instruct = new OrderInstruct();
$order_instruct->aid = XXXXXX;
$order_instruct->orders = $order;

$submit_order = new OrderSubmitOrders();
$submit_order->instructs = $order_instruct;
$submit_order_response = $lendingClub->OrderSubmitOrders($submit_order);
var_dump($submit_order_response);
Anyone else get this action to work?
Thanks in advance.

mo

  • Full Member
  • ***
  • Posts: 126
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #1 on: July 21, 2013, 10:57:14 am »
I don't know PHP so i can't be sure but, based on the WSDL both the orders value of the OrderInstruct object and the argument that gets passed to the OrderSubmitOrders() call should be arrays or lists depending on the terminology used in your language of choice.  It looks like you are using single object for both instead of an array.

You may want to try replacing lines 7 and 9 respectively as follows...

$order_instruct->orders = array($order);

and

$submit_order->instructs = array($order_instruct);
« Last Edit: July 21, 2013, 11:12:10 am by mo »

Fudgenut

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #2 on: July 21, 2013, 11:32:58 am »
Hi mo,
Thanks for the reply.

Yes, that is what made sense to me as well, and that is actually how I had it initially.  Unfortunately, I got the same error wrapping the instruct and the orders in arrays.

mo

  • Full Member
  • ***
  • Posts: 126
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #3 on: July 21, 2013, 11:53:48 am »
Try specifying the requested Amount as an integer instead of a float.  If that doesn't work figure out how to turn on debugging for you SOAP library and look at the XML being sent to see if you can see anything unexpected.

Another thought, why are you creating a "OrderSubmitOrders" object?  doesn't OrderSubmitOrders take an array of OrderInstructs directly?  ie...

$submit_order_response = $lendingClub->OrderSubmitOrders(array($order_instruct));
« Last Edit: July 21, 2013, 11:58:15 am by mo »

Fudgenut

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #4 on: July 21, 2013, 04:19:57 pm »
Hi Mo,
Thanks again for your continued help with this issue.

I tried using an integer for requestedAmount, no luck, same error.

I also tried an array of instructs as the parameter directly into the OrderSubmitOrders() function, but received an error about incorrect type for argument 1.
Here is the function declaration generated by wsdl2php, so I believe that it is correct that I am using an OrderSubmitOrders object as the parameter:
Code: [Select]
public function OrderSubmitOrders(OrderSubmitOrders $parameters) {
        return $this->__soapCall('OrderSubmitOrders', array($parameters),       array(
            'uri' => 'http://ws.lendingclub.com/',
            'soapaction' => ''
           )
      );
  }

Also for reference, here is a code exert for a service call that was successful:
Code: [Select]
$available_notes = $lendingClub->LoanBrowseLoans(new LoanBrowseLoans())->result;
echo $available_notes->asOfDate.' '.date('r').'<br />';
$i = 0;
foreach ($available_notes->loans as $listing)
{
echo $listing->listD.' '.date('r', strtotime($listing->listD)).'<br />';
$i++;
}
echo $i;


Going back to the OrderSubmitOrders method, I tried commenting out the assignment of requestedAmount.  I received the error I would expect:
Code: [Select]
Uncaught SoapFault exception: [S:Server] Invalid value for parameter REQUESTED_AMOUNT, Cannot be null.: <null>
I am working on debugging SOAP to produce the outputted XML.

Fudgenut

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #5 on: July 21, 2013, 04:27:46 pm »
I caught the error and made a call to the PHP function:
SoapClient::__getLastRequestHeaders(), but that produced nothing.

I suspect the error occured before XML request was constructed.

Another thing I tried was using SOAPUI to send the request.  This was actually successful, and the XML request used here is:

Code: [Select]
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.lendingclub.com/">
   <soapenv:Header/>
   <soapenv:Body>
      <ws:OrderSubmitOrders>
         <!--Zero or more repetitions:-->
         <instructs aid="#######">
            <!--Optional:-->
            <!--Zero or more repetitions:-->
            <orders loanId="#######" requestedAmount="25.00" portfolioId="######"/>
</instructs>
      </ws:OrderSubmitOrders>
   </soapenv:Body>
</soapenv:Envelope>

Fudgenut

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #6 on: July 21, 2013, 04:36:31 pm »
I was missing the track=TRUE parameter when initializing the SoapClient class.

Here is what the request looks like:


__getLastRequestHeaders:
Code: [Select]
POST /ws/1.3 HTTP/1.1
Host: www.lendingclub.com
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.4.7
Content-Type: text/xml; charset=utf-8
SOAPAction: "OrderSubmitOrders"
Content-Length: 339
Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

__getLastRequest:
Code: [Select]
<?xml version="1.0" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.lendingclub.com/">
  <SOAP-ENV:Body>
    <ns1:OrderSubmitOrders>
      <instructs aid="XXXXXXX">
        <orders loanId="XXXXXXX" portfolioId="XXXXXX" requestedAmount="25"/>
      </instructs>
    </ns1:OrderSubmitOrders>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
« Last Edit: July 21, 2013, 04:39:25 pm by Fudgenut »

rawraw

  • Hero Member
  • *****
  • Posts: 1777
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #7 on: July 21, 2013, 04:44:39 pm »
Now I know how people feel when I start talking to them about financial modeling. . .

Fudgenut

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #8 on: July 21, 2013, 04:54:38 pm »
Success: ORDER_FULFILLED!

I used the generated lastRequest XML in SOAPUI and was able to see an exception that actually made sense: NOT_INFUNDING_LOAN

After using a loan ID that was actually in funding, it worked.

Thanks for your help walking through this issue mo!

mo

  • Full Member
  • ***
  • Posts: 126
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #9 on: July 22, 2013, 08:10:27 pm »
Cool.

MTaylor

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #10 on: July 23, 2013, 05:29:09 pm »
Uh, do we need to understand all this to eventually use the Lendingclub API? :P

Fudgenut

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #11 on: July 23, 2013, 05:30:31 pm »
Uh, do we need to understand all this to eventually use the Lendingclub API? :P

I'm afraid so....

brycemason

  • Hero Member
  • *****
  • Posts: 704
    • View Profile
    • P2P-Picks.com
    • Email
Re: LendingClub API OrderSubmitOrders action
« Reply #12 on: July 24, 2013, 10:44:24 am »
No, LC will make something more friendly for users of its site. And there are third-party sites to give you access to the API, but you have to pay.

MTaylor

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #13 on: July 24, 2013, 05:28:25 pm »
That's a relief.

DonDaVinci

  • Jr. Member
  • **
  • Posts: 60
    • View Profile
Re: LendingClub API OrderSubmitOrders action
« Reply #14 on: July 24, 2013, 05:30:52 pm »
No, LC will make something more friendly for users of its site. And there are third-party sites to give you access to the API, but you have to pay.

Do you have a link to those sites?