Powerful Custom Solutions with Printify’s API
What is an API?
According to IBM the API definition is:
“An application programming interface, or API, enables companies to open up their applications’ data and functionality to external third-party developers, business partners, and internal departments within their companies.
This allows services and products to communicate with each other and leverage each other’s data and functionality through a documented interface.”
The API in Simple Terms
Simply put, an API is a messenger that takes your request and its details, communicates it to a system and brings back a response to you with the specific data you need.
The Restaurant Analogy
To further simplify the above definition, it’s useful to look at the classic restaurant analogy.
Let’s assume you’re at your favorite pizza restaurant and you’d like to order a pizza. Now, you cannot go into the kitchen and start cooking it yourself.
What will happen is that you will take a look at the menu, find the item you need with the ingredients you like, and give your order to the waiter. Your order is your request.
The waiter (the API), then heads back to the kitchen (the system), passes your order (your request) down to the professional cooking staff and a while later, returns with the pizza you ordered (data in need).
An API Example in Real Life
APIs are utilized almost everywhere in our daily internet interactions. One of the most common examples is when you’re booking your flight via a website such as Kayak, Expedia, or Scyscanner.
When you’re on a flight-booking website, you’d like to see all available flights. So you input details such as flight date, destination, round or one-way trip and you hit “Search”.
Once you hit the search button, an API will take your request and its details, communicate with all the airlines and return a list of available flights that match your needs.
This way you don’t have to go into each airline’s unique website and search for matching flights.
Technical Applications - Use Cases
In this section, we go over several applications of Printify’s API that you can use in your own online business to further its capabilities.
Below, you can find the explanation of each use case as well as sample codebases that can give a developer some insight on how the Printify API can be practically applied.
Feel free to share this information with an API Developer if you’d like to see how to implement these solutions to your store.
Order Management/Routing sample code
If you’re managing several stores at once, and/or have a large order volume, you can use an API to route your order traffic in whichever direction you need and get all that data in a single place for improved monitoring and management.
In short, managing orders becomes easier with API.
To do that, we build up a standard HTTP client with OAuth and add your shop as the order endpoint.
We will return the 10 latest orders to call for another page with the next link.
If you want to get only fulfilled orders, add a query parameter for status=fulfilled to the request.
The returned orders will contain everything needed for their analysis or routing into your custom system.
Below is the sample codebase on how to achieve this functionality in PHP:
class PrintifyOrders {
public function __construct(private \GuzzleHttp\Client $client, private string $accessToken) {}
public function getShopOrders(int $shopId, bool $fulfilled = false): array {
$orders = [];
$endpointUrl = "/v1/shops/$shopId/orders.json";
$options = [
'headers' => ['Authorization' => 'Bearer '.$this->accessToken],
'query' => ['page' => 1] + ($fulfilled ? ['status' => 'fulfilled'] : []),
];
do {
[$newOrders, $nextPage] = $this->parseResponse($this->client->get($endpointUrl, $options));
foreach ($newOrders as $order) {
$orders[] = $order;
}
$options['query']['page'] = $nextPage;
} while (null !== $nextPage);
return $orders;
}
private function parseResponse(\Psr\Http\Message\ResponseInterface $response): array {
$data = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
return [$data['data'], $data['current_page'] < $data['last_page'] ? $data['current_page'] + 1 : null];
}
}
class OrdersManager {
public function __construct(private PrintifyOrders $printifyOrders) {}
public function customAnalysis(int $shopId): void {
$orders = $this->printifyOrders->getShopOrders($shopId, fulfilled: true);
foreach ($orders as $order) {
// custom analysis script
}
}
}
class OrdersRouter {
public function __construct(private \GuzzleHttp\Client $client, private PrintifyOrders $printifyOrders) {}
public function routeOrders(int $shopId, string $route): void {
$orders = $this->printifyOrders->getShopOrders($shopId);
foreach ($orders as $order) {
$this->client->post($route, ['body' => json_encode($order, JSON_THROW_ON_ERROR)]);
}
}
}
Product Management sample code
Are you moving a large portfolio of designs to Printify or maybe you’re aiming to simultaneously launch a new collection of products on top of your existing product line?
Then using API to carry out this process would save you the time and hassle of completing a number of steps manually, while limiting the chance for errors.
You have to call just a few endpoints for changing designs on multiple products.
First, you have to upload your new design and store its unique ID.
Then for each of the products you want to change the design, you have to update their print area placeholders.
If you’re satisfied with the changes, you can publish the product changes to your store.
Below is the sample codebase how to achieve this functionality in PHP:
class PrintifyClient
{
public function __construct(private \GuzzleHttp\Client $client, private string $accessToken) {}
public function request(string $method, string $uri = '', array $data = []): array {
$options = ['headers' => ['Authorization' => 'Bearer '.$this->accessToken]];
if (!empty($data)) {
$options['json'] = $data;
}
$response = $this->client->request($method, $uri, $options);
return json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
}
}
class PrintifyImage
{
public function __construct(private PrintifyClient $client) {}
public function uploadImage(string $filename, string $url): string {
$data = $this->client->request('POST', '/v1/uploads/images.json', ['file_name' => $filename, 'url' => $url]);
return $data['id'];
}
}
class PrintifyProduct
{
public function __construct(private PrintifyClient $client) {}
public function replaceImage(int $shopId, string $productId, string $imageId): void {
$productUri = "/v1/shops/$shopId/products/$productId.json";
$data = $this->client->request('GET', $productUri);
$data['print_areas'][0]['placeholders'][0]['images'][0]['id'] = $imageId;
$this->client->request('PUT', $productUri, $data);
}
public function publishProduct(int $shopId, string $productId): void {
$data = ['title' => true, 'description' => true, 'images' => true, 'variants' => true, 'tags' => true];
$this->client->request('POST', "/v1/shops/$shopId/products/$productId/publish.json", $data);
}
}
Product Information Export sample code
As any business, you need to make decisions based on data.
With an API solution, Printify can offer you access to as much low-level data as possible. This way, you can analyze it all and determine the best course of action for continued business growth and success of your ideas.
To export product-related information about orders, you can call the order endpoints with your product SKU as a query filter.
Returned data will contain all orders with at least one product with passed SKU.
Next, you can filter out the unneeded products and export that data to a CSV file that contains all the information about the order, product, potential sales and delivery information.
Below is the sample codebase how to achieve this functionality in PHP:
class PrintifyProductOrders {
public function __construct(private \GuzzleHttp\Client $client, private string $accessToken) {}
public function getShopOrdersForProduct(int $shopId, string $sku): array {
$orders = [];
$endpointUrl = "/v1/shops/$shopId/orders.json";
$options = [
'headers' => ['Authorization' => 'Bearer '.$this->accessToken],
'query' => ['page' => 1, 'sku' => $sku],
];
do {
[$newOrders, $nextPage] = $this->parseResponse($this->client->get($endpointUrl, $options));
foreach ($newOrders as $order) {
$orders[] = $order;
}
$options['query']['page'] = $nextPage;
} while (null !== $nextPage);
return $this->filterProductsWithSku($orders, $sku);
}
private function parseResponse(\Psr\Http\Message\ResponseInterface $response): array {
$data = json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
return [$data['data'], $data['current_page'] < $data['last_page'] ? $data['current_page'] + 1 : null];
}
private function filterProductsWithSku(array $orders, string $sku): array {
foreach ($orders as $orderIndex => $order) {
foreach ($order['line_items'] as $itemIndex => $item) {
if ($sku !== $item['metadata']['sku']) {
unset($orders[$orderIndex]['line_items'][$itemIndex]);
}
}
}
return $orders;
}
}
class ProductInformationExport {
public function __construct(private PrintifyProductOrders $printifyOrders) {}
public function export(string $filename, int $shopId, string $sku): void {
$orders = $this->printifyOrders->getShopOrdersForProduct($shopId, $sku);
$file = fopen($filename, 'wb');
fputcsv(
$file,
[
'shop_id',
'sku',
'order_id',
'quantity',
'shipping_cost',
'cost',
'price',
'sold',
'shipments_carrier',
'country',
'city',
'email',
'phone',
'created_at',
'sent_to_production_at',
'fulfilled_at',
]
);
foreach ($orders as $order) {
$item = current($order['line_items']);
fputcsv($file,
[
$shopId,
$sku,
$order['id'],
$item['quantity'],
$item['shipping_cost'],
$item['cost'],
$item['metadata']['price'],
'fulfilled' === $item['status'] ? 'YES' : 'NO',
$order['shipments']['carrier'] ?? '',
$order['address_to']['country'],
$order['address_to']['city'],
$order['address_to']['email'],
$order['address_to']['phone'],
$order['created_at'],
$item['sent_to_production_at'] ?? '',
$item['fulfilled_at'] ?? '',
]
);
}
fclose($file);
}
}
Make It Happen Today!
Keep Exploring Our Blog
Written by
Printify
Share the article
Topics
28 comments
Hi all, I’ve tried to contact your support through a suspiciously looking form that gave no feedback at the end ) Does that mean that I’ll receive the answers at the email I provided?
Hi Yuriy!
To get in touch with our support team, please follow this guide.
Hi Martha, I’m having trouble using the v1/shops/{shop_id}/products.json endpoint (see error message below). Any idea where I can find some assistance to fix that ?
{“status”:”error”,”code”:8150,”message”:”Validation failed.”,”errors”:{“reason”:”print_areas.1.placeholders: The print_areas.1.placeholders field is required.”,”code”:8150}}
(My post body has a print_area.placeholders field)
Hi Alan,
Please reach out to [email protected] regarding this, as they are best equipped to help you sort this out.
Instead of creating a design on Printify and then hooking that up to your storefront, is it possible to go the other way? Create the designs elsewhere and then pass the design to Printify via API? Ideally would only like to create the product in Printify once it has been ordered from the storefront.
Hi Chris,
That’s exactly how Printify works – you connect Printify to your store, sell the designed products on your store. Once a customer will place the order, only then Printify will fulfill it and ship it directly to your customer. Feel free to check out our Help Center for more information.
How can I sell items from multiple vendors on my Squarespace site? i.e. Printify for hats/shirts, etc. and other vendors for items you don’t carry like glassware. Is that an API solution?
Hey,
You can certainly sell Printify products to your Squarespace site alongside products from other vendors. No need to use API to achieve this. What you need to do is integrate your Squarespace site to Printify, create and publish a product and don’t forget to set up shipping.
When an order syncs to Printify and if that order contains a mix of Printify products and products from your other vendors, our system will remove the non-Printify products.
Unfortunately, we can’t speak in behalf of your other vendors if they allow selling their products alongside our products. We recommend reaching out to their support team.
Hello
I am thinking of integrating a t-shirt store on my site. The idea I have is that the t-shirt designs (with phrases) are generated automatically (on the fly) via API and then users can purchase them on the fly.
I don’t know if you offer this service, I would like it to be a dropshiping service.
Is this possible with Printify?
Thank you very much
Hi Daniel,
The way Printify works is, that you add your designs to shirts on our platform, connect Printify to your site and when a customer will buy them, Printify will automatically produce and ship directly to your customer.
Hi, is there any article links where integration with Angular is taught? I would love to sell your products to my own website. Please direct me to some article tutorial that help me with this please.
Hi Jules,
You can check out how to integrate Printify API, here.
hi, how can i set up a link to a Printify product so I can sell it on Pinterest?
Hi Jade,
This article might be helpful. In case any other questions arise, do not hesitate reaching out to our Support team via 24/7 live chat on your Printify account or you can also fill out a form here.
Is there an EASY way to transfer my Printful inventory to my business website inventory? Does Printify have a program/fee to help with this? Thank you.
Hi there!
Yes, please see more information here. In case any other questions arise, feel free to get in touch with our Support team here or via 24/7 live chat on your Printify account.
Do I need an external shop to connect to printify? It looks like everything needed for ordering is already there since I can do sample or bulk orders without linking to an external marketplace. So why isn’t there a way for the public to directly buy from my printify site without linking it to anything?
Hi there,
At the moment, Printify does not provide a storefront, therefore your customers cannot purchase products directly from the Printify account. However, you can sell on any other site, store platform, or social media pages, without linking your Printify account, but rather, for example, placing manual orders using .csv files.
Hi,
I am developing a Online Shopping Mobile App independent of Third Party providers like Shopify, Wix, etc.
Does the API allow the seamless integration for Product info, inventory and Payments from APP?
Hi there,
We don’t offer API as “plugin” code, so this may not be as seamless as you may expect. But you can find all the information here, and if you have any specific questions and need assistance, please reach out to our merchant support team via the live chat on our website.
Hi team, I’m interested in using your API so that it will automatically place a QR code on one of my products based on the affiliate tracking code of the person who ordered to begin with. Ideally I would like to avoid creating a bunch of duplicate products and instead you see API so that it’s simply use as a QR code overlay on top of each new order. I’d like to automate this process if possible, can this be done?
Hi Aaron,
Unfortunately, that won’t be possible. You will need to create a new product for each new QR code. If you need further assistance, please do not hesitate to reach out to our merchant support team via the live chat on our website.
How do I connect to my Shopify
Hi Tiffany,
You can check out this Help Center article here for more detailed instructions on how to integrate your Shopify store with Printify.
Hello there..
Please can I connect my printify store to my printful through API?
Hi Bob,
I’m afraid that most likely this is not possible via API. You can reach out to our merchant support team via the chat feature to look for possible alternative workarounds.
The information Was indeed Helpful
Hi there Lizzy,
Happy to hear that you liked the article!