powered by

Build an order system

Build an order system with customers, products, orders and line items, a live REST API, a Slack alert on each new order, and an AI that reports what's paid.

Last updated

Almost every shop, booking tool or internal sales app needs the same core: people who buy, things they buy, and an order that ties the two together and moves from placed to paid to shipped. This page builds that in one Anythink project, then wires it up so a new order posts to Slack and you can ask an AI which orders are paid.

You'll model four entities, create and filter orders over the REST API, run a workflow when an order is created, and ask questions about the data. Each step shows the Anythink dashboard, the CLI and an AI assistant (MCP).

If you haven't used Anythink before, read Core concepts first. Build your first app is a shorter walk through the same ideas.

What you'll build#

Entity What it holds Key fields
customers The people who order name, email
products What you sell name, price
orders One per purchase reference, status (pending, paid or shipped), total, customer
order_items The lines on an order quantity, order, product

Each order points at one customer. Each order item points at one order and one product. Those links are relationships, so one request can return an order with its customer inside it.

Step 1: Model the order system#

Create the four entities, then add their fields. The relationships come last, because a relationship needs its target entity to exist.

In the Anythink dashboard

The quickest route is the AI chat. Open the AI panel and ask:

text
Create four entities: customers (name, required email that is unique), products (name, price), orders (reference, total, a status select with pending, paid and shipped defaulting to pending, and a many-to-one link to customers) and order_items (integer quantity, a many-to-one link to orders and a many-to-one link to products).

The chat acts on your project with your permissions. It isn't read-only, so it creates the entities and fields when you ask. Check the result in Settings › Data Model, and ask it to change anything that's wrong. Chat with your backend data using AI covers the setup.

To build it by hand instead:

  1. Go to Settings › Data Model and select Add Entity. Create customers, products, orders and order_items.
  2. Open each entity, select Add Field and add the fields in the table above. Make status a Select with the choices Pending, Paid and Shipped, defaulting to Pending.
  3. On orders, add a Many-to-One field customer that targets customers. On order_items, add Many-to-One fields order (targets orders) and product (targets products).

With the CLI

bash
anythink entities create customers
anythink entities create products
anythink entities create orders
anythink entities create order_items

anythink fields add customers name --type varchar --required --name-field
anythink fields add customers email --type varchar --required --unique
anythink fields add products name --type varchar --required --name-field
anythink fields add products price --type decimal --required
anythink fields add orders reference --type varchar --required --name-field
anythink fields add orders status --type varchar --display select --options "Pending=pending,Paid=paid,Shipped=shipped" --default pending
anythink fields add orders total --type decimal
anythink fields add orders customer --type many-to-one --target customers --on-delete "SET NULL"
anythink fields add order_items quantity --type integer --required
anythink fields add order_items order --type many-to-one --target orders --on-delete CASCADE
anythink fields add order_items product --type many-to-one --target products --on-delete RESTRICT

The --on-delete option decides what happens to a record when the one it points at is deleted. Here, deleting an order deletes its items, deleting a customer keeps their orders, and a product that's on an order can't be deleted. See Model your data for every field type and option.

With an AI assistant (MCP)

text
Create entities customers, products, orders and order_items. customers: required name (name field), required unique email. products: required name (name field), required decimal price. orders: required reference (name field), decimal total, a status select of pending, paid and shipped defaulting to pending, and a many-to-one customer. order_items: required integer quantity, a many-to-one order that cascades on delete, and a many-to-one product that restricts delete.

The assistant runs entities create and one fields add per field through the cli tool. Connect Claude to your backend with MCP sets up the server.

Step 2: Add data and call the REST API#

Every entity has a REST API as soon as it exists. Create a customer and a product in the Anythink dashboard or the CLI first, then place an order for them over HTTP. You'll need an API key whose role has orders:create and orders:read. See API keys and Roles and permissions.

In the Anythink dashboard

  1. Open customers, select Add Customer and enter a name and email. Do the same in products.
  2. Open orders and select Add Order. Enter a reference such as ORD-1001, a total, and pick the customer.
  3. To filter, use the filter bar above the table and choose status equals paid.

With the CLI

bash
anythink data create customers --data '{"name":"Sam Rivers","email":"sam@example.com"}'
anythink data create products --data '{"name":"Trail shoes","price":89.5}'
anythink data create orders --data '{"reference":"ORD-1001","total":179,"customer":1}'
anythink data create order_items --data '{"order":1,"product":1,"quantity":2}'
anythink data list orders --filter 'status=paid'

Relationship fields take the related record's id. data create prints the saved record, including the customer expanded inside the order.

With an AI assistant (MCP)

text
Add a customer Sam Rivers (sam@example.com) and a product Trail shoes at 89.50. Create order ORD-1001 for Sam with a total of 179 and one order item of 2 pairs. Then list the paid orders.

The assistant runs data create for each record, then data list orders with a status filter.

The raw request#

This is what the CLI and dashboard send. Set your project ID and key once:

bash
export BASE=https://api.my.anythink.cloud/org/<project_id>
export ANYTHINK_API_KEY=ak_your_key_here

Create an order:

bash
curl -X POST "$BASE/entities/orders/items" \
  -H "x-api-key: $ANYTHINK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"reference": "ORD-1001", "total": 179, "customer": 1}'

The response is 201 Created with the saved record. The status took its default, and the customer comes back expanded:

json
{
  "locked": false,
  "id": 1,
  "created_at": "2026-10-09T09:09:39.901591Z",
  "updated_at": "2026-10-09T09:09:39.901591Z",
  "reference": "ORD-1001",
  "status": "pending",
  "total": 179,
  "customer": {
    "id": 1,
    "name": "Sam Rivers",
    "email": "sam@example.com",
    "__name": "Sam Rivers"
  },
  "__name": "ORD-1001"
}

List the paid orders:

bash
curl "$BASE/entities/orders/items?status=paid&pageSize=10" \
  -H "x-api-key: $ANYTHINK_API_KEY"
json
{
  "items": [
    {
      "locked": false,
      "id": 2,
      "reference": "ORD-1002",
      "status": "paid",
      "total": 40,
      "customer": { "id": 1, "name": "Sam Rivers", "email": "sam@example.com", "__name": "Sam Rivers" },
      "__name": "ORD-1002"
    }
  ],
  "page": 1,
  "page_size": 10,
  "total_items": 1,
  "total_pages": 1,
  "has_next_page": false,
  "has_previous_page": false,
  "retrieval_time": 22
}

A bare value means equals. Use an operator for anything else, such as total=GTE:100. See The instant REST API for paging, sorting and updates, and Filter operators reference for every operator.

Step 3: Post to Slack when an order is created#

A workflow can react to a new order. This one posts to a Slack channel and then stamps the order with the time it was announced. It needs Slack connected first: follow Connect Slack to send workflow messages.

Add a notified_at timestamp field to orders first:

bash
anythink fields add orders notified_at --type timestamp

In the Anythink dashboard

  1. Go to Workflows and select New Workflow. Name it notify-slack-on-order, set Trigger Type to Event, Event Type to Entity Created and Entity to orders. Tick Enable Workflow and select Create Workflow.

  2. Select Add Step, open the Integrations tab and choose Slack. Set Key to notify_slack, Operation to Send Message, Credential Source to System (shared connection), pick the channel, and set the message to:

    text
    New order {{ $anythink.trigger.data.reference }}: £{{ $anythink.trigger.data.total }}
    
  3. Select Add Step again and choose the Action card, then Update Data. Set Key to mark_notified, Entity to orders, IDs to {{ $anythink.trigger.id }} and the payload to:

    json
    { "notified_at": "{{ $anythink.now }}" }
    
  4. Connect Start to notify_slack, drag from its green handle to mark_notified, then select Save Workflow.

