Image for Automatic Shopify Order Printing Using Webhooks

Automatic Shopify Order Printing Using Webhooks

Many Shopify apps offer comprehensive solutions for automating various aspects of your e-commerce operations, including order printing. However, these all-in-one tools can be expensive and often come with features you may not need. If you’re looking for a straightforward and budget-friendly way to automatically print your Shopify orders, using webhooks and PrintNode might be the perfect solution. We'll guide you through a point-and-click process, making it accessible for non-developers, while also offering flexibility for more advanced use cases later on.

Setting up PrintNode

PrintNode is a cloud printing service that allows you to send print jobs to your printers from anywhere. PrintNode has an inexpensive API that we will use to communicate with your printer. At this time PrintNode starts at $1.80 for 1,000 prints, and the price goes down as the number of prints goes up.

You will need to sign up for an account and get an API key:

  1. Sign Up:
    1. Visit PrintNode and sign up for an account
  2. Download and Install the PrintNode Client:
    1. Go to the "Downloads" section in the left-hand menu
    2. Download the client for your operating system and run the installer, it should detect your printer automatically
    3. Under the "Printers" tab, you should see the ID of your printer. Copy this ID for later use
    4. Use the "Print Something" option in the left-hand menu to print out a test page, to make sure everything works correctly
  3. Create the API Key:
    1. Click on the “API Keys” button in the top menu to navigate to the "API" section
    2. Click on the option to create a new API key and follow the prompts (screenshot)
    3. Save the API key for the next section

Configure a Webhook Listener

To automate the printing of Shopify orders, we will use CodeUpify, a straightforward serverless function service that allows us to easily create webhook endpoints. CodeUpify charges based on usage, similar to other serverless services, and the costs should be very low - on the order of less than a dollar for a few thousand print jobs. Here's how to get started:

  1. Sign Up:
    1. Go to CodeUpify and create an account
  2. Create a Function: (screenshot)
    1. Name: Enter "Shopify Automatic Printer"
    2. Description: Enter "Uses Webhooks and PrintNode API to automate printing of new Shopify orders"
    3. Language: Select "python"
    4. Image: Select "python:3.12.1-slim"
    5. Concurrency: Choose "async"
    6. Environment Variable:
      • Add variable PRINTNODE_API_KEY and use the key you generated from PrintNode as the value
      • Add variable PRINTNODE_PRINTER_ID and use the printer ID that you got from the PrintNode desktop app
    7. Packages:
      • Select "requests" to enable API queries from our code
      • Select "fpdf2" to enable text to PDF conversion
    8. Create Function: Click on the "Create" button
  3. Add the Code: (screenshot)
    1. Copy the code provided in this Github file
    2. Paste it into the code editor in CodeUpify
    3. Click "Save" to store your function.
  4. Copy the Webhook URL:
    1. After saving, copy the URL displayed at the top of the page. This URL will be used in the next section to configure Shopify Webhooks

Shopify Webhooks

To complete the setup, we need to configure a webhook in Shopify that triggers whenever a new order is created. This webhook will send order details to the URL we set up in CodeUpify. Follow these steps:

  1. Navigate to Webhooks:
    1. Go to Settings > Notifications (screenshot)
    2. Scroll down to the "Webhooks" section and click on "Create webhook"
  2. Create a Webhook :
    1. Event: Select Order creation
    2. Format: Choose JSON
    3. URL: Paste the URL you copied from the CodeUpify function setup
  3. Save the Webhook:
    1. Click the "Save webhook" button to create the webhook
  4. Test the Webhook: (screenshot)
    1. Place a test order in your Shopify store to ensure the webhook is triggering correctly and that the order details are being sent to your CodeUpify function
    2. You can look in CodeUpify → Logs to see if there are any errors or if the function ran successfully

Flexibility

With the flexibility of custom code, you can tailor the solution to fit your specific requirements. For example, you can update the code to exclude POS purchases (check out this Github code). Customizations can be simple, like modifying the print template, or more complex, like integrating third-party APIs to fetch extra details or trigger additional workflows.

Conclusion

That’s it! You should now have a fully automated system for printing Shopify orders using webhooks and PrintNode. This setup provides an affordable and efficient way to streamline your order fulfillment process without relying on expensive third-party apps. If you encounter any issues or have additional questions, please don't hesitate to reach out to us using the Contact page.