This article is the third installment in our series on automating procurement for your Shopify store. In previous parts, we laid the groundwork for building a robust automated system from scratch. We first explored how to monitor inventory levels using a simple integration between Shopify and Airtable, ensuring you always have a clear picture of your stock.
Following that, we introduced solutions for automatically sending product and vendor information to QuickBooks once inventory levels hit predefined thresholds. This laid the foundation for seamless financial record-keeping. Now, we're ready to dive into the core of the process: automatically generating and dispatching purchase orders to the correct vendors as soon as product quantities reach critical levels.
Purchase Order Automation: An Overview of the Process
In this tutorial, we will construct a Make.com scenario designed to automatically create purchase orders and send them directly to your suppliers. This automation is crucial for maintaining optimal stock levels and ensuring your Shopify store runs efficiently without manual intervention for reordering.
The scenario operates in a straightforward manner. It begins by scanning your inventory for items that meet specific reorder criteria. Once identified, it intelligently groups these items by supplier to consolidate orders, preventing multiple purchase orders for the same vendor. Finally, it generates and emails the consolidated purchase orders.
To achieve this, our Make.com scenario will leverage several key modules:
- Airtable > Search Records
- Array Aggregator
- Iterator
- Quickbooks > Create a Purchase Order
- Quickbooks > Make an API call
- Quickbooks > Get a Vendor
- Gmail > Send an email
- Airtable > Update a Record
It's important to note that this tutorial is part of a larger series. In the upcoming and final segment, we will explore how to manage incoming invoices from suppliers, route them to your finance department, and update your inventory records once items have been received. For now, let's focus on getting those purchase orders out the door automatically!
Step 1: Retrieving Items That Reach Certain Inventory Levels
In the second part of this series, we introduced the concept of "rotation frequency" for each inventory item, which is a critical component of this automation. This frequency determines the reorder point for each product, ensuring that high-demand items are replenished more proactively than slower-moving ones.
To recap, our demo uses the following frequency definitions:
- High: A purchase order is automatically generated when the item's quantity falls below 50% of its maximum stock level.
- Medium: A purchase order is automatically generated when the item's quantity falls below 20% of its maximum stock level.
- Low: No automatic purchase order is sent. These items typically require manual review, or you might choose to adjust their frequency or eventually remove them from your store.
Our first task is to configure the automation to identify items with a "High" or "Medium" rotation frequency that need to be reordered and have not already been ordered. The "Ordered" field, which we'll discuss later, plays a crucial role in preventing duplicate orders.
Begin by creating a new scenario within your Make.com dashboard. Once you're in the visual builder, add an "Airtable > Search Records" module. Configure this module to connect to your "Shopify Inventory" base and select the "Inventory" table. This module will be responsible for fetching the relevant product data.
To filter for items that meet our reorder criteria, paste the following formula into the configuration box. This formula checks for items with either a 'High' or 'Medium' rotation that are below their respective reorder thresholds and have not yet been marked as 'Ordered':
OR((AND(({Quantity} < {Maximum Quantity for item} *0.5), ({Ordered} = 0), ({Rotation} = 'High'))),(AND(({Quantity} < {Maximum Quantity for item} *0.2), ({Ordered} = 0), ({Rotation} = 'Medium'))))
You can easily adjust the percentages (0.5 for 50%, 0.2 for 20%) in the formula to align with your specific inventory management policies. Additionally, remember to increase the "Limit" field in the module's settings to ensure all relevant records are retrieved during each scenario execution; the default of 10 records is often insufficient for larger inventories.
Once the initial item records have been successfully retrieved, the next logical step is to fetch the corresponding supplier information for these items. This is crucial because a single vendor often supplies multiple products to your store. Our goal is to consolidate all items from one vendor into a single purchase order, rather than sending a separate order for each individual item.
Consider this example: if Supplier 1 provides both Product A and Product B, we want to generate one purchase order for Supplier 1 that includes both A and B. Similarly, if Supplier 2 only provides Product C, they would receive a single purchase order for C. This approach optimizes communication and simplifies logistics for both your store and your vendors.
The process to achieve this consolidation involves several steps:
- First, the retrieved vendor IDs are aggregated, merging individual data points into a single, manageable bundle.
- Next, these aggregated items are iterated, meaning they are split into separate parts for individual processing.
- Through this iteration, each vendor is accurately matched with all the specific items you need to order from them.
- Finally, all the items destined for a particular vendor are re-aggregated, ensuring they are combined into a single, comprehensive purchase order ready for dispatch.
Step 2: Aggregating the Data
To begin the data aggregation process, open the "Tools" menu located at the bottom of your Make.com visual builder. From there, drag and drop an "Array Aggregator" module into your scenario. This module is essential for combining multiple pieces of data into a single array, which is particularly useful when dealing with multiple items from the same vendor.
In the configuration panel for the Array Aggregator, simply check the box next to the "Quickbooks Vendor ID" field. This action will instruct the module to collect and group all unique QuickBooks Vendor IDs from the bundles of data it receives. This ensures that you're preparing to process each vendor's orders efficiently.
Once you have configured the Array Aggregator as described, click the "OK" button to save your changes and proceed to the next step in building your automation scenario. This step is crucial for consolidating vendor-specific data before generating purchase orders.
Step 3: Adding Filters
Just as in the previous scenarios we've built, incorporating filters is a vital part of this automation. The primary purpose of these filters is to prevent the scenario from continuing to process if no relevant records are found. This saves unnecessary operations and ensures your automation runs efficiently, only acting when there's actual work to be done.
To add a filter, click on the small wrench icon positioned between your Airtable module and the Array Aggregator module in the visual builder. This will open the filter configuration box.
Within the configuration box, set the condition to "Total number of bundles." For the data operator, select "Greater than" from the dropdown menu, and then enter "0" in the subsequent field. This setup ensures that the scenario will only proceed if there is at least one bundle of data (i.e., at least one item requiring a purchase order) to process. After setting these parameters, click the "OK" button to apply the filter.
Step 4: Iterating the Data
Now, it's time to introduce an "Iterator" module into your scenario. This module is essential for breaking down aggregated data into individual bundles, allowing each piece of information to be processed separately. You can find and add the Iterator from the "Tools" menu at the bottom of the visual builder, much like you did with the Array Aggregator.
The reason for using an Iterator here is straightforward: it's common for multiple items from the same vendor to be retrieved in the initial Airtable search. Consequently, that specific vendor's ID might appear numerous times within the aggregated array. If we were to proceed without addressing this, the vendor could receive multiple identical purchase orders, leading to confusion and potential over-ordering.
To prevent this, we will employ the "deduplicate" function. This powerful function, found within the "Functions for working with arrays" menu, will ensure that each vendor ID is processed only once. To configure it, map the "Array[]" element and then insert "Quickbooks Vendor ID" within the brackets, as illustrated in the screenshot below. This setup guarantees that your automation sends a single, consolidated purchase order per vendor, even if they supply many items.
Once you have correctly configured the Iterator module with the deduplicate function, click the "OK" button to save your settings. This step is crucial for ensuring that your purchase orders are efficiently consolidated and that each vendor receives only one comprehensive order, streamlining your procurement process.
Step 5: Matching the Vendors to Their Items
With the Iterator now in place, vendor IDs will flow through the scenario one at a time, allowing for individual processing. This enables us to precisely match each vendor with all the specific items you need to order from them, ensuring accuracy and efficiency in your purchase orders.
To achieve this matching, you'll need to add another "Airtable > Search Records" module to your scenario. This module will perform a targeted search within your inventory based on the vendor ID currently being processed by the Iterator.
In the configuration box for this new Airtable module, paste the following formula. Crucially, you must map the "Quickbooks Vendor ID" element, which is outputted by the Iterator, directly into the quotation marks ("") within the formula. This dynamic mapping ensures that the search is always performed for the correct vendor:
OR((AND(({Quantity} < {Maximum Quantity for item} *0.5), ({Ordered} = 0), ({Rotation} = 'High'), ({Quickbooks Vendor ID} = ""))), (AND(({Quantity} < {Maximum Quantity for item} *0.2), ({Ordered} = 0), ({Rotation} = 'Medium'), ({Quickbooks Vendor ID} = ""))))
As a reminder, if you adjusted the reorder percentages in the initial Airtable search module, make sure to apply those same percentage changes here to maintain consistency across your automation. This ensures that the criteria for identifying items to order remain uniform throughout the workflow.
Step 6: Creating the Purchase Order and Aggregating the Items
You've now arrived at the most critical phase of our entire automation series: the automatic creation of purchase orders. This is where all the previous steps converge to generate the necessary documents for your suppliers. The primary objective here is to aggregate all the items destined for a single vendor into one comprehensive purchase order, which is essential for efficient communication and logistics.
To achieve this, add another "Array Aggregator" module to your scenario. For its "Source Module," select the "Airtable > Search Records" module that you configured in the previous step. This ensures that the aggregator processes the items already matched to a specific vendor.
It's crucial that the structure of the array produced by this aggregator aligns perfectly with the expected structure of a QuickBooks purchase order. This alignment is what will allow us to seamlessly map the data in the subsequent module. However, you might notice that under the "Target structure type" option, only "Custom" is initially available, which isn't what we need for direct QuickBooks integration.
To make the correct QuickBooks purchase order structure available, you'll first need to add and configure the "Quickbooks > Create a purchase order" module. Once that module is set up, you can then return to the Array Aggregator's "Target structure type" menu, and the appropriate QuickBooks option will appear. Let's proceed with configuring the QuickBooks module first, and then we'll circle back to finalize the Array Aggregator.
After adding the "Quickbooks > Create a purchase order" module immediately following your second Array Aggregator, configure it with the following settings:
- Select the appropriate "AP Account" from your QuickBooks setup.
- Enable the map switches for the two fields below, which allows for dynamic data mapping.
- Map the "Quickbooks Vendor ID" element to the "Vendor" field. This links the purchase order to the correct supplier in QuickBooks.
- Map the "Array[]" element (from the Array Aggregator) to the "Lines" field. This is where all the aggregated item data for the purchase order will be placed.
Once you've completed these mappings, click the "OK" button to save the QuickBooks module's configuration. Now, you can reopen the second Array Aggregator module. In its configuration box, you should now see and be able to select the "Quickbooks > Create a purchase order Lines" option from the "Target structure type" list. This ensures the data is formatted correctly for QuickBooks.
Now, let's proceed with mapping the data to the fields that appear below in the Array Aggregator. To accurately calculate the amount for each line item, you'll use the "sum" function from the "Math functions" available in Make.com. Within this function, you'll perform the following operations:
- Map the "Maximum Quantity for item" element, which is outputted by the previous "Search records" module.
- Subtract the current "Quantity" on hand using the "subtraction" operator. This calculates the quantity needed for reorder.
- After closing the bracket for the subtraction, multiply the result by the "Unit price" element using the "multiplication" operator. This gives you the total cost for that line item.
Additionally, map the "Variant Name" to the "Description" field of the line item, and ensure you select "Item based" under the "Type" field. This provides clear details for each product on the purchase order. The image below provides a visual guide for these mappings.
Continuing with the configuration of this module, scroll down to complete the remaining fields:
- Map the "Quickbooks Inventory Item ID" element to the "Item" field. This links the product to its corresponding entry in QuickBooks.
- In the "Quantity" field, once again map the "Maximum Quantity for item" element and subtract the current "Quantity" on hand. This ensures the purchase order requests the exact number of units needed to reach your maximum stock level.
- Finally, map the "Unit price" element to the "Unit price" field. This populates the cost per unit for each item on the purchase order.
Congratulations! You have successfully configured both the Array Aggregator and the "Create a purchase order" modules. This is a significant milestone in automating your procurement process.
At this juncture, it's crucial to execute the scenario once. This action will generate a sample purchase order, and more importantly, it will output the "ID" of that order from the "Create a purchase order" module. This ID is vital for the subsequent steps in our automation, particularly for downloading and emailing the purchase order. To trigger this, temporarily change the quantity of one or more items in your Airtable "Inventory" table to "0" and then click "Run once" in Make.com.
Pro tip: When testing, temporarily set an item's quantity to '0' in Airtable and use 'Run once' in Make.com to generate a sample purchase order ID for mapping in subsequent modules.
In the next step, we will leverage this generated ID to download the purchase order and prepare it for emailing to your vendors.
Step 7: Downloading and Emailing the Purchase Orders
Now that your purchase orders are being created, the next essential step is to download them so they can be sent to your vendors. Currently, QuickBooks does not offer a dedicated module within Make.com for directly downloading purchase orders. Therefore, we will use Make.com's versatile "Make an API call" module to achieve this functionality.
Add the "Quickbooks > Make an API call" module to your scenario. In its configuration panel, paste the following into the "URL" field: purchaseorder//pdf. Following this, you must map the "ID" element, which was outputted by the "Quickbooks > Create a purchase order" module after your last scenario execution. This dynamic ID ensures you're requesting the correct purchase order document.
Since the file you are downloading is a PDF, you need to specify this in the module's "Headers" section. Make the following crucial adjustments:
- Change the Value of the "Content-Type" Key to:
application/pdf. This tells the system the format of the content being received. - Add a new item to the headers: set the Key to "accept" and its Value to
application/pdf. This indicates that your system is prepared to accept a PDF response.
With this module configured, the purchase orders will be successfully downloaded. The next step is to retrieve the vendor's email address so you can send the purchase order immediately. To do this, add a "Quickbooks > Get a vendor" module to your scenario. In its configuration, simply map the "Vendor: Value" element from the "Quickbooks > Create a purchase order" module. This ensures you fetch the contact details for the specific vendor associated with the purchase order.
Now it's time to send the email! Add a "Gmail > Send an email" module (or an equivalent email module if you use a different service) to your scenario. This module is generally straightforward to set up.
First, enable the map switch in the "To" field and map the "Primary email address: address" element from the preceding "Quickbooks > Get a vendor" module. This ensures the email is sent to the correct vendor. You might also consider adding your finance department's email to the CC field to keep them informed and maintain a record of all dispatched purchase orders.
For the "Subject line" and "Content" of the email, you have complete flexibility to customize them as needed. You can include details like the purchase order number, expected delivery dates, or any other relevant information for your vendors.
For the most critical part – attaching the generated purchase order – scroll down to the "Attachments" section and click the "Edit" button. Give the attachment a descriptive name, ensuring it ends with ".pdf". A useful tip is to use the "Doc number" element from the QuickBooks module to create a unique and easily identifiable filename for each purchase order.
Finally, map the "Body" element outputted by the "Quickbooks > Make an API call" module to the "Data" field within the attachment settings. This action directly attaches the downloaded PDF of the purchase order to your email. With this, your purchase orders will be created and emailed exactly as intended.
Excellent work! You've successfully configured the automation to create and email purchase orders. There's just one more crucial step to ensure the system functions flawlessly and avoids sending duplicate orders. Let's take a look at how to update the "Ordered" field.
Step 8: Updating the “Ordered” Field
If you've been curious about the "Ordered" field mentioned in the formulas earlier, now is the time to clarify its vital role. This field in your Airtable inventory table is extremely important because it acts as a safeguard, preventing the automation from sending duplicate purchase orders for items that have already been ordered in previous runs.
Essentially, if this field is marked as "Yes" (or ticked), the automation will recognize that a purchase order for that specific item has already been dispatched, and it will not generate a new one. This mechanism is critical for maintaining accurate inventory records and avoiding unnecessary reorders.
After a purchase order for an item has been successfully emailed, the scenario must update the "Ordered" field for that specific item in Airtable. This means setting the field to "Yes" or ticking the box. Conversely, when the ordered items are physically received in your shop, you will need to manually or automatically untick this field in Airtable, making the item eligible for reordering again in the future.
To implement this, add another "Airtable > Search Records" module to your scenario. This module will be used to locate the specific item in your inventory that has just been ordered from the vendor. Use the same formula as before to search for the item, and map the "Vendor ID" as shown in the screenshot below the formula. This ensures you're targeting the correct record for an update:
OR((AND(({Quantity} < {Maximum Quantity for item} *0.5), ({Ordered} = 0), ({Rotation} = 'High'), ({Quickbooks Vendor ID} = ""))), (AND(({Quantity} < {Maximum Quantity for item} *0.2), ({Ordered} = 0), ({Rotation} = 'Medium'), ({Quickbooks Vendor ID} = ""))))
To finalize this step, add an "Airtable > Update a Record" module to your scenario. In its configuration box, map the "ID" element from the previous "Search Records" module to the "Record ID" field. This tells the module precisely which record in Airtable needs to be modified.
Scroll down to the bottom of the configuration options and select "Yes" under the "Ordered" field. This action will mark the item as ordered, preventing it from being reordered in subsequent runs of the scenario until it is manually or automatically unticked upon receipt of the goods.
And that completes the setup for updating the "Ordered" field! Now, let's ensure the entire scenario works as intended by performing a test run.
Step 9: Testing the Scenario
After you have meticulously saved your entire Make.com scenario, it's time to put it to the test to ensure everything is functioning correctly. Navigate to your Airtable inventory table and deliberately adjust the quantity of a few items so that they fall below their defined ordering quantity level. This action should trigger the automation.
For instance, if you have an item tagged with a "High" rotation frequency (meaning a purchase order is generated when stock drops below 50% of maximum) and its current inventory level is 100 units, change its quantity to 20. This should activate the reorder process for that item.
Before running the test, remember to temporarily change the email address in the "Gmail" module to your own. This crucial step ensures that the test purchase orders are sent to you for review, rather than inadvertently being dispatched to your actual vendors. Once your testing is complete and you're satisfied with the results, be sure to revert the email address back to the vendor's contact information.
Pro tip: Always test your automation scenarios with your own email address first to prevent accidental emails to real vendors during setup and debugging.
If your scenario has been set up correctly, its execution should visually resemble the example provided below, with data flowing smoothly through each module and the purchase order being generated and sent as expected. Finally, don't forget to schedule your scenario to run at an appropriate frequency, such as once or twice daily, to keep your procurement process fully automated and your inventory optimized.