From Email to Purchase Order: Automating Order Processing with Zoho Flow and OpenAI

Ever wasted hours manually transferring purchase order details from emails into your accounting system? With this guide, learn how to automate the entire process, turning email orders into perfectly formatted purchase orders in Zoho Books using OpenAI and Zoho Flow's smart automation tools.

Published on November 19, 2024

Share This Post
Chatgpt

From Email to Purchase Order: Automating Order Processing with Zoho Flow and OpenAI

Ever spent hours copying and pasting purchase order details from emails into your accounting system? We’ve been there. What if you could have those emails automatically transformed into perfectly formatted purchase orders in Zoho Books, with all the right details in all the right places? This guide shows you how to build exactly that, using the intelligent processing power of OpenAI combined with Zoho Flow’s automation tools.

You’ll learn how to create a system that not only extracts order information from emails but also formats it, sends confirmation requests, and creates purchase orders – all without any manual data entry. Whether you’re drowning in procurement paperwork or simply want to modernize your ordering process, this step-by-step tutorial will help you build a seamless, error-free automation system.

Understanding Zoho Flow and OpenAI

Before diving into the technical setup, let’s understand the key tools that make this automation possible. Zoho Flow serves as our automation backbone; think of it as a digital assembly line where you can connect different apps and services to work together seamlessly. It’s like having a virtual assistant that can monitor your email, process information, and update your business systems, all following rules you define.

OpenAI brings the brainpower to our automation. Its natural language processing capabilities can understand and extract structured information from even the most inconsistent email formats. Instead of writing complex rules to parse different email layouts, OpenAI can intelligently identify purchase order details regardless of how they’re presented.

When combined, these tools create a powerful workflow: Zoho Flow handles the orchestration—managing the flow of information between your email, OpenAI, and Zoho Books—while OpenAI handles the intelligent data extraction. It knows exactly what to look for in emails and where to put that information in your purchase order system based on your instruction.

The best part? You don’t need to be a programming expert to set this up. Both platforms provide user-friendly interfaces that make it possible to build sophisticated automations through simple point-and-click configurations.

Benefits of Automating Purchase Order Processing with Zoho Flow and Open AI

Automating your purchase order process isn’t just about keeping up with technology; it’s about transforming how your business handles procurement. Here are the key advantages of implementing this automated system:

  • Time saving: Processing purchase orders manually can take hours each day. With automation, what previously required 15-20 minutes per order now happens in seconds. Your team can redirect this saved time toward strategic tasks like vendor relationship management and procurement strategy.
  • Enhanced accuracy and consistency: Human error during manual data entry is inevitable, especially when dealing with multiple line items and complex pricing. The OpenAI-powered system extracts information with remarkable precision, eliminating typos, misplaced decimals, and incorrect item codes. Every purchase order follows the same standardized format, maintaining consistency across your procurement records.
  • Improved vendor relationships: Automated processing means vendors receive confirmations and responses faster. The system instantly sends formatted confirmation emails with clear order details, leading to fewer back-and-forth communications and queries. This professional, prompt communication strengthens vendor relationships and can often lead to better terms and priority service.
  • Real-time processing and tracking: Unlike batch processing common in manual systems, automated workflows process orders as they arrive. This real-time handling provides better visibility into procurement status and cash flow requirements. Managers can access up-to-date purchase order data in Zoho Books without waiting for manual updates
  • Reduced operational costs: Beyond the obvious time savings, automation reduces costs across multiple areas. Fewer errors mean less time spent on corrections and reconciliation. Digital processing eliminates printing and storage costs, while standardized workflows reduce training requirements for new staff members handling procurement tasks.

Step-by-Step Guide to Automating Purchase Orders with Zoho Flow and OpenAI

This section will walk you through setting up an automated system that creates purchase orders in Zoho Books from email content using OpenAI for data extraction and Zoho Flow for workflow automation.

The automation workflow:

  • Monitors email inbox for purchase order related emails.
  • Uses OpenAI to extract structured data from email content.
  • Formats the data into a standardized format.
  • Sends a confirmation email with order details and approval button.
  • Creates a purchase order in Zoho Books.

Prerequisites

To be able to follow the guide, you need to have the following in place:

  • Zoho account.
  • OpenAI API key.
  • js server for handling order confirmations.
  • Basic knowledge of Javascript.

