In this guide you can read how to print a file that is hosted by Peecho. This tutorial takes you through the process of uploading your file on the Peecho servers and then placing print orders from it. With this approach you can print the same document as many times as you like, without uploading the file every time.

Requirements

Before you can start using Peecho’s print API, you need to do two things:
    • Register

The first step is creating a Peecho account. You can create your Peecho account here.

    • Top up your balance

In order to print your products, first you have to make sure you have some credit on your account. To do this, you have to log in and go to your dashboard. Click on ”Money” in the top menu and then click on ”Deposit” in the drop down menu. When you click on the green ”+ Buy credit” button, you can top-up your balance. You can pay with MasterCard, Visa, iDeal or PayPal.

1. Upload your document

First you have  to upload your document to the Peecho system. You can find all your uploaded files by clicking on ”Publications” in the top menu of your dashboard.

POST /rest/storage/createPublicationFromUpload

 

Request

RequestRequirementExplanation
sourceUrlYesThe full URL to the source document
applicationApiKeyYesUnique string identifier of the application
Curl
curl -v -d "sourceUrl={yourSourceUrl}&applicationApiKey={yourApplicationApiKey}" "http://www.peecho.com/rest/storage/createPublicationFromUpload"

Response

Service returns publication number

 

2. Choose product

The next step is to select what kind of product you want to offer in print. Not all available products are valid for each file you uploaded. To see offerings suitable for your document you should call this API method:

GET /rest/offering/list/publication/{publicationId}

Request

ParameterRequiredExplanation
publicationIdYesUnique string identifier of the publication.
applicationApiKeyYesUnique string identifier of the application.
Curl
curl -v "http://www.peecho.com/rest/offering/list/filtered?applicationApiKey={yourApplicationApiKey}&numberOfPages=40&fileType=PDF"

Response

The response is exactly the same as the response for accessing an unfiltered offering list.

 

<?xml version="1.0"?>
<root>
   <pricingExpireDate>2011-09-13T16:00:00.000+02:00</pricingExpireDate>
   <offerings>
      <offering>
         <id>1</id>
         <price>1.00</price>
         <countryShippingPrice>0.00</countryShippingPrice>
         <regionShippingPrice>0.00</regionShippingPrice>
         <worldShippingPrice>0.00</worldShippingPrice>
         <pricePerPage>1.00</pricePerPage>
         <name>boek a5</name>
         <downloadLocation>http://cloud.peecho.com/1/</downloadLocation>
         <currency>EUR</currency>
         <priceByCurrency>
            <value amount="1.00" currency="EUR"/>
            <value amount="1.37" currency="USD"/>
         </priceByCurrency>
         <pricePerPageByCurrency>
            <value amount="0.00" currency="EUR"/>
            <value amount="0.00" currency="USD"/>
         </pricePerPageByCurrency>
         <countryShippingPriceByCurrency>
            <value amount="0.00" currency="EUR"/>
            <value amount="0.00" currency="USD"/>
         </countryShippingPriceByCurrency>
         <regionShippingPriceByCurrency>
            <value amount="0.00" currency="EUR"/>
            <value amount="0.00" currency="USD"/>
         </regionShippingPriceByCurrency>
         <worldShippingPriceByCurrency>
            <value amount="0.00" currency="EUR"/>
            <value amount="0.00" currency="USD"/>
         </worldShippingPriceByCurrency>
         <vatPercentage>19</vatPercentage>
         <defaultNumberOfPages>12</defaultNumberOfPages>
         <minNumberOfPages>0</minNumberOfPages>
         <maxNumberOfPages>100</maxNumberOfPages>
         <dimensionWidth>0</dimensionWidth>
         <dimensionHeight>0</dimensionHeight>
         <minimumQuantity>1</minimumQuantity>
         <addShipping>true</addShipping>
         <recommended>false</recommended>
         <dimensionUnit>mm</dimensionUnit>
         <elements>
            <id>1</id>
            <name>content</name>
            <url/>
         </elements>
         <elements>
            <id>2</id>
            <name>cover</name>
            <url>cover</url>
         </elements>
         <catalogueItemCode>boek a5</catalogueItemCode>
         <merchantApiKey>your-merchant-api-key</merchantApiKey>
         <applicationApiKey>your-application-api-key</applicationApiKey>
         <fixedSize>false</fixedSize>
      </offering>
   </offerings>
