Jump to content

CreatePackingSlipbyLineItem: PartnerCredentials.Token element missing.


hinesj87

Recommended Posts

I'm trying to create a packing slip in PHP. What is the correct method of passing in the PartnerCredentials.Token?

 

<?php
$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pac="http://www.printable.com/WebService/PackingSlip">
  <soapenv:Header/>
  <soapenv:Body>
     <pac:CreatePackingSlipByLineItem>
        <pac:pRequest>
           <PartnerCredentials>
              <Token>TOKEN_STRING</Token>
           </PartnerCredentials>
           <PackingSlipNode>
              <PackingSlipNumber>999999</PackingSlipNumber>
              <ShipDate>2017-01-19</ShipDate>
              <CarrierName>UPS</CarrierName>
              <TrackingNumber>TRACKING_NUMBER</TrackingNumber>
              <ShipCost>9.99</ShipCost>
          <SkipAdjustInventory></SkipAdjustInventory>
              <ShipToAddress>
                 <Attention>Attn</Attention>
                 <Name>Name</Name>
                 <Address1>123 Fake St.</Address1>
                 <Address2></Address2>
                 <Address3></Address3>
                 <Address4></Address4>
                 <City>City</City>
                 <State>ST</State>
                 <PostalCode>99999</PostalCode>
                 <Country>US</Country>
              </ShipToAddress>
           </PackingSlipNode>
           <LineItems>
              <LineItem>
                 <ID type="Printable">LINE_ITEM_ID</ID>
                 <Quantity>1000</Quantity>
              </LineItem>
           </LineItems>
        </pac:pRequest>
     </pac:CreatePackingSlipByLineItem>
  </soapenv:Body>
</soapenv:Envelope>';

$soap = new SoapClient("http://services.printable.com/trans/1.0/PackingSlip.asmx?wsdl", array('trace' => 1, 'cache_wsdl' => WSDL_CACHE_NONE));

$parameters = array(
   "pRequest" => $xml
);

$soap->CreatePackingSlipbyLineItem($parameters);

header('Content-type: text/xml');
echo $soap->__getLastResponse(); exit;

Here is the response:

 

<soap:Envelope>
   <soap:Body>
       <CreatePackingSlipByLineItemResponse>
           <CreatePackingSlipByLineItemResult>
               <OrderId/>
               <Status Action="PACKING_SLIP" Status="ProcessFailure" Code="2" Message="Service Failure - Printable.WebServices.BusinessLogic - PartnerCredentials.Token element missing."/>
               <LineItemResponses/>
               <Actions/>
               <LineItemID/>
           </CreatePackingSlipByLineItemResult>
       </CreatePackingSlipByLineItemResponse>
   </soap:Body>
</soap:Envelope>

Link to comment
Share on other sites

My original intent was to use native PHP functionality to submit jobs to the SOAP server. Due to (my IIS) server configuration and a general lack of ambition to troubleshoot the issues I have encountered, I have decided to use Curl.

 

Here is the code:

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

$endpoint_url = "https://services.printable.com/trans/1.0/PackingSlip.asmx?wsdl";

$soap_action_url = "http://www.printable.com/WebService/PackingSlip/CreatePackingSlipByLineItem";

$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pac="http://www.printable.com/WebService/PackingSlip">
  <soapenv:Header/>
  <soapenv:Body>
     <pac:CreatePackingSlipByLineItem>
        <pac:pRequest>
           <PartnerCredentials>
              <Token>TOKEN_STRING</Token>
           </PartnerCredentials>
           <PackingSlipNode>
              <PackingSlipNumber>PACKINGSLIPNUMBER_STRING</PackingSlipNumber>
              <ShipDate>SHIPDATE_DATE</ShipDate>
              <CarrierName>CARRIERNAME_STRING</CarrierName>
              <TrackingNumber>TRACKINGNUMBER_STRING</TrackingNumber>
              <ShipCost>SHIPCOST_FLOAT</ShipCost>
              <SkipAdjustInventory>BOOL</SkipAdjustInventory>
              <ShipToAddress>
                 <Attention>ATTENTION_STRING</Attention>
                 <Name>NAME_STRING</Name>
                 <Address1>ADDR1_STRING</Address1>
                 <Address2>ADDR2_STRING</Address2>
                 <Address3>ADDR3_STRING</Address3>
                 <Address4>ADDR4_STRING</Address4>
                 <City>CITY_STRING</City>
                 <State>STATE_STRING</State>
                 <PostalCode>ZIP_STRING</PostalCode>
                 <Country>COUNTRY_STRING</Country>
              </ShipToAddress>
           </PackingSlipNode>
           <LineItems>
              <LineItem>
                 <ID type="Printable">LINE_ITEM_ID_STRING</ID>
                 <Quantity>QTY_INT</Quantity>
              </LineItem>
           </LineItems>
        </pac:pRequest>
     </pac:CreatePackingSlipByLineItem>
  </soapenv:Body>
</soapenv:Envelope>';

$send_payload_response = send_payload($endpoint_url, $soap_action_url, $xml);

var_dump($send_payload_response);

exit;

/********************************************
* Sends an XML payload to the SOAP server of your choice
*
* @param string $endpoint_url
* @param string $soap_action_url
* @param string $xml
* @param array $headers
*/
function send_payload($endpoint_url, $soap_action_url, $xml, $headers = array()) {

   $default_headers = array(
       'Content-Type: text/xml; charset="utf-8"', 
       'Content-Length: ' . strlen($xml),
       'SOAPAction: "' . $soap_action_url . '"'
   );

   if(count($headers) == 0)
       $headers = $default_headers;

   if( ! function_exists('curl_version'))
       die("cURL is not installed. Please relay this error to your friendly neighborhood webmaster.");

   $c = curl_init(); 
   curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt($c, CURLOPT_URL, $endpoint_url); 
   curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE); 
   curl_setopt($c, CURLOPT_TIMEOUT, 60); 
   curl_setopt($c, CURLOPT_HTTPHEADER, $headers);
   curl_setopt($c, CURLOPT_HEADER, 1);
   curl_setopt($c, CURLINFO_HEADER_OUT, TRUE);
   curl_setopt($c, CURLOPT_POST, TRUE); 
   curl_setopt($c, CURLOPT_POSTFIELDS, $xml);

   $response = curl_exec($c);

   // debug
   // echo "<pre>" . htmlentities($xml) . "<hr>" . var_dump($response); exit;

   return $response;
}

Edited by hinesj87
Link to comment
Share on other sites

×
×
  • Create New...