Tutorial: Easiest Way to Integrate Your Custom Website with Printful

Printful logo

So we are reviewing at UltimateWB how to integrate with Printful, to possibly include as a built-in feature, and we are accepting feedback now on what features you would like in the integration. Here’s some info on possibilities, with the Printful API.

Integrating your custom website with Printful is a fantastic way to offer print-on-demand products to your customers without handling inventory or shipping. Printful allows you to create custom products and automatically fulfill orders on your website.

In this tutorial, we will walk you through the easiest way to integrate Printful into your custom website. The method we’ll use involves Printful’s API to connect your store and automate the process of syncing products and processing orders.

Step 1: Create a Printful Account

If you haven’t already, start by creating a Printful account:

  1. Go to Printful.
  2. Click on Sign Up and follow the instructions to create your account.

Once you’re signed up, you can access the dashboard to manage your products, orders, and integrations.

Step 2: Set Up a Custom Website

You’ll need to have your custom website already set up. If you’re building your own site, it’s likely you’re using a combination of HTML, CSS, JavaScript, and a backend technology like PHP, Python, or Node.js, along with a database like MySQL. UltimateWB website builder uses PHP and MySQL for the backend.

Ensure that your website is capable of handling product pages, shopping cart functionality, and receiving orders.

Step 3: Understand Printful API

Printful provides a REST API that allows you to manage products, sync orders, and track shipments directly from your website.

  • API Documentation: You can find the Printful API documentation on their website. This documentation includes endpoints for products, orders, and fulfillment.
  • Authentication: You’ll need an API key to interact with the Printful API. This can be found in your Printful dashboard by navigating to Settings > API. Generate an API key and store it safely.

Step 4: Connect Your Website to Printful API

To connect your website to Printful’s API, follow these steps:

a. Generate the API Key

  1. Log in to Printful.
  2. Go to Settings > API.
  3. Generate an API key.

This API key will be used to authenticate requests between your website and Printful.

b. Make API Requests

You’ll need to set up your website to interact with Printful’s API. In this example, we’ll use PHP to make requests, but the same logic applies for other languages.

Here’s a simple example using PHP to get your store’s information:

<?php
$api_key = 'YOUR_API_KEY_HERE';
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.printful.com/store');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $api_key
));

$response = curl_exec($ch);
curl_close($ch);

$store_info = json_decode($response, true);
print_r($store_info);
?>

This script sends a request to Printful’s /store endpoint and returns your store information. You can use similar requests for products, orders, and fulfillment.

c. Sync Products

To display products from Printful on your website, use the /products API endpoint.

Here’s an example of fetching your products:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.printful.com/products');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $api_key
));

$response = curl_exec($ch);
curl_close($ch);

$products = json_decode($response, true);

// Display the products on your site
foreach ($products['result'] as $product) {
echo '<h2>' . $product['name'] . '</h2>';
echo '<img src="' . $product['thumbnail_url'] . '" alt="' . $product['name'] . '">';
echo '<p>Price: ' . $product['price'] . '</p>';
}

This will output the list of products available in your Printful store, including their names, images, and prices.

d. Process Orders

When a customer places an order on your site, you can use the Printful API to send that order for fulfillment. Here’s how to create an order programmatically using the /orders endpoint:

$order_data = array(
'recipient' => array(
'name' => 'John Doe',
'address1' => '123 Street',
'city' => 'Los Angeles',
'state_code' => 'CA',
'country_code' => 'US',
'zip' => '90001'
),
'items' => array(
array(
'variant_id' => 4011, // Get this ID from Printful product catalog
'quantity' => 1
)
)
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.printful.com/orders');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($order_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $api_key,
'Content-Type: application/json'
));

$response = curl_exec($ch);
curl_close($ch);

$order_response = json_decode($response, true);
print_r($order_response);

This will send an order to Printful for fulfillment. You will need to replace the recipient details and variant_id with dynamic data from your website’s checkout form.

Step 5: Handle Webhooks for Order Status

To keep your customers informed about their order status, you can use Printful’s Webhooks feature. Webhooks allow Printful to send real-time updates (e.g., order fulfilled, shipped) to your website.

  1. Set up a webhook URL on your website to receive notifications from Printful.
  2. Register the Webhook in Printful’s API by sending a request to the /webhooks endpoint.

Example of registering a webhook:

$webhook_data = array(
'url' => 'https://yourwebsite.com/printful-webhook',
'types' => array('package_shipped', 'order_fulfilled')
);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.printful.com/webhooks');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($webhook_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $api_key,
'Content-Type: application/json'
));

$response = curl_exec($ch);
curl_close($ch);

$webhook_response = json_decode($response, true);
print_r($webhook_response);

Now, when a Printful order is shipped or fulfilled, Printful will send updates to your webhook, which you can then display to customers.

Step 6: Test Everything

Before launching, thoroughly test the integration:

  • Test product sync: Ensure all products are displayed correctly on your website.
  • Test order processing: Place a test order to see if it’s submitted correctly to Printful.
  • Test webhooks: Verify that order updates are properly sent from Printful and processed by your website.

Step 7: Launch and Promote Your Store

Once the integration is complete and tested, you can launch your website. Promote it through social media, email marketing, and SEO to attract customers.

In Summary

Integrating Printful with your custom website is straightforward using their API. This allows you to automate the process of displaying products, submitting orders, and tracking fulfillment without manual intervention. With the right implementation, you can offer a seamless shopping experience for your customers, with all the benefits of print-on-demand fulfillment.

By following the steps in this guide, you’ll have your website up and running with Printful, ready to sell custom products and scale your business.

Want this as a built-in feature in UltimateWB? Please contact us and provide your feedback on what features and any specifics regarding setup that you would like.

Are you ready to design & build your own website? Learn more about UltimateWB! We also offer web design packages if you would like your website designed and built for you.

Got a techy/website question? Whether it’s about UltimateWB or another website builder, web hosting, or other aspects of websites, just send in your question in the “Ask David!” form. We will email you when the answer is posted on the UltimateWB “Ask David!” section.

This entry was posted in Ask David!, Business and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *