Skip to content

Update Order Status

After processing an order (e.g., sending it to the kitchen, completing fulfillment), update the order state on the iorder server. This tells the system the order has been handled and prevents duplicate processing.

Endpoint

text
PUT https://{host}/orders/{orderId}/statusupdate

Path parameters:

ParameterTypeDescription
orderIdstringThe order number (as a string)

Headers:

HeaderRequiredDescription
api_keyYesService device API key
Content-TypeYesapplication/json

Request body: OrderUpdate

json
{
  "newState": "COMPLETED",
  "comment": "Order delivered to table A12"
}

Request Schema

OrderUpdate

FieldTypeRequiredDescription
newStatestringYesTarget order state (see valid values below)
commentstring or nullNoOptional comment or message (stored as order message)

Valid newState Values

ValueDescription
PLACEDOrder has been submitted by customer
COMPLETEDOrder was fulfilled successfully
ABORTEDOrder was cancelled
FAILEDOrder processing failed

Valid State Transitions

The iorder system tracks orders through a defined lifecycle. Not all transitions are valid.

text
                    +---> COMPLETED
                    |
  PLACED -----------+
                    |
                    +---> ABORTED

  SELECTING -------> ABORTED

  PLACED ----------> FAILED

  FAILED ----------> PLACED (retry)

Valid transitions for service clients:

FromToDescription
PLACEDCOMPLETEDOrder fulfilled (most common)
PLACEDABORTEDOrder cancelled after being placed
PLACEDFAILEDBackend processing error
SELECTINGABORTEDCustomer session closed with no order placed

The FAILED state is special: orders in FAILED state are retried by a scheduled job that resets them back to PLACED. After that, the client can attempt processing again.

Response

Success: 200 OK with the updated Order DTO:

json
{
  "number": 12345,
  "userNumber": 5,
  "rows": [
    {
      "category": {
        "order": 1,
        "id": 1,
        "description": "Beverages"
      },
      "itemType": "MENU_ITEM",
      "name": "Espresso",
      "number": 1,
      "factor": 2,
      "price": 3.50,
      "priceTogo": null,
      "discount": null,
      "subrows": null
    }
  ],
  "state": "COMPLETED",
  "orderTime": "10:30:00",
  "completeTime": "10:35:00",
  "tableNumber": "A12",
  "deviceNames": "service-device-1",
  "message": "Order delivered to table A12",
  "version": 2
}

The state field reflects the new state. The completeTime is populated automatically by the server when transitioning to COMPLETED or ABORTED.

Curl Examples

Success: Mark Order as Completed

bash
curl -i -X PUT \
  -H "api_key: abc123-def456-ghi789" \
  -H "Content-Type: application/json" \
  -d '{"newState": "COMPLETED", "comment": "Order delivered to table A12"}' \
  "https://{host}/orders/12345/statusupdate"

Response:

http
HTTP/1.1 200 OK
Content-Type: application/json

{
  "number": 12345,
  "state": "COMPLETED",
  ...
}

Success: Abort an Order

bash
curl -i -X PUT \
  -H "api_key: abc123-def456-ghi789" \
  -H "Content-Type: application/json" \
  -d '{"newState": "ABORTED", "comment": "Customer cancelled"}' \
  "https://{host}/orders/12345/statusupdate"

Invalid State Transition

bash
curl -i -X PUT \
  -H "api_key: abc123-def456-ghi789" \
  -H "Content-Type: application/json" \
  -d '{"newState": "SELECTING", "comment": "Trying to revert"}' \
  "https://{host}/orders/12345/statusupdate"

Response:

http
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "type": "about:blank",
  "title": "Illegal argument",
  "status": 400,
  "detail": "No enum constant com.ridme.pos.model.enums.OrderState.SELECTING",
  "instance": "/orders/12345/statusupdate"
}

Note: The error uses ProblemDetail (RFC 7807) format.

Order Not Found

bash
curl -i -X PUT \
  -H "api_key: abc123-def456-ghi789" \
  -H "Content-Type: application/json" \
  -d '{"newState": "COMPLETED"}' \
  "https://{host}/orders/99999/statusupdate"

Response:

http
HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "type": "about:blank",
  "title": "Illegal argument",
  "status": 400,
  "detail": "Order does not exist",
  "instance": "/orders/99999/statusupdate"
}

Duplicate and Idempotent Updates

The status update endpoint is not inherently idempotent. If you send the same status update twice, the second call will fail because the order's state has already changed from the original state. To handle this:

  • Track which orders you have already processed using the order number as an idempotency key.
  • Only send status updates for orders you have not yet processed.
  • If a status update fails with a 400 error, check the current order state via polling before retrying.

Error Handling

StatusMeaning
200Order status updated successfully
400Invalid state transition, invalid enum value, or order does not exist
401Unauthorized (invalid or expired API key)
409Optimistic locking conflict (another device modified the order concurrently)

For 409 conflicts, the server implements automatic retry with up to 3 attempts. If the conflict persists, the client should refresh its view of the order and retry.

Next Steps