API

Overview

Printmotor has two different APIs for two separate use cases: client and server API.

Both client and server APIs are RESTful and accessed over a secure HTTPS network. Endpoints read and receive JSON objects.

Client API and Server API

Client API is used in situations where customers are able to create shopping carts and pay for products with credit card. This way you can easily create a web site that communicates straight to Printmotor backend and provides your customers a great and easy way of ordering and receiving beautiful printed products.

For businesses integrating with client API is really easy: there is no upfront or other fees for setup. When your customer orders something from your web store, printing, delivery and billing is performed by Printmotor. Each month you will receive a payment from Printmotor, depending on your sales and margins you’ve set up in the Printmotor admin panel.

Server API is commonly used in enterprise integrations: your server is accessing Printmotor backend when performing a new order. With server API you can integrate your existing software to send print orders to the Printmotor backend. Each request may define a new destination or can reuse an existing one.

When you send new orders using the server API there is no billing integration, instead Printmotor will charge you each time a product is delivered.

Client API

Use client API when you want a website to communicate with Printmotor backend. Commonly this is done with Javascript functions and frameworks, for example with jQuery.

Printmotor client API provides a RESTful JSON-over-HTTPS interface. In addition to this, Printmotor client API also provides a jQuery library if you’d like to implement or integrate a HTML+CSS page to Printmotor.

Each request must provide a service request header, to identify the service for Printmotor. This is very easily done, e.g. in jQuery site you may write the following block in your HTML site, just before end of head-tag:

 <script>
    <!-- Printmotor key identifies your service 
         and is available after registration -->
    var printmotorKey = "YourPrintmotorKey";
</script>

<script src="//api.printmotor.io/v1/script.js"
        type="text/javascript"></script>
<link href="//api.printmotor.io/v1/styles.css"
      rel="stylesheet" type="text/css" /> 

After this you get helper methods to access Printmotor RESTful client API, but also a ready jQuery helper library that checks your HTML site for specific Printmotor CSS classes. With these classes you can implement necessary functionality to build a custom print product web site.

Server API

Use Printmotor Server API when you have a system that is ready to send print product orders to production and delivery.

For example if you’d like to order a predefined print product to a custom delivery address just perform a simple HTTPS POST request to Printmotor server API. You may use a shell script for this, for example:

 #!/bin/sh

/usr/bin/curl -v \
-X POST -d @payloaddata.json \
-u "username:password" \
-H "Content-Type: application/json" \
"https://api.printmotor.io/api/v1/order" 

where payloaddata.json could be like this:

 {
    "address": {
        "id": "224490cd-1da4-47d3-b646-97a40e026b0c"
    }
    "products": [
        {
            "layout": "5041ed5a-64fc-32b8-8286-2e0a5fe254b2",
            "amount": 10
        }
    ]
} 

You may also for example implement a PHP web site that takes in a form that holds delivery address information and places a new Printmotor order:

 <?php

/**
 * This server API example sends an order to printmotor:
 *
 * - HTTP request provides the destination address where goods 
 *   will be delivered
 * - HTTP request also determines the layout id that's used
 *   when a product layout is created, 
 *   e.g. "40d7d456-c4c0-42bf-8328-219359658674"
 * - HTTP request also contains the amount of ordered products.
 */

$apiendpoint = "https://api.printmotor.io/api/v1/order";
$apiserviceid = "myserviceid";
$apiusername = "myusername";
$apipassword = "mypassword";

// Layout ID is available in Printmotor administration panel:
$sendDataJson = json_encode(array(
	"address" => array(
        "address" => $_POST["order-address"],
        "address2" => $_POST["order-address2"],
        "postalArea" => $_POST["order-city"],
        "postalCode" => $_POST["order-postalcode"],
        "countryIso2" => $_POST["order-country"]
	),
    "orderer" => array(
        "firstName" => $_POST["order-firstname"],
        "lastName" => $_POST["order-lastname"]
    ),
    "products" => array(
        array(
            "layout" => $_POST["order-layoutid"],
            "amount" => $_POST["order-amount"]
		)
	)
));

/*** perform the API call ****/

$session = curl_init($apiendpoint); 
curl_setopt($session, CURLOPT_USERPWD,
            $apiusername . ":" . $apipassword);
$headers = array(
    'Content-Type: application/json',
    'X-Printmotor-Service: ' . $apiserviceid
);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $sendDataJson);

$curl_response = curl_exec($session);
$decodedResponse = json_decode($curl_response);
if (!isset($decodedResponse->orderNumber)) {
	die("Unknown error");
} else {
	// successful order! parse an order number
	$orderNumber = $decodedResponse->orderNumber;
}

curl_close($session);
?> 

Real-life Example

Request API access and Get started!

Please register to get a more detailed API description and if needed, ready-made code to start providing print products over web even today!

External, Third Party Integrations

Printmotor also provides integrations to existing e-commerce platforms including WooCommerce and Shopify.