Mienne StateSet One Agentic Order Operations: Quickstart Guide

Welcome to the Mienne StateSet One Agentic Order Operations Quickstart Guide. This document is designed for developers and technical teams to understand and utilize the automated workflows built on StateSet (powered by Temporal) that integrate Shopify, NetSuite, DCL (Distribution Alternatives), Gorgias, and other services for Mienne’s e-commerce operations.

This guide will walk you through the core automated processes, key API interactions, and data flows, enabling you to manage, monitor, and potentially extend these agentic operations.

Table of Contents

  1. Introduction
  2. System Architecture Overview
  3. Prerequisites
  4. Core Workflows & API Interactions
  5. Key Configuration Parameters
  6. Development Environment: Activities & Workflows
  7. Error Handling & Monitoring
  8. Troubleshooting Common Issues
  9. Support Resources
  10. Conclusion

Introduction

Mienne’s StateSet One platform orchestrates complex order operations by connecting various e-commerce and backend systems. This automation streamlines processes from order capture to fulfillment, inventory management, and customer service. Key benefits include:

  • Automated Order Flow: Seamlessly move order data from Shopify to NetSuite and then to DCL for fulfillment.
  • Real-time Fulfillment Updates: Keep Shopify and NetSuite synchronized with shipment and tracking information from DCL.
  • Inventory Accuracy: Maintain consistent inventory levels between NetSuite, DCL, and Shopify.
  • Efficient Inbound Logistics: Automate PO/ASN communication with DCL and item receipt processing in NetSuite.
  • Agentic Customer Service: Enhance Gorgias with AI-powered responses and actions via integrations with Recharge and Shopify.
  • Centralized Orchestration: Utilize StateSet (Temporal) for robust, observable, and scalable workflow management.

This guide focuses on the API-driven interactions orchestrated by the workflows defined in workflows.js and activities in activities.js.


System Architecture Overview

The core data flow is designed for efficiency and accuracy:


Prerequisites

Before implementing or extending these workflows, ensure you have:

  • API Credentials: Access keys and tokens for Shopify, NetSuite, DCL (Distribution Alternatives), Gorgias, and StateSet APIs.
  • StateSet Account: A StateSet account with API key for workflow orchestration.
  • Temporal Setup: Access to the Temporal dashboard for monitoring workflows and activities.
  • Environment Variables: Configure necessary secrets (e.g., API keys) in your deployment environment.
  • Development Tools: Node.js environment for working with workflows.js and activities.js.

Core Workflows & API Interactions

A. Shopify Order Ingestion (shopifyToNetsuiteWorkflow)

This workflow automates the transfer of paid and unfulfilled orders from Shopify to NetSuite.

Trigger: Shopify webhook on order creation/update or scheduled CRON job.

Purpose: Convert Shopify Order to NetSuite Sales Order (SO) and tag the order as SENT_TO_NS.

Steps:

  1. Fetch new or updated orders from Shopify.
  2. Create an order record in StateSet using stateset.order.create().
  3. Transform order data and create a Sales Order in NetSuite (status: Pending Fulfillment).
  4. Update Shopify with NetSuite SO ID if needed.

Key API Calls:

  • Shopify API: GET /admin/api/2023-01/orders.json
  • StateSet API: POST /orders
  • NetSuite API: POST /record/v1/salesOrder

Error Handling: Retries on API failures; logs to Temporal for monitoring.

B. Order Fulfillment Dispatch (NetSuite to DCL - netsuiteToDCLWorkflow)

Dispatches approved Sales Orders from NetSuite to DCL for fulfillment.

Trigger: NetSuite flag custbody_sent_to_3pl = F on Sales Order.

Purpose: Transform SO and POST to DCL; set custbody_sent_to_3pl = T.

Steps:

  1. Query NetSuite for eligible Sales Orders.
  2. Transform data to DCL format.
  3. POST to DCL API to create batch/shipments.
  4. Update NetSuite flag to prevent re-processing.

Key API Calls:

  • NetSuite API: GET /record/v1/salesOrder (with search filters)
  • DCL API: POST /shipments
  • NetSuite API: PATCH /record/v1/salesOrder/

C. Fulfillment & Tracking Updates (DCL to NetSuite & Shopify - dclFulfillmentWorkflow / dclTrackingUpdateWorkflow)

Handles fulfillment confirmations and tracking updates from DCL.

Trigger: DCL webhook or polling on shipment updates.

Purpose: Create Item Fulfillment & optional Cash Sale in NetSuite; push tracking to Shopify.

Steps:

  1. Receive fulfillment data from DCL.
  2. Create Item Fulfillment in NetSuite.
  3. Optionally create Cash Sale if applicable.
  4. Update StateSet order status to FULFILLED.
  5. Update Shopify with fulfillment and tracking info.

Key API Calls:

  • NetSuite API: POST /record/v1/itemFulfillment
  • StateSet API: PATCH /orders/
  • Shopify API: POST /admin/api/2023-01/fulfillments.json

D. Inbound Logistics: PO/ASN Management

PO/TO Notification to DCL (dclPoNotificationWorkflow)

Trigger: Flag trigger on NetSuite PO/TO (status: Pending Receipt).

Purpose: Send ASN (Advance Ship Notice) to DCL.

Steps:

  1. Detect flagged PO/TO in NetSuite.
  2. Transform to DCL ASN format.
  3. POST to DCL API.
  4. Update NetSuite flag.

PO Receipt Processing from DCL (dclPoReceiptWorkflow)

Trigger: Scheduled poll of DCL PO receipts.

Purpose: Create Item Receipt in NetSuite, reconcile quantities, close PO if complete.

Steps:

  1. Poll DCL for new receipts.
  2. Create Item Receipt in NetSuite.
  3. Reconcile and update quantities.
  4. Close PO if fully received.

E. Inventory Synchronization

Standard Inventory Sync (inventorySyncWorkflow)

Trigger: Scheduled (every 15 minutes).

Purpose: Pull inventory from NetSuite, bulk update Shopify.

Steps:

  1. Query NetSuite inventory levels.
  2. Transform data.
  3. Bulk update Shopify inventory.

Bundle Inventory Sync (inventoryBundlesSyncWorkflow)

Trigger: Scheduled (every 15 minutes + 10 seconds).

Purpose: Compute bundle availability and update Shopify bundles.

Steps:

  1. Request BOM data from NetSuite.
  2. Calculate bundle_qty = MIN(component_qty[]).
  3. Update Shopify.

F. Returns, Cancellations & Refunds

This section covers workflows for handling returns, cancellations, and refunds, integrating with Gorgias, Shopify, and other systems.

Trigger: Gorgias ticket creation, Shopify cancellation request, or manual initiation.

Purpose: Validate and process returns/cancellations, update relevant systems, and issue refunds.

Steps:

  1. Receive and validate return/cancellation request (e.g., check eligibility within 30 days).
  2. Generate customer response and return label (US or CA specific).
  3. Create return record in StateSet.
  4. Optionally cancel subscriptions.
  5. Wait period (e.g., 3 days) for receipt.
  6. If conditions met (e.g., instant refund eligible), process refund via Shopify/Recharge.
  7. Update NetSuite, DCL if inventory affected.
  8. Post updates to Gorgias/Zendesk.

Key API Calls:

  • StateSet API: POST /returns
  • Shopify API: POST /refunds
  • Gorgias API: POST /tickets//messages

Error Handling: Validate order status, handle partial refunds, log discrepancies.

G. Agentic Customer Service (mienneResponseWorkflow)

Trigger: Webhook from Gorgias on new ticket.

Purpose: Generate AI-powered responses and actions using OpenAI, Recharge, and Shopify.

Steps:

  1. Receive ticket data.
  2. Analyze with OpenAI.
  3. Perform actions (e.g., refund, subscription update).
  4. Post response to Gorgias.

Key Configuration Parameters

  • API Endpoints: Configure URLs for Shopify, NetSuite, DCL, etc.
  • Credentials: Secure storage of API keys and tokens.
  • Schedules: CRON expressions for inventory syncs.
  • Flags: Custom fields in NetSuite (e.g., custbody_sent_to_3pl).
  • Thresholds: Inventory warning levels, retry limits.

Development Environment: Activities & Workflows

Workflows are defined in workflows.js using Temporal syntax. Activities (API calls, transformations) are in activities.js.

Setup:

  • Install Temporal SDK: npm install @temporalio/workflow
  • Run worker: node worker.js

Extending:

  • Add new activities for custom API integrations.
  • Compose new workflows for additional processes.

Error Handling & Monitoring

  • Retries: Exponential backoff for transient failures.
  • Compensation: Saga pattern for rollbacks.
  • Monitoring: Temporal UI for workflow visibility; integrate with Grafana/Prometheus.
  • Alerts: Slack/Email notifications on failures.

Troubleshooting Common Issues

  • API Rate Limits: Implement throttling in activities.
  • Data Mismatches: Validate transformations between systems.
  • Webhook Failures: Check signatures and endpoints.
  • Inventory Discrepancies: Run manual syncs via CLI.

Support Resources

Conclusion

This quickstart provides the foundation for leveraging StateSet One for Mienne’s order operations. By automating these workflows, you achieve efficiency, accuracy, and scalability. For custom extensions, contact StateSet support.