Php – Very basic question about submitting data to API using SOAP & PHP

apiPHPsoap

Before I ask my question I want to thank everyone on stack overflow. I'm really amazed at how helpful everyone is and how much I've learned just in the past year or so from asking questions when I'm confused.

I'm trying to use the recordSale function on this API for someone my work does business with, it's a way to record sales (hence the name):

url: https://secure.directtrack.com/api/soap.php#
wsdl: https://secure.directtrack.com/api/soap.php?wsdl

Name: recordSale
Binding: DirectTrackWebServicesBinding
Endpoint: http://secure.directtrack.com/api/soap.php
SoapAction: http://secure.directtrack.com/api/soap.php/recordSale
Style: rpc
Input:
use: encoded
namespace: http://soapinterop.org//
encodingStyle: http://schemas.xmlsoap.org/soap/encoding/
message: recordSaleRequest
parts:
client: xsd:string
password: xsd:string
order_id: xsd:string
sale_amount: xsd:double
campaign_id: xsd:int

Output:
use: encoded
namespace: http://soapinterop.org//
encodingStyle: http://schemas.xmlsoap.org/soap/encoding/
message: recordSaleResponse
parts:
return: xsd:int

Namespace: http://soapinterop.org//
Transport: http://schemas.xmlsoap.org/soap/http

So I am trying to set up the php for this and I wrote:

$client2 = new SoapClient("http://secure.directtrack.com/api/soap.php?wsdl", array('trace'=> true));
$results2 = $client2->recordSale(array(
                                       "client" => 'my work's client #', 
                                       "password" => "password",
                                       "order_id"  => "2",
                                       "sale_amount"  => "1000",
                                       "campaign_id"  => "16",
                                       "affiliate_code"  => "CD35",
                                       "date"  => "2009-11-17",
                                       "sale_status"  => "",
                                       "optional_info"  => "fsq2",
                                       "misc"  => "9",
                                       "record_lead"  => "1"));
echo "<pre>";
        print_r($results2);
echo "</pre>";

And the return value that gets printed is the number "1". The thing is that this "1" doesn't change if I change the password or leave out required fields. Am I going about this in entirely the wrong way?

Best Answer

It looks like you have a single quote in there

'my work's client #'

...which should be:

"my work's client #"

Secondly, you should probably use a debugging tool (I use eclipse php for debugging but there's several out there including netbeans). You will see more information with a debugger.

Lastly, you can see the actual XML of the request and response via:

$lastRequest = $client2->__getLastRequest();
$lastResponse = $client2->__getLastResponse();

...since you have trace turned on.

Related Topic