d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Php Soap > Stamps.com
Add Reply New Topic New Poll
Member
Posts: 5,269
Joined: Oct 18 2006
Gold: 21,400.00
Jun 4 2015 11:45am
I am trying to learn the basics, but I cannot get a working example for a request. Here is what I have:

Request needed:
Code
POST /swsim/SwsimV42.asmx HTTP/1.1
Host: swsim.testing.stamps.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://stamps.com/xml/namespace/2015/01/swsim/swsimv42/AuthenticateUser"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<AuthenticateUser xmlns="http://stamps.com/xml/namespace/2015/01/swsim/swsimv42">
<Credentials>
<IntegrationID>guid</IntegrationID>
<Username>string</Username>
<Password>string</Password>
</Credentials>
</AuthenticateUser>
</soap:Body>
</soap:Envelope>


PHP Code:
Code
<?php
$wsdl = 'https://swsim.testing.stamps.com/swsim/swsimv42.asmx?WSDL';

$trace = true;
$exceptions = true;

$Credentials = array(
'IntegrationID' => 'my-int-id',
'Username' => 'username',
'Password' => 'password'
);
try
{
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->AuthenticateUser($Credentials);
}

catch (Exception $e)
{
echo "Error!";
echo $e -> getMessage ();
echo 'Last response: '. $client->__getLastResponse();
}

var_dump($response);
?>


Error:
Code
Error!SOAP-ERROR: Encoding: object has no 'Credentials' propertyLast response:
Notice: Undefined variable: response in C:\Stamps\TEST.php on line 26
NULL


This seems like it should be very simple to fix but I am inexperienced with PHP and SOAP. I am looking for the most simplistic answer. 300fg for corrected PHP code.
Member
Posts: 5,269
Joined: Oct 18 2006
Gold: 21,400.00
Jun 4 2015 12:44pm
Got it. I didn't realize I still needed to use the outer most level (AuthenticateUser) in the array when I was using the function AuthenticateUser.

Code

<?php
$wsdl = 'https://swsim.testing.stamps.com/swsim/swsimv42.asmx?WSDL';

$trace = true;
$exceptions = true;

$AuthenticateUser = array(
'Credentials' =>
array(
'IntegrationID' => 'my-int-id',
'Username' => 'username',
'Password' => 'password'
)
);

try
{
$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
$response = $client->AuthenticateUser($AuthenticateUser);
}
catch(Exception $e)
{
echo "Error!";
echo $e -> getMessage () . "\n";
echo 'Last response: '. $client->__getLastResponse();
}

var_dump($response);
?>
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll