Python helpers

shopify_get_customer / shopify_get_customer_orders

Find a Shopify customer account, or its recent orders, by exact email address.

shopify_get_customer(context: dict, email: str) -> dict | None
shopify_get_customer_orders(context: dict, email: str) -> list[dict]

Helpers that find a Shopify customer account by email. They are built on shopify_graphql with Admin API version 2026-10, so your code never holds a Shopify token.

Both use the current business's first connected Shopify store and only match a customer whose email is exactly the address given, ignoring case and surrounding spaces. Shopify's search can return other customers too, so every result is checked.

For order lookups, prefer shopify_find_orders. It searches every store connected to the business, also finds orders placed as a guest, and leaves out fields a support bot should never see. Use these helpers when you need the customer account itself, or code that already reads their order shape.


shopify_get_customer

NameTypeDescription
contextdictThe context object passed to your code
emailstrThe customer's email address. Case and surrounding spaces are ignored

Returns the customer, or None when no customer has this email (or email is empty):

{
    "id": "gid://shopify/Customer/7012345678901",
    "email": "jane@example.com",
    "firstName": "Jane",
    "lastName": "Doe",
    "phone": "+15551234567",
    "createdAt": "2026-03-14T09:21:07Z",
    "updatedAt": "2026-11-02T16:40:12Z",
}

shopify_get_customer_orders

NameTypeDescription
contextdictThe context object passed to your code
emailstrThe customer's email address. Case and surrounding spaces are ignored

Returns up to 30 of the customer's orders, most recently updated first, or an empty list when no customer has this email or they have no orders.

Orders are in Shopify's Admin GraphQL shape (camelCase fields; see Shopify's Order object). Each order includes its statuses, totals, addresses, tags, up to 5 line items, fulfillments with tracking (trackingInfo), returns, refunds and transactions. Connections such as lineItems come back as {"edges": [{"node": {...}}]}. The order's customer holds id, phone, firstName, lastName and note.

The selection includes statusPageUrl, which opens the order's status page without a login. Return it to the AI agent only once the customer is verified.

Errors

Both helpers raise requests.HTTPError when Shopify isn't connected for the business or the lookup fails.


Example

def execute_action(context):
    email = context["args"]["email"]

    customer = shopify_get_customer(context, email)
    if customer is None:
        return {"success": False, "message": "No customer account uses this email."}

    orders = shopify_get_customer_orders(context, email)
    return {
        "success": True,
        "customer": {"firstName": customer["firstName"], "since": customer["createdAt"]},
        "orderCount": len(orders),
        "latestOrder": orders[0]["name"] if orders else None,
    }

On this page