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:
- Sign Up:
- Visit PrintNode and sign up for an account
- Download and Install the PrintNode Client:
- Go to the "Downloads" section in the left-hand menu
- Download the client for your operating system and run the installer, it should detect your printer automatically
- Under the "Printers" tab, you should see the ID of your printer. Copy this ID for later use
- Use the "Print Something" option in the left-hand menu to print out a test page, to make sure everything works correctly
- Create the API Key:
- Click on the “API Keys” button in the top menu to navigate to the "API" section
- Click on the option to create a new API key and follow the prompts (screenshot)
- 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:
- Sign Up:
- Go to CodeUpify and create an account
- Create a Function: (screenshot)
- Name: Enter "Shopify Automatic Printer"
- Description: Enter "Uses Webhooks and PrintNode API to automate printing of new Shopify orders"
- Language: Select "python"
- Image: Select "python:3.12.1-slim"
- Concurrency: Choose "async"
- 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
- Packages:
- Select "requests" to enable API queries from our code
- Select "fpdf2" to enable text to PDF conversion
- Create Function: Click on the "Create" button
- Add the Code: (screenshot)
- Copy the code provided in this Github file
- Paste it into the code editor in CodeUpify
- Click "Save" to store your function.
- Copy the Webhook URL:
- 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:
- Navigate to Webhooks:
- Go to Settings > Notifications (screenshot)
- Scroll down to the "Webhooks" section and click on "Create webhook"
- Create a Webhook :
- Event: Select Order creation
- Format: Choose JSON
- URL: Paste the URL you copied from the CodeUpify function setup
- Save the Webhook:
- Click the "Save webhook" button to create the webhook
- Test the Webhook: (screenshot)
- 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
- 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.