I'm using the Merchant Fulfillment portion of the Amazon Selling Partner API found at https://github.com/jlevers/selling-partner-api/
I have other portions working... namely orders coming down and reports going up. But I am using the same techniques and the Merchant Fulfillment API is not working. The response I get back indicates that it's not received the data I am sending it.
What am I doing wrong?
// North America Live
$NA = [
'url' => 'https://sellingpartnerapi-na.amazon.com',
'region' => 'us-east-1',
];
// North America Sandbox
// $NA = [
// 'url' => 'https://sandbox.sellingpartnerapi-na.amazon.com',
// 'region' => 'us-east-1',
// ];
$config = new SellingPartnerApi\Configuration([
"lwaClientId" => $lwaClientId,
"lwaClientSecret" => $lwaClientSecret,
"lwaRefreshToken" => $lwaRefreshToken,
"awsAccessKeyId" => $awsAccessKeyId,
"awsSecretAccessKey" => $awsSecretAccessKey,
"endpoint" => $NA // or another endpoint from lib/Endpoint.php
]);
$apiInstance = new SellingPartnerApi\Api\MerchantFulfillmentApi($config);
$body = new \SellingPartnerApi\Model\MerchantFulfillment\GetEligibleShipmentServicesRequest(
[
"shipment_request_details" =>
[
"amazon_order_id" => "XXX-XXXXXXXX-XXXXXXXX",
"item_list" =>
[
"order_item_id" => "XXXXXXXXXXXXXXX",
"quantity" => 1,
],
"ship_from_address" =>
[
"name" => "XXXXXXX",
"address_line1" => "XXXXXXXXXX",
"email" => "XXXXX#XXXXX.COM",
"city" => "XXXXXXXXX",
"postal_code" => "XXXXXX",
"country_code" => "US",
"phone" => "XXXXXXXXXXXX",
],
"weight" =>
[
"value" => 7,
"unit" => "oz",
],
"shipping_service_options" =>
[
"delivery_experience" => "DeliveryConfirmationWithSignature",
"carrier_will_pick_up" => true,
]
]
]
);
try {
$result = $apiInstance->getEligibleShipmentServices($body);
d($result);
} catch (Exception $e) {
echo "<PRE>";
echo 'Exception when calling MerchantFulfillmentV0Api->getEligibleShipmentServices: <BR>', wordwrap($e->getMessage(),80,"<br>\n",TRUE), PHP_EOL;
echo "</PRE>";
}
The $response I get back is:
Exception when calling MerchantFulfillmentV0Api->getEligibleShipmentServices:
[400] {
"errors": [
{
"code": "InvalidInput",
"message": "5
validation errors detected: Value \u0027\u0027 at
\u0027shipmentRequestDetails.shipFromAddress.email\u0027 failed to satisfy
constraint: Member must satisfy regular expression pattern: .+#.+; Value
\u0027\u0027 at \u0027shipmentRequestDetails.amazonOrderId\u0027 failed to
satisfy constraint: Member must satisfy regular expression pattern:
[0-9A-Z]{3}-[0-9]{7}-[0-9]{7}; Value \u0027\u0027 at
\u0027shipmentRequestDetails.weight.unit\u0027 failed to satisfy constraint:
Member must satisfy enum value set: [g, ounces, oz, grams]; Value null at
\u0027shipmentRequestDetails.weight.value\u0027 failed to satisfy constraint:
Member must not be null; Value \u0027[]\u0027 at
\u0027shipmentRequestDetails.itemList\u0027 failed to satisfy constraint: Member
must have length greater than or equal to 1",
"details": ""
}
]
}
In the Shipping Service options.... this needs to be set false.
"carrier_will_pick_up" => true,
If its set to true then it will not work. I think it has something to do with sending a request for pickup to the carrier.... and it seems counter-intuitive to set it to false... but thats what made it work!
I am attempting to make a SOAP call in PHP using the PHP Soap Client class. I managed to connect to the WDSL file however it isn't accepting my parameters. Here are all the necessary information needed for this call. When I enter the following:
$wsdlUrl = 'https://irm.cooperboating.com/rdpwincentralsvc/irmpublic.asmx?WSDL';
$client = new SoapClient($wsdlUrl);
var_dump($client->__getFunctions());
var_dump($client->__getTypes());
I get:
// Output from getFunctions()
[26]=>
string(83) "GetCourseInformationResponse GetCourseInformation(GetCourseInformation $parameters)"
// Output from getTypes()
[117]=>
string(63) "struct GetCourseInformation {
GetCourseInformation_irmRQ RQ;
}"
[118]=>
string(152) "struct GetCourseInformation_irmRQ {
irmWebSvcCredentials Credentials;
string CourseNumber;
string CourseID;
dateTime StartDate;
dateTime EndDate;
}"
[4]=>
string(104) "struct irmWebSvcCredentials {
string LogonID;
string Password;
string DataPath;
string DatabaseID;
}"
After reading the answer from: How to make a PHP SOAP call using the SoapClient class
I have attempted the following:
class irmWebSvcCredentials {
public function __construct() {
$this->LogonID = "SomeLogin";
$this->Password = "SomPass";
$this->DataPath = "SomePath";
$this->DatabaseID = "SomeId";
}
}
try {
$wsdlUrl = 'https://irm.cooperboating.com/rdpwincentralsvc/irmpublic.asmx?WSDL';
$client = new SoapClient($wsdlUrl);
$credentials = new irmWebSvcCredentials();
$params = array(
"Credentials" => $credentials,
"CourseNumber" => "",
"CourseID" => "",
"StartDate" => "2019-12-05T18:13:00",
"EndDate" => "2025-12-29T18:13:00",
);
$response = $client->GetCourseInformation(array($params));
var_dump($response);
}
catch(Exception $e) {
echo $e->getMessage();
}
I've also tried inputting "Credentials" as just an array instead of a class as some other answers have suggested like so:
$params = array(
"Credentials" => array(
"LogonID" => "SomeLogin",
"Password" => "SomPass",
"DataPath" => "SomePath",
"DatabaseID" => "SomeId",
),
"CourseNumber" => "",
"CourseID" => "",
"StartDate" => "2019-12-05T18:13:00",
"EndDate" => "2025-12-29T18:13:00",
);
It doesn't seem to matter what I input for the parameters when I call $client->GetCourseInformation, as long as I provide a parameter in the structure of an array it always gives me the same output which is:
object(stdClass)#3 (1) {
["GetCourseInformationResult"]=>
object(stdClass)#4 (3) {
["Status"]=>
int(1)
["ErrMsg"]=>
string(47) "GetCourseInformation_irmRQ is not instantiated."
...
Using Postman I've been able to get the expected output so that leads me to believe that I am not providing a certain parameter. Lastly here is the body I provide in Postman to get the expected output with content type being text/xml:
<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>
<GetCourseInformation xmlns="http://someurl.com/irmpublic">
<RQ>
<Credentials>
<LogonID>SomeLogin</LogonID>
<Password>SomPass</Password>
<DataPath>SomePath</DataPath>
<DatabaseID>SomeId</DatabaseID>
</Credentials>
<CourseNumber></CourseNumber>
<CourseID></CourseID>
<StartDate>2019-12-20T18:13:00</StartDate>
<EndDate>2025-12-29T18:13:00</EndDate>
</RQ>
</GetCourseInformation>
</soap:Body>
</soap:Envelope>
Is there something I'm not providing? Or does this problem have something to do with the API itself?
This question has been solved. The answer was in the body provided in Postman.
<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>
<GetCourseInformation xmlns="http://someurl.com/irmpublic">
<RQ> <----- Notice the RQ here
<Credentials>
<LogonID>SomeLogin</LogonID>
<Password>SomPass</Password>
<DataPath>SomePath</DataPath>
<DatabaseID>SomeId</DatabaseID>
</Credentials>
<CourseNumber></CourseNumber>
<CourseID></CourseID>
<StartDate>2019-12-20T18:13:00</StartDate>
<EndDate>2025-12-29T18:13:00</EndDate>
</RQ>
</GetCourseInformation>
</soap:Body>
</soap:Envelope>
The RQ was never provided so it didn't know how to read the provided parameter. To fix this we simply have to change this:
$params = array(
"Credentials" => array(
"LogonID" => "SomeLogin",
"Password" => "SomPass",
"DataPath" => "SomePath",
"DatabaseID" => "SomeId",
),
"CourseNumber" => "",
"CourseID" => "",
"StartDate" => "2019-12-05T18:13:00",
"EndDate" => "2025-12-29T18:13:00",
);
To this:
$params = array(
"RQ" => array(
"Credentials" => array(
"LogonID" => "SomeLogin",
"Password" => "SomPass",
"DataPath" => "SomePath",
"DatabaseID" => "SomeId",
),
"CourseNumber" => "",
"CourseID" => "",
"StartDate" => "2019-12-05T18:13:00",
"EndDate" => "2025-12-29T18:13:00",
)
);
This was a very specific question but I hope this helps someone in the future.
I'm trying to access the HelloWorldCredentials service on
https://statistik.uni-c.dk/instregws/DataServiceXML.asmx?op=HelloWorldCredentials
I have the necessary credentials.
As far as I can see, I need to submit an array called "Credentials" containing one array containing two strings, one called "Username" and one called "Password".
I build my array like this:
$params = array(
"Credentials" => array(
"Username" => "Obviously",
"Password" => "NotPublic",
)
);
However, when I execute
$client = new SoapClient("https://statistik.uni-c.dk/instregws/DataServiceXML.asmx?wsdl", array('trace' => 1));
$params = array(
"Credentials" => array(
"Username" => "Obviously",
"Password" => "NotPublic",
)
);
$response = $client->__soapCall("HelloWorldCredentials", array($params));
echo("*** PARAMS ***\n");
var_dump( $params );
echo("\n*** REQUEST ***\n");
echo( $client->__getLastRequest() );
echo("\n*** RESPONSE ***\n");
var_dump( $response );
I get
*** PARAMS ***
array(1) {
["Credentials"]=>
array(2) {
["Username"]=>
string(11) "Obviously"
["Password"]=>
string(8) "NotPublic"
}
}
-as I should, but
*** REQUEST ***
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://statistik.uni-c.dk/instreg/">
<SOAP-ENV:Body>
<ns1:HelloWorldCredentials/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So obviously I get
*** RESPONSE ***
object(stdClass)#3 (1) {
["HelloWorldCredentialsResult"]=>
string(19) "Missing credentials"
}
Why are my parameters completely absent from the request?
according to the WSDL for the HelloWorldCredentials method you need to send the Credentials in the Header not the Body of the soap Envelope
so this should work:
<?php
$client = new SoapClient("https://statistik.uni-c.dk/instregws/DataServiceXML.asmx?wsdl", array('trace' => 1));
$credentials = array(
'Username' => 'Obviously',
'Password' => 'NotPublic'
);
$header = new SoapHeader('http://statistik.uni-c.dk/instreg/', 'Credentials', $credentials);
$client->__setSoapHeaders($header);
$response = $client->HelloWorldCredentials();
echo("\n*** REQUEST ***\n");
echo( $client->__getLastRequest() );
echo("\n*** RESPONSE ***\n");
var_dump( $response );
I'm trying to achieve a PHP SOAP client to a HTTPS service and am encountering a problem I'm not able to resolve. Am I missing something ?
I'm establishing a connection to the webservice as follow :
$context = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'allow_self_signed' => true
)
));
$opt = array(
"login" => self::LOGIN,
"password" => self::PASSWORD,
"authentication" => SOAP_AUTHENTICATION_BASIC,
"trace" => true,
"exceptions" => 1,
"cache_wsdl" => WSDL_CACHE_NONE,
'stream_context' => $context,
"connection_timeout" => 30
);
try {
$soapClient = new SoapClient(self::WS_URL, $opt);
} catch (SoapFault $fault) {
var_dump($fault);
exit;
}
Until there, no problem seems to arise. Then I do the following :
var_dump($soapClient->__getFunctions());
This gives me the list of functions the service can process and I get a valid response :
array(1) { [0]=> string(54) "ListReponseAX getElig(Elig $in0)" }
The problem then arises : when I try to invoke the getElig function, no matter how I try, I get this "Could not connect to host" error.
I've tried passing the data as text, as array, as object, as soapvar but always get this annoying error.
Thx in advance for any help !
Ok the problem is resolved. For those wondering, the WSDL file had an endpoint specification in it that was irrelevant. By forcing the location upon initializing the PHP class, I was able to circumvent the problem :
$opt = array(
"login" => self::LOGIN,
"password" => self::PASSWORD,
"authentication" => SOAP_AUTHENTICATION_BASIC,
"trace" => true,
"exceptions" => 1,
"cache_wsdl" => WSDL_CACHE_NONE,
'stream_context' => $context,
"connection_timeout" => 30,
"location" => "https://the_location_to_force"
);
What do I need:
I need some help figuring out an error that i receive from calling a function from a WSDL file with soapclient. Or I would like some help extracting data from a cURL response.
What am I trying to reach:
I am trying to reach to call a function from a WSDL, and get a response from the action.
What are my experiences:
I can call the actions storeOrders succesfull with a cURL statement, I do also get a response.
But with the given response i guess a string. I am not able to extract the data out of it.
So I tried to request the same action from the server but then using soapclient, but I keep getting a error.
What I already tried:
I tried to make the cURL response a new SimpleXMLElement, but it always returns a emty object. Also when I try to reach one of the children.
I tried to make the cURL reponse return as an array and loop trough it with a foreach, also here I got an empty object.
I tried to explode the cURL reponse, but also there i had some problems with the wrong data being returned.
I tried to call it with SoapClient, but I keep getting this error.
So I would like some help with extracting data from cURL, or processing the request with SoapClient.
My cURL request (with answer, all the variables are set with the correct data):
function storeOrderAndGetLabel($delisId, $auth_token, $messageLanguage, $printerLanguage, $paperFormat, $identificationNumber,
$sendingDepot, $product, $mpsCompleteDelivery, $send_name, $send_street, $send_country, $send_zipcode, $send_city,
$send_customerNumber, $rec_name, $rec_street, $rec_state, $rec_country, $rec_zipcode, $rec_city, $parcelLabelNumber,
$orderType)
{
$xml = '
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://dpd.com/common/service/types/Authentication/2.0" xmlns:ns1="http://dpd.com/common/service/types/ShipmentService/3.1">
<soapenv:Header>
<ns:authentication>
<delisId>'.$delisId.'</delisId>
<authToken>'.$auth_token.'</authToken>
<messageLanguage>'.$messageLanguage.'</messageLanguage>
</ns:authentication>
</soapenv:Header>
<soapenv:Body>
<ns1:storeOrders>
<printOptions>
<printerLanguage>'.$printerLanguage.'</printerLanguage>
<paperFormat>'.$paperFormat.'</paperFormat>
</printOptions>
<order>
<generalShipmentData>
<identificationNumber>'.$identificationNumber.'</identificationNumber>
<sendingDepot>'.$sendingDepot.'</sendingDepot>
<product>'.$product.'</product>
<mpsCompleteDelivery>'.$mpsCompleteDelivery.'</mpsCompleteDelivery>
<sender>
<name1>'.$send_name.'</name1>
<street>'.$send_street.'</street>
<country>'.$send_country.'</country>
<zipCode>'.$send_zipcode.'</zipCode>
<city>'.$send_city.'</city>
<customerNumber>'.$send_customerNumber.'</customerNumber>
</sender>
<recipient>
<name1>'.$rec_name.'</name1>
<street>'.$rec_street.'</street>
<state>'.$rec_state.'</state>
<country>'.$rec_country.'</country>
<zipCode>'.$rec_zipcode.'</zipCode>
<city>'.$rec_city.'</city>
</recipient>
</generalShipmentData>
<parcels>
<parcelLabelNumber>'.$parcelLabelNumber.'</parcelLabelNumber>
</parcels>
<productAndServiceData>
<orderType>'.$orderType.'</orderType>
</productAndServiceData>
</order>
</ns1:storeOrders>
</soapenv:Body>
</soapenv:Envelope>
';
$headers = array(
"POST HTTP/1.1",
"Content-type: application/soap+xml; charset=\"utf-8\"",
"SOAPAction: \"http://dpd.com/common/service/ShipmentService/3.1/storeOrders\"",
"Content-length: ".strlen($xml)
);
$cl = curl_init('https://public-ws-stage.dpd.com/services/ShipmentService/V3_1/');
curl_setopt($cl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($cl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($cl, CURLOPT_POST, 1);
curl_setopt($cl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($cl, CURLOPT_POSTFIELDS, "$xml");
curl_setopt($cl, CURLOPT_RETURNTRANSFER, 1);
$output_cl = json_decode(trim(json_encode(curl_exec($cl))), TRUE);
return $output_cl;
//return $output_cl;
}
And from this code i get the reponse, i guess it is a string but i don't know for sure:
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:body>
<ns2:storeordersresponse xmlns:ns2="http://dpd.com/common/service/types/ShipmentService/3.1">
<orderresult>
<parcellabelspdf>pdfkey</parcellabelspdf>
<shipmentresponses>
<identificationnumber>identificationnumber</identificationnumber>
<mpsid>mpsid</mpsid>
<parcelinformation>
<parcellabelnumber>labelnr</parcellabelnumber>
</parcelinformation>
</shipmentresponses>
</orderresult>
</ns2:storeordersresponse>
</soap:body>
</soap:envelope>
Now my function calling the SoapClient function:
$label = storeOrderAndGetLabel($delisId, $auth_token, $messageLanguage, $printerLanguage, $paperFormat, $identificationNumber,
$sedingDepot, $product, $mpsCompleteDelivery, $send_name, $send_street, $send_country, $send_zipcode, $send_city,
$send_customerNumber, $rec_name, $rec_street, $rec_state, $rec_country, $rec_zipcode, $rec_city, $parcelLabelNumber,
$orderType);
print_r($label);
now the soap call itself:
function storeOrderAndGetLabel($delisId, $auth_token, $messageLanguage, $printerLanguage, $paperFormat, $identificationNumber,
$sendingDepot, $product, $mpsCompleteDelivery, $send_name, $send_street, $send_country, $send_zipcode, $send_city,
$send_customerNumber, $rec_name, $rec_street, $rec_state, $rec_country, $rec_zipcode, $rec_city, $parcelLabelNumber,
$orderType)
{
$client = new SoapClient('https://public-ws-stage.dpd.com/services/ShipmentService/V3_1?WSDL');
$label = $client->storeOrders
(array
(
"printOptions" => array
(
"printerLanguage" => "$printerLanguage",
"paperFormat" => "$paperFormat"
),
"order" => array
(
"generalShipmentData" => array
(
"identificationNumber" => "$identificationNumber",
"sendingDepot" => "$sendingDepot",
"product" => "$product",
"mpsCompleteDelivery" => "$mpsCompleteDelivery",
"sender" => array
(
"name1" => "$send_name",
"street" => "$send_street",
"country" => "$send_country",
"zipCode" => "$send_zipcode",
"city" => "$send_city",
"customerNumber" => "$send_customerNumber"
),
"recipient" => array
(
"name1" => "$rec_name",
"street" => "$rec_street",
"state" => "$rec_state",
"country" => "$rec_country",
"zipCode" => "$rec_zipcode",
"city" => "$rec_city"
)
),
"parcels" => array
(
"parcelLabelNumber" => "$parcelLabelNumber"
),
"productAndServiceData" => array
(
"orderType" => "$orderType"
)
)
)
);
return $label;
}
The error I receive from the soapcall:
Fatal error: Uncaught SoapFault exception: [soap:Server] Fault occurred while processing. in getLabel.php:107 Stack trace: #0 getLabel.php(107): SoapClient->__call('storeOrders', Array) #1 getLabel.php(107): SoapClient->storeOrders(Array) #2 getLabel.php(38): storeOrderAndGetLabel('username', 'password...', 'nl_NL', 'PDF', 'A4', '77777', '0163', 'CL', '0', 'uname', 'straat', 'NL', 'zipcode', 'City', '341546246451...', 'Test-Empfaenger', 'Test-Strasse', 'BY', 'DE', '123451', 'ahahaha', '16231545', 'consignment') #3 {main} thrown in getLabel.php on line 107
I would like to extract the parcellabelspdf key and the mpsid from the response. It would be really nice if someone could take a look at it.
Two possible problems:
You need to authenticate when calling the DPD ShipmentService. See below for a working example.
Make sure, that the parameter mpsCompleteDelivery is passed as an integer (0), not the string "false". Consider changing this line:
"mpsCompleteDelivery" => "$mpsCompleteDelivery"
to:
"mpsCompleteDelivery" => $mpsCompleteDelivery
Here is a full example including the login and output of a DPD-label as PDF:
// Let's log in first...
$c = new SoapClient('https://public-ws-stage.dpd.com/services/LoginService/V2_0?wsdl');
$res = $c->getAuth(array(
'delisId' => 'your-Id',
'password' => 'your-Password',
'messageLanguage' => 'de_DE'
));
// ...and remember the token.
$auth = $res->return;
// ...and then generate a label
$c = new SoapClient('https://public-ws-stage.dpd.com/services/ShipmentService/V3_1?wsdl');
$token = array(
'delisId' => $auth->delisId,
'authToken' => $auth->authToken,
'messageLanguage' => 'de_DE'
);
// Set the header with the authentication token
$header = new SOAPHeader('http://dpd.com/common/service/types/Authentication/2.0', 'authentication', $token);
$c->__setSoapHeaders($header);
try {
$res = $c->storeOrders( array
(
"printOptions" => array(
"paperFormat" => "A4",
"printerLanguage" => "PDF"
),
"order" => array(
"generalShipmentData" => array(
"sendingDepot" => $auth->depot,
"product" => "CL",
"mpsCompleteDelivery" => false,
"sender" => array(
"name1" => "Sender Name",
"street" => "Sender Street 2",
"country" => "DE",
"zipCode" => "65189",
"city" => "Wiesbaden",
"customerNumber" => "123456789"
),
"recipient" => array(
"name1" => "John Malone",
"street" => "Johns Street 34",
"country" => "DE",
"zipCode" => "65201",
"city" => "Wiesbaden"
)
),
"parcels" => array(
"parcelLabelNumber" => "09123829120"
),
"productAndServiceData" => array(
"orderType" => "consignment"
)
)
)
);
} catch (SoapFault $exception) {
echo $exception->getMessage();
die();
}
// Et voilà!
header('Content-type: application/pdf');
echo $res->orderResult->parcellabelsPDF;
Check here for more information:
http://labor.99grad.de/2014/10/05/deutscher-paket-dienst-dpd-soap-schnittstelle-mit-php-nutzen-um-versandetikett-als-pdf-zu-generieren/