With the CLI

bash
anythink workflows create notify-slack-on-order --trigger Event --event EntityCreated --entity orders --enabled

anythink workflows integration-add <workflow_id> notify_slack \
  --name "Notify Slack" --provider slack --operation send-message \
  --credential-source system --start --enabled \
  --inputs '{"channel":"#orders","text":"New order {{ $anythink.trigger.data.reference }}: £{{ $anythink.trigger.data.total }}"}'

anythink workflows step-add <workflow_id> mark_notified \
  --name "Mark notified" --action UpdateData --enabled \
  --params '{"entity_name":"orders","ids":"{{ $anythink.trigger.id }}","payload":"{ \"notified_at\": \"{{ $anythink.now }}\" }"}'

anythink workflows step-link <workflow_id> <notify_slack_step_id> --on-success <mark_notified_step_id>

workflows create prints the workflow's ID, and each step-add prints a step ID. On an EntityCreated trigger, trigger.data holds the fields in the create request and trigger.id is the new record's ID. The payload of an Update Data step is a string that holds JSON, so its quotes are escaped. See Triggers and scheduling and Step types.

With an AI assistant (MCP)

text
Create a workflow notify-slack-on-order that runs when an order is created. First step: post "New order {{ $anythink.trigger.data.reference }}: £{{ $anythink.trigger.data.total }}" to #orders in Slack using the shared connection. On success, an Update Data step that sets notified_at on the new order to the current time. Enable it.

The assistant runs workflows create, workflows integration-add, workflows step-add and workflows step-link through the cli tool.

To test it, create an order as in step 2. The message appears in the channel, and the order's notified_at is filled in. View Job History on the workflow shows each step's output. Test workflows and read job history explains how to read it.

Step 4: Ask the AI what's been paid#

With the data in place, ask questions in plain English. The AI chat reads your orders using your permissions. It can also change them if you ask, so word a question as a question.

In the Anythink dashboard

Open the AI panel and ask:

text
Which orders have been paid, and how much is that in total?

The chat reads orders where status is paid, lists them and adds up the totals.

With the CLI

The CLI has no chat command. This is the read the chat runs for you:

bash
anythink data list orders --filter 'status=paid'

With an AI assistant (MCP)

text
Which orders have been paid, and what's the total?

The assistant runs data list orders with a status=paid filter and sums the total field. See How AI chat and MCP work for what each can do.

Step 5: Notify the customer when it ships (optional)#

If your customers sign in to a mobile app, a workflow can push a notification when you ship their order. This one is triggered by an API call, so the caller passes the order and user:

In the Anythink dashboard

  1. Go to Workflows and create a workflow named order-shipped with an API trigger and the route order-shipped.
  2. Add a Send a Push Notification step. Set the Title to Order {{ $anythink.trigger.data.order_id }} shipped, choose A single user, and enter {{ $anythink.trigger.data.user_id }} as the User id.
  3. Select Enable Workflow.

With the CLI

bash
anythink workflows create order-shipped --trigger Api --api-route order-shipped --enabled
anythink workflows step-add <workflow_id> notify --action SendPushNotification --start --enabled \
  --params '{"title":"Order {{ $anythink.trigger.data.order_id }} shipped","body":"Tap to track it","audience":{"kind":"user","user_id":"{{ $anythink.trigger.data.user_id }}"}}'

With an AI assistant (MCP)

text
Create a workflow order-shipped with an API trigger on the route order-shipped. Add a Send a Push Notification step that sends "Order {{ $anythink.trigger.data.order_id }} shipped" to the user in trigger data user_id. Enable it.

Device registration, action buttons and the full set of options are in Push notifications.

What you get#

  • A relational order model with a REST API for every entity, available as soon as the fields exist.
  • Orders that return their customer inside the same response, and filters on any field.
  • A workflow that announces each new order in Slack and records that it did.
  • An AI that answers questions about your orders using only what its user may read.

Next steps#