1. Create New Flow

Let’s begin by creating a new flow:

 1. Go to Zoho Flow and click “Create Flow“.

1

 2. Give your flow a name like “Purchase Order Automation“.

2

2. Set Up Email Trigger

Let’s start the automation setting up our email trigger. This trigger starts the workflow whenever a new purchase order email arrives. Here’s how to get it done:

  1. In the Apps tab, find Zoho Mail.
  2. Select “Email matching search received” under triggers.

3

 3. Connect your Zoho Mail, and configure the trigger to search for purchase order emails based on Subject contains.

4

3. Add ChatGPT Integration

Now, let’s use ChatGPT to extract and format the purchase order details:

  1. In the Apps tab, search for ChatGPT.
  2. Drag the “Create chat completion” action onto the canvas and connect your account (i.e you Open AI token).

5

 3. Configure the action with your desired prompt. Here is a sample I used:

Analyze the following text and extract relevant purchase order details in a well-formatted JSON structure. Don’t add any note before and after JSON generated. I need only the JSON. The JSON should only have these fields, don’t change it. PurchaseOrderNumber, Date, PaymentTerms, Vendor (with Name and ContactEmail), Items (a list containing Description, Quantity, UnitPrice, and Total for each item), Subtotal, Tax, Shipping, Total, and DeliveryAddress (including Recipient, Street, City, State, and PostalCode). Use ${trigger.emailHtmlContent} as the source for this extraction. If any of the fields can’t be gotten from the source, put “Not available”

 4. Set the Model to your preferred model and click Done.

4.Add Format Email Function

Next, we will have to clean the data from ChatGPT and format it into a nice email template:

 1. Switch to the Logic tab in the left sidebar.

  • Drag Custom Function onto the canvas after the ChatGPT action.

6

2. Name the function “formatEmailData” and add the following parameters:

  • purchaseOrderDataString (String).
  • senderEmail (String).

3. Write the formatEmailData code. You can use the sample below:

