Your friendly helper for building print-on-demand apps
To install the package, run:
npm install pressmatic
pnpm add pressmatic
bun add pressmatic
First, you need to configure the client with your Printify API key and endpoint:
import { PressmaticClient, PressmaticConfig } from "pressmatic";
const config: PressmaticConfig = {
apiKey: "your-api-key",
endpoint: "https://api.printify.com/v1",
};
const client = new PressmaticClient(config);
Get a paginated list of products:
const products = await client.getProducts("shopId", { page: 1, limit: 10 });
console.log(products);
Get details of a single product:
const product = await client.getProduct("shopId", "productId");
console.log(product);
Publish a product to your store:
await client.publishProduct("shopId", "productId");
console.log("Product published");
Mark a product as successfully published:
await client.setPublishingSucceeded(
"shopId",
"productId",
"product-handle",
"external-id"
);
console.log("Publishing status updated");
Create a new order:
const orderData = {
id: "orderId",
address_to: {
first_name: "John",
last_name: "Doe",
email: "[email protected]",
country: "US",
address1: "123 Main St",
city: "New York",
zip: "10001",
},
line_items: [
{
product_id: "productId",
variant_id: 1,
quantity: 2,
},
],
shipping_method: 1,
send_shipping_notification: true,
status: "pending",
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
};
const order = await client.createOrder("shopId", orderData);
console.log(order);
Create a new order with a product ID:
const order = await client.createOrderWithProductId(
"shopId",
"external-order-id",
"Order Label",
[
{
product_id: "productId",
variant_id: 1,
quantity: 2,
},
],
1, // shipping method
{
first_name: "John",
last_name: "Doe",
email: "[email protected]",
country: "US",
address1: "123 Main St",
city: "New York",
zip: "10001",
},
false, // isPrintifyExpress
false, // isEconomyShipping
true // sendShippingNotification
);
console.log(order);
Create a new order with SKU:
const order = await client.createOrderWithSKU(
"shopId",
"external-order-id",
"Order Label",
[
{
sku: "product-sku",
quantity: 2,
},
],
1, // shipping method
{
first_name: "John",
last_name: "Doe",
email: "[email protected]",
country: "US",
address1: "123 Main St",
city: "New York",
zip: "10001",
}
);
console.log(order);
Get details of an existing order:
const orderDetails = await client.getOrderDetails("shopId", "orderId");
console.log(orderDetails);
Update an existing order:
const updatedOrder = await client.updateOrder("shopId", "orderId", {
status: "completed",
});
console.log(updatedOrder);
Delete an order:
await client.deleteOrder("shopId", "orderId");
console.log("Order deleted");
Get shipping options for a product:
const shippingOptions = await client.getShippingOptions("shopId", "productId");
console.log(shippingOptions);
Get the shipping cost for a order:
const shippingCost = await client.getShippingCost(
"shopId",
[
{
product_id: "productId",
variant_id: 1,
quantity: 2,
},
],
{
first_name: "John",
last_name: "Doe",
email: "[email protected]",
country: "US",
address1: "123 Main St",
city: "New York",
zip: "10001",
}
);
console.log(shippingCost);
The client uses a central request handler with error management. If an error occurs, it throws a PrintifyError
:
try {
const products = await client.getProducts("shopId");
} catch (error) {
if (error instanceof PrintifyError) {
console.error(`Error: ${error.message}, Status Code: ${error.statusCode}`);
} else {
console.error("Unknown error occurred");
}
}
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request.
Special thanks to the Printify team for their API.
This package is maintained by 10d3.