</root>

 

3. Create an order

Once you decided which product you want to print, it is time to place an order. You can do this by calling this method:

POST /rest/order/create_from_publication

Request

ParameterRequiredExplanation
merchantApiKeyYesUnique string identifier of the merchant.
offeringIdYesUnique integer identifier of your offering.
publicationIdYesUnique integer identifier of your publication.
merchantReferenceYesUse your own internal id as a reference to link this order to your internal systems.
paymentReferenceNo Reference for the payment provider, this should be a globally unique identifier. Use a UUID.
titleNoPublication title
Curl
curl -v -d "merchantApiKey={yourMerchantApiKey}&offeringId=70&publicationId=1240&merchantReference=12245&title=My publication" "http://www.peecho.com/rest/order/create_from_publication"

Response

An XML representation of the new order including the policy and signature to be used when sending files to the order bucket.

 

<?xml version="1.0"?>
<order>
  <externalOrderId>4194</externalOrderId>
  <signedPutUrl>http://peecho-test-order.s3.amazonaws.com</signedPutUrl>
  <signedPutPath>1/4194/</signedPutPath>
  <base64EncodedPolicy>encoded-policy </base64EncodedPolicy>
  <signature>3XRuQ96XNs10porjx30=</signature>
  <apiVersion>0</apiVersion>
  <id>4194</id>
  <orderState>OPEN</orderState>
  <quantity>1</quantity>
</order>

 

4. Set details

Great! You have placed your order. You can find your orders by clicking on ”Orders” in the top menu of your dashboard. Now you have to provide order details.

POST /rest/order/details

Supply additional details about an order, such as the customer shipping address and quantity.

Request

<?xml version="1.0"?>
<address>
    <firstName>recipientFirstName</firstName>
    <lastName>recipientLastName</lastName>
    <addressLine1>shippingAddressLine1</addressLine1>
    <addressLine2>shippingAddressLine2</addressLine2>
    <zipCode>shippingZipCode</zipCode>
    <city>shippingCity</city>
    <state>state</state>
    <country>Netherlands</country>
    <countryCode>NL</countryCode>
</address>

Curl
curl -v -d "externalOrderId={externalOrderId}&emailAddress=marcel@peecho.com&shippingAddressXml=<?xml version='1.0'?><address><firstName>recipientFirstName</firstName><lastName>recipientLastName</lastName><addressLine1>shippingAddressLine1</addressLine1><addressLine2>shippingAddressLine2</addressLine2><zipCode>shippingZipCode</zipCode><city>shippingCity</city><country>Netherlands</country><countryCode>NL</countryCode></address>" "http://www.peecho.com/rest/order/details"

Response

If all went well, this service will only respond with the string 'OK'.

 

5. Confirm payment
The last step is the payment confirmation. Typically, the API method should be called after you received confirmation from the payment provider. The moment you call this API method, we will start processing your order (costs of the print will be substracted from your balance).

POST /rest/order/set_paid

Set an order as paid. This is required if you use your own payment procedure.

Request

curl -v -d "externalOrderId={yourExternalOrderId}&merchantApiKey={yourMerchantApiKey}&secret={generatedSecretHash}" "http://www.peecho.com/rest/order/set_paid"
Java
String secretKey = "merchantSecretKey";
String merchantApiKey = "merchantApiKey";
String externalOrderId = "1234";
String data = merchantApiKey + externalOrderId;
Mac m = Mac.getInstance("HmacSHA1");
m.init(new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA1"));
byte[] hash = m.doFinal(data.getBytes("UTF-8"));
String secret = new String(Base64.encodeBase64(hash));

/*
You get as result: LmzDnZGhdSI3D3aWXrQNcY0GDqI=

(using org.apache.commons.codec.binary for base64 and javax.crypto for Mac).
*/

Response

This service either returns 'ERROR' or 'OK'.

 

After completing these simple steps, your order will be processed, printed and shipped. Next time you want to print the same file, you can skip first step.

If you need help integrating the Print API, contact support@peecho.com