Sample Code

Here are some sample code snippets in PHP for each of our three API functions. Snippets for other languages will be coming soon.

Place Order Function

<?php // * Place an Order *

//showing all errors
error_reporting(E_ALL);
ini_set('display_errors', '1');

$client = new soapclient('http://orderapi.zenprint.com/orderapi/?WSDL', array('cache_wsdl' => WSDL_CACHE_NONE));
$credentials = array("partnerCode"=>"REPLACE_WITH_PARTNER_CODE", "apiKey" =>"REPLACE_WITH_API_KEY");

$orderLines = array(); //setup an array to contain your order line items

$shipToAddress = array(
	"name"=>"John Doe",
	"address1"=>"555 Main Street",
	"address2"=>"Suite 100",
	"city"=>"Provo",
	"state"=>"UT",
	"zipCode"=>"84606",
	"countryCode"=>"USA",
	"emailAddress"=>"john@example.com",
	"mainPhone"=>"555-555-5555"
);

$shippingInfo = array(
	"shipAddress"=>$shipToAddress,
	"carrier"=>'USPS',
	"shipMethod"=>"PR", //see the shipping codes section below for more info
	"returnAddress"=>""
);	

// * start line item area * (you may need to loop this section if you have multiple line items)

$file=array(
	"FileFormat"=>"PDF",
	"FileName"=>"https://zenprint.s3.amazonaws.com/zenprint/temp/pdfs/12345-1-FULL.pdf"
);

$lineitem = array(
	"lineItemId"=>1, //this should be unique (1 for first item, 2 for second item ordered, etc.)
	"productId"=>27, //this is the product you're wanting to order
	"projectId"=>0, //pass 0 for this unless otherwise instructed
	"quantity"=>1,
	"files"=>array($file),
	"shippingData"=>$shippingInfo
);

$orderLines = array_merge($orderLines,$lineitem); //add the line item to your orderLines array

// * end line item area *

//set up today's date
$s = date("m/d/Y, H:i:s");
$date = strtotime($s);

$order = array(
	"creds"=>$credentials, //see the section on authentication for this
	"partnerOrderId"=>"12345", //you can pass your own order number if you have one
	"orderLineItems"=>array($orderLines),
	"rushOrder"=>0,
	"orderDate"=>$date,
	"errors"=>"" //just pass an empty string for this
);

//var_dump($order);

$newOrder = $client->PlaceOrder(array("orderData" => $order));
?>

Check Order Status Function

<?php * Check Order Status *
										
//showing all errors
error_reporting(E_ALL);
ini_set('display_errors', '1');

$client = new soapclient('http://orderapi.zenprint.com/orderapi/?WSDL', array('cache_wsdl' => WSDL_CACHE_NONE));
$credentials = array("partnerCode"=>'REPLACE_WITH_PARTNER_CODE', "apiKey" =>'REPLACE_WITH_API_KEY');
$orderID = 12345; // replace with the order number you'd like to check

$orderStatus = $client->CheckOrderStatus(array(
        "creds" => $credentials,
        "partnerOrderId" => $orderID
))->CheckOrderStatusResult;

//var_dump($orderStatus);
if (is_array($orderStatus->orderLineItems->LineItem)){
	echo "Current Order Status: ".$orderStatus->orderLineItems->LineItem[0]->currentState;
	if ($orderStatus->orderLineItems->LineItem[0]->currentState == 'SHIPPED') {
		echo "<br>Date Shipped: ".$orderStatus->orderLineItems->LineItem[0]->shippingData->dateShipped;
		echo "<br>Carrier: ".$orderStatus->orderLineItems->LineItem[0]->shippingData->actualCarrier;
		echo "<br>Ship Method: ".$orderStatus->orderLineItems->LineItem[0]->shippingData->actualShipmethod;
		echo "<br>Tracking Info: ".$orderStatus->orderLineItems->LineItem[0]->shippingData->trackingNumber;
	}
} else {
	echo "Current Order Status: ".$orderStatus->orderLineItems->LineItem->currentState;
	if ($orderStatus->orderLineItems->LineItem->currentState == 'SHIPPED') {
		echo "<br>Date Shipped: ".$orderStatus->orderLineItems->LineItem->shippingData->dateShipped;
		echo "<br>Carrier: ".$orderStatus->orderLineItems->LineItem->shippingData->actualCarrier;
		echo "<br>Ship Method: ".$orderStatus->orderLineItems->LineItem->shippingData->actualShipmethod;
		echo "<br>Tracking Info: ".$orderStatus->orderLineItems->LineItem->shippingData->trackingNumber;
	}
}
?>

Cancel Order Function

<?php * Cancel an Order *
										
//showing all errors
error_reporting(E_ALL);
ini_set('display_errors', '1');

$client = new soapclient('http://orderapi.zenprint.com/orderapi/?WSDL', array('cache_wsdl' => WSDL_CACHE_NONE));
$credentials = array("partnerCode"=>"REPLACE_WITH_PARTNER_CODE", "apiKey" =>"REPLACE_WITH_API_KEY");
$orderID = 12345; // replace with the order number you'd like to cancel

$orderStatus = $client->CancelOrder(array(
        "creds" => $credentials,
        "partnerOrderId" => $orderID
))->CancelOrderResult;

//var_dump($orderStatus);
if (is_array($orderStatus->orderLineItems->LineItem)){
	echo "Current Order Status: ".$orderStatus->orderLineItems->LineItem[0]->currentState;
} else {
echo "Current Order Status: ".$orderStatus->orderLineItems->LineItem->currentState;
}
?>
Application: ZenPrintApp [Run Tests, View Tests]
Framework: CFWheels 1.4.4
Active Environment: Development
Host Name: utpspro2
CFML Engine: Adobe ColdFusion 9,0,1,274733
Default Data Source: Zenprint
Database Adapter: SQLServer
URL Rewriting: On
URL Obfuscation: Off
Plugins: None
Controller: Main
Action: ApiSampleCode
Parameters: None
Execution Time: 31ms (view ~31ms, action ~31ms)
Help Links: Documentation, Mailing List, Issue Tracker