Create NetSuite sales orders from paid Shopify orders

By General Input

When a Shopify order is paid, we match or create the buyer in NetSuite, build the sales order line by line, and post a Slack recap to your orders channel.

Integrations

  • NetSuite
  • Shopify
  • Slack

Type

Deterministic Code

Categories

  • Operations
  • Finance

When Shopify sends a webhook telling us an order has been paid, I want the matching sales order created in NetSuite automatically. Take the order id from the webhook payload and use the Shopify Get Order operation to fetch the full order: customer name and email, the Shopify customer id, the order number, every line item with its SKU, quantity and unit price, plus line discounts, shipping cost, tax, and the order total. If the order is not actually paid, stop and do nothing.

Next resolve the buyer in NetSuite. Run a SuiteQL query against the customer table filtering on the buyer's email address. If a customer comes back, use it. If none exists, create one with the NetSuite upsert by external id operation on the customer record type, keyed to the Shopify customer id (for example shopify-customer-8123456789), and fill in name, email, and the billing address from the Shopify order. Keying on the Shopify customer id means repeat buyers and replayed webhooks land on the same NetSuite customer instead of spawning duplicates.

Before writing the order, map every Shopify line item SKU to a NetSuite item. Run a SuiteQL query against the item table matching the SKU to the NetSuite item id and collect the internal id for each line. If any SKU has no matching NetSuite item, do not silently drop that line and do not create a partial sales order. Fail the whole order instead: post a Slack message to our orders channel with the Send a Message operation, naming the Shopify order number and every unmatched SKU so someone can fix the item mapping and run the order through again, then stop the workflow.

When every SKU resolves, create the sales order in NetSuite using the upsert by external id operation on the salesOrder record type, with the external id set to the Shopify order number (for example shopify-order-1043). Set the customer to the NetSuite customer resolved above and add one line per Shopify line item carrying the mapped NetSuite item, the quantity, the unit price, and any line level discount. Carry shipping cost and tax onto the order as well. NetSuite money and quantity fields are plain decimals in the record currency, so pass the Shopify amounts straight through with no cents conversion. Because the sales order is keyed on the Shopify order number, a duplicate or replayed webhook updates the existing sales order rather than creating a second one.

Then notify the team in Slack, in our orders channel. For a normal order, post a short confirmation with the NetSuite sales order number, the customer name, and the order total. When the order total is over $5,000, post a louder alert in the same channel instead: an at-here mention, a bold headline calling out the high value order, and the same details plus the number of lines, so the account team sees it right away.

If NetSuite rejects a write for any other reason, such as a validation failure, a missing permission, or concurrency throttling, post that failure to the same Slack channel naming the Shopify order number and the error, so no paid order ever fails silently on its way into NetSuite.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentWin back LiveChat visitors whose chats went unansweredChat quality review board for LiveChat support leadsReceiving dock console for inspecting and restocking Loop returnsWin back no-show and cancelled appointments every morningSee which influencer creators actually drove Shopify salesLive Loop returns analytics with product-level drill-downNewsletter pre-flight and approval board for Mailjet sendsTurn a prospect spreadsheet into personalized sequence enrollmentsMailjet email delivery lookup console for support teams