string formatEmailData(string purchaseOrderDataString, string senderEmail)
{
// Clean up the provided string by removing unnecessary markers and trimming
purchaseOrderDataString = purchaseOrderDataString.replaceAll(““`json”,””).replaceAll(““`”,””).trim();
// Parse the cleaned string to a Map
try
{
purchaseOrderDataMap = purchaseOrderDataString.toMap();
}
catch (e)
{
return “Error: Invalid JSON format in input data.”;
}
// Retrieve the PurchaseOrder data
purchaseOrderData = purchaseOrderDataMap;
if(purchaseOrderData.isEmpty())
{
return “Error: ‘PurchaseOrder’ section missing in data.”;
}
// Extract the Purchase Order details
orderNumber = purchaseOrderData.get(“PurchaseOrderNumber”);
date = purchaseOrderData.get(“Date”);
// Vendor Information
vendor = purchaseOrderData.get(“Vendor”);
vendorName = vendor.get(“Name”);
contactEmail = vendor.get(“ContactEmail”);
// Order Items
orderDetails = purchaseOrderData.get(“Items”);
orderItemsText = “”;
if(orderDetails != null && orderDetails.size() > 0)
{
orderItemsText = “”;// Start tableorderItemsText = orderItemsText + “”;
// Table header
for each item in orderDetails
{
itemName = item.get(“Description”);
quantity = item.get(“Quantity”);
unitPrice = item.get(“UnitPrice”);
totalPrice = item.get(“Total”);
// Add row to table for each item
orderItemsText = orderItemsText + “”;orderItemsText = orderItemsText + “”;
orderItemsText = orderItemsText + “”;
orderItemsText = orderItemsText + “”;
orderItemsText = orderItemsText + “”;
orderItemsText = orderItemsText + “”;/**/

Item Quantity Unit Price Total Price
” + itemName + “ ” + quantity + “ ” + unitPrice + “ ” + totalPrice + “

}
orderItemsText = orderItemsText + ”
“;
// End table
}
else
{
orderItemsText = “No items available.
“;
}
// Order Summary
subtotal = purchaseOrderData.get(“Subtotal”);
tax = purchaseOrderData.get(“Tax”);
shippingCost = purchaseOrderData.get(“Shipping”);
totalCost = purchaseOrderData.get(“Total”);
// Delivery Address
deliveryAddress = purchaseOrderData.get(“DeliveryAddress”);
recipient = deliveryAddress.get(“Recipient”);
street = deliveryAddress.get(“Street”);
city = deliveryAddress.get(“City”);
state = deliveryAddress.get(“State”);
postalCode = deliveryAddress.get(“PostalCode”);
// Additional Information
paymentTerms = purchaseOrderData.get(“PaymentTerms”);
// Construct the email body using the extracted values with better formatting
emailBody = ”

Purchase Order Details

“;
emailBody = emailBody + “———————————-
“;
emailBody = emailBody + “Purchase Order Number: ” + orderNumber + “
“;
emailBody = emailBody + “Date: ” + date + ”

“;
emailBody = emailBody + “

Vendor Information

“;
emailBody = emailBody + “———————————-
“;
emailBody = emailBody + “Vendor Name: ” + vendorName + ”
“;
emailBody = emailBody + “Contact Email: ” + contactEmail + ”

“;
emailBody = emailBody + ”

Order Items

“;
emailBody = emailBody + “———————————-
“;
emailBody = emailBody + orderItemsText + “
“;
emailBody = emailBody + ”

Order Summary

“;
emailBody = emailBody + “———————————-
“;
emailBody = emailBody + “Subtotal: ” + subtotal + “
“;
emailBody = emailBody + “Tax: ” + tax + ”
“;
emailBody = emailBody + “Shipping Cost: ” + shippingCost + ”
“;

emailBody = emailBody + “<b>Total Cost:</b> ” + totalCost + “<br><br>”;
emailBody = emailBody + “<h3 style=’color: black;’>Delivery Address</h3>”;
emailBody = emailBody + “<b>———————————-</b><br>”;
emailBody = emailBody + “<b>Recipient:</b> ” + recipient + “<br>”;
emailBody = emailBody + “<b>Street:</b> ” + street + “<br>”;
emailBody = emailBody + “<b>City:</b> ” + city + “<br>”;
emailBody = emailBody + “<b>State:</b> ” + state + “<br>”;
emailBody = emailBody + “<b>Postal Code:</b> ” + postalCode + “<br><br>”;
emailBody = emailBody + “<h3 style=’color: black;’>Payment Terms</h3>”;
emailBody = emailBody + “<b>———————————-</b><br>”;
emailBody = emailBody + “<b>Payment Terms:</b> ” + paymentTerms + “<br><br>”;
confirmOrderUrl = “http://localhost:3000/confirm-order?purchaseOrderNumber=” + orderNumber + “&email=” + senderEmail;
emailBody = emailBody + “<a href='” + confirmOrderUrl + “‘ style=’background-color: green; color: white; padding: 10px 20px; text-decoration: none; font-weight: bold;’>Confirm Order</a><br><br>”;
return emailBody;
}

This function creates a confirmation URL with the order number and sender email. The recipient can click the “Confirm Order” button in the email, which links to the Node.js server endpoint. Here’s the Node.js server code for handling this request:

const express = require(‘express’);
const nodemailer = require(‘nodemailer’);
const app = express();
const port = 3000;// Email transport setup
const transporter = nodemailer.createTransport({
service: ‘gmail’,
auth: {
user: ‘YOUR_EMAIL@gmail.com’,
pass: ‘YOUR_APP_PASSWORD’ // Replace with a secure app-specific password
}
});// Route to handle order confirmation
app.get(‘/confirm-order’, (req, res) => {
const { purchaseOrderNumber, email } = req.query;if (!purchaseOrderNumber || !email) {
return res.status(400).send(‘Missing required parameters.’);
}const mailOptions = {
from: ‘YOUR_EMAIL’,
to: email,
subject: ‘Order Confirmation’,
text: `Purchase order no: ${purchaseOrderNumber} has been confirmed ✅.`
};transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return res.status(500).send(‘Error sending email: ‘ + error.toString());
}
res.send(`Purchase order ${purchaseOrderNumber} has been confirmed ✅. Thanks :)`);
});
});app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});

4. Configure the input mappings:

  • purchaseOrderDataString: Select ${createChatCompletion_2.choice_text} from ChatGPT.
  • senderEmail: Select ${trigger.toAddress}.

5. Click Done.

5. Add Send Email Action

Now, we’ll send the formatted email back to the sender:

  1. Switch back to the Apps tab and search for Zoho Mail.
  2. Drag the Send Email action onto the canvas.
  3. Configure the email:

7

  • To: Select ${trigger.fromAddress} from Email search trigger.
  • Subject: “Processed Order Data“.
  • Message: Select ${formatEmailData_2}.

4 . Click Done.

6. Add Purchase Order Parser Function

Now, let’s parse the extracted purchase order data:

  1. Stay in the Logic tab and drag another Custom Function onto the canvas.
  2. Name it “parsePurchaseOrderData” and configure the parameter:
  3. jsonString (String).
  4. Paste the parsePurchaseOrderData code.
map parsePurchaseOrderData(string jsonString)
{
// Clean up the provided string by removing unnecessary markers and trimming
jsonString = jsonString.replaceAll(““`json”,””).replaceAll(““`”,””).trim();
// Parse the cleaned string to a Map
try
{
purchaseOrderMap = jsonString.toMap();
}
catch (e)
{
info “Error: Invalid JSON format in input data.”;
return Map();
}
// Validate the parsed data
if(purchaseOrderMap.isEmpty())
{
info “Error: Empty or invalid purchase order data.”;
return Map();
}
return purchaseOrderMap;
}

4. Map the input from ChatGPT trigger:

  • jsonString: Select ${createChatCompletion_2.choice_text}.

5. Click Save.

7. Create Purchase Order in Zoho Books

Let’s create the purchase order in Zoho Books:

  1. Now switch to the Apps tab and search for Zoho Books.
  2. Drag the Create Purchase Order action onto the canvas.

Map the necessary fields:

Purchaseorder number: ${parsePurchaseOrderData_4.get(“PurchaseOrderNumber”)}

Date: ${parsePurchaseOrderData_4.get(“Date”).toDate(“MMMM d, yyyy”).toString(“yyyy-MM-dd”)}

Payment terms: ${parsePurchaseOrderData_4.get(“PaymentTerms”)}

Vendor ID: ${parsePurchaseOrderData_4.get(“Vendor”).get(“Name”)}

Attention: ${parsePurchaseOrderData_4.get(“DeliveryAddress”).get(“Recipient”)}

// For the first item (index 0)
Item name: ${parsePurchaseOrderData_4.get(“Items”)[0].get(“Description”)}
Item description: ${parsePurchaseOrderData_4.get(“Items”)[0].get(“Description”)}
Item quantity: ${parsePurchaseOrderData_4.get(“Items”)[0].get(“Quantity”)}
Item rate: ${parsePurchaseOrderData_4.get(“Items”)[0].get(“UnitPrice”)}

// Additional numeric fields available:
Subtotal: ${parsePurchaseOrderData_4.get(“Subtotal”)}
Tax: ${parsePurchaseOrderData_4.get(“Tax”)}
Shipping: ${parsePurchaseOrderData_4.get(“Shipping”)}
Total: ${parsePurchaseOrderData_4.get(“Total”)}

4. Click Done.

8. Testing the Flow

Once you’ve configured the steps, use Zoho Flow’s Test feature:

  • Click on the play button in the top right.

8

  • Send a test email with purchase order details.
  • Watch the flow execution in real-time and check each step’s output in the execution history.

If everything goes well, your execution tree will look like the one below:

9

 

Now you can go to Zoho Books and confirm if your purchase order is recorded there after successful execution.

Conclusion

Implementing this automated purchase order system marks a significant step forward in modernizing your procurement process. While the initial setup requires careful attention to detail, the long-term benefits far outweigh the setup time. With Zoho Flow and OpenAI working together, you’ll transform a traditionally manual, error-prone process into a streamlined, efficient workflow.

As your business grows, this automation will scale with you, handling increasing order volumes without requiring additional resources. Take the time to implement this solution, and you’ll wonder how your team ever managed without it. The future of procurement is automated; why not start today?

Recent Posts
  • From Email to Purchase Order: Automating Order Processing with Zoho Flow and OpenAI
  • How to Create Custom Zoho Writer Documents with Conditions and Subforms
  • How to Create Macros to Automate Ticket Replies in Zoho Desk
  • Integrating Zoho Creator and Zoho Desk using a Widget Extension
Share This Post

Related Posts

Discover the latest news and updates on Zoho applications.

Unlock Your Knowledge Journey!

Get three articles for free, then enjoy unlimited access by registering.