# Resty Orders API

Λάβετε μη εκτυπωμένα δελτία κουζίνας και αποδείξεις ως πλήρες JSON και σημειώστε τις ως εκτυπωμένες μέσω API — ιδανικό για εκτυπωτές κουζίνας, POS και AI agents.

## Authentication

Στείλτε το Orders API key σε κάθε αίτημα. Μην το εκθέτετε σε δημόσιο front-end κώδικα.

```http
X-Api-Key: YOUR_ORDERS_API_KEY
```

Alternatively: `Authorization: Bearer YOUR_ORDERS_API_KEY`

Generate or rotate the key in **Dashboard → Settings → Orders API**.

## 1) List unprinted orders (kitchen tickets)

```
GET https://resty.gr/api/public/orders/unprinted
```

Επιστρέφει JSON με ok, username, currency, count και πίνακα orders. Περιλαμβάνονται μόνο δελτία κουζίνας με Εκτυπωμένη = Όχι (έως 500, από τις παλαιότερες). Αν η παραγγελία έχει τιμολογηθεί, περιλαμβάνονται invoice (JSON Wrapp/απόδειξης) και invoice_receipt_printed· αλλιώς invoice είναι null.

Top-level keys: `ok`, `username`, `currency` (`code`, `symbol`, `label`, `position`), `count`, `orders`.
Each order may include `invoice` (saved Wrapp/receipt JSON) and `invoice_receipt_printed`.

### Example request

```bash
curl -sS -H "X-Api-Key: YOUR_ORDERS_API_KEY" "https://resty.gr/api/public/orders/unprinted"
```

### Example response

```json
{
    "ok": true,
    "username": "your_username",
    "currency": {
        "code": "EUR",
        "symbol": "€",
        "label": "EUR — Euro (€)",
        "position": "left"
    },
    "count": 1,
    "orders": [
        {
            "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "order_code": "A104",
            "username": "your_username",
            "currency": {
                "code": "EUR",
                "symbol": "€",
                "label": "EUR — Euro (€)",
                "position": "left"
            },
            "status_id": "…",
            "status_name": "Preparing",
            "status_color": "#22c55e",
            "order_mode": "in_store",
            "floor_table_id": "…",
            "floor_table_code": "T12",
            "customer_inputs": {
                "custom_fields": [
                    {
                        "label": "Name",
                        "value": "Maria"
                    },
                    {
                        "label": "Phone",
                        "value": "6900000000"
                    },
                    {
                        "label": "Address",
                        "value": ""
                    }
                ]
            },
            "custom_fields": [
                {
                    "label": "Name",
                    "value": "Maria"
                },
                {
                    "label": "Phone",
                    "value": "6900000000"
                },
                {
                    "label": "Address",
                    "value": ""
                }
            ],
            "cart_items": [
                {
                    "id": "line_…",
                    "product_id": "…",
                    "name": "Burger",
                    "quantity": 2,
                    "unit_price": 8.5,
                    "total_num": 17,
                    "comment": "No onions",
                    "option_labels": [
                        "Size: Large",
                        "Extra cheese"
                    ],
                    "options": [
                        {
                            "group_id": "…",
                            "group": "Size",
                            "item_id": "…",
                            "label": "Large",
                            "price_num": 1
                        },
                        {
                            "group_id": "…",
                            "group": "Extras",
                            "item_id": "…",
                            "label": "Extra cheese",
                            "price_num": 0.5
                        }
                    ],
                    "selections": {},
                    "thumb_url": ""
                }
            ],
            "cart_total": 17,
            "show_on_order_screen": true,
            "is_printed": false,
            "payment_method_type": null,
            "invoice": null,
            "invoice_receipt_printed": false,
            "created_at": "2026-07-20 12:00:00",
            "updated_at": "2026-07-20 12:01:00",
            "created_at_unix": 1721476800,
            "updated_at_unix": 1721476860
        }
    ]
}
```

## 2) Mark kitchen ticket as printed

```
POST https://resty.gr/api/public/orders/{orderId}/printed
```

Ορίζει Εκτυπωμένη = Ναι για αυτή την παραγγελία (του εμπόρου του API key). Η απάντηση περιλαμβάνει username και currency. Είναι ασφαλές να ξανακληθεί: επιστρέφει ok με already_printed true.

Replace `{orderId}` with the order `id` UUID from the list response.

### Example request

```bash
curl -sS -X POST -H "X-Api-Key: YOUR_ORDERS_API_KEY" "https://resty.gr/api/public/orders/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/printed"
```

### Example response

```json
{
    "ok": true,
    "username": "your_username",
    "currency": {
        "code": "EUR",
        "symbol": "€",
        "label": "EUR — Euro (€)",
        "position": "left"
    },
    "order_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "order_code": "A104",
    "is_printed": true,
    "already_printed": false
}
```

- `already_printed: true` means the order was already Yes; the call is still success.
- After a successful mark, the order no longer appears in the unprinted list.

## 3) List unprinted receipts

```
GET https://resty.gr/api/public/orders/unprinted-receipts
```

Επιστρέφει παραγγελίες με αποθηκευμένο invoice/receipt JSON και Απόδειξη = Όχι (έως 500). Κάθε cart_items[] έχει vat_rate, net_total, vat_total για εκτύπωση απόδειξης. Εκτυπώστε με cart_items (+ invoice) και μετά κάντε σήμανση receipt-printed.

### Example request

```bash
curl -sS -H "X-Api-Key: YOUR_ORDERS_API_KEY" "https://resty.gr/api/public/orders/unprinted-receipts"
```

### Example response

```json
{
    "ok": true,
    "username": "your_username",
    "currency": {
        "code": "EUR",
        "symbol": "€",
        "label": "EUR — Euro (€)",
        "position": "left"
    },
    "count": 1,
    "orders": [
        {
            "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
            "order_code": "A104",
            "username": "your_username",
            "currency": {
                "code": "EUR",
                "symbol": "€",
                "label": "EUR — Euro (€)",
                "position": "left"
            },
            "status_id": "…",
            "status_name": "Completed",
            "status_color": "#22c55e",
            "order_mode": "in_store",
            "floor_table_id": "…",
            "floor_table_code": "T12",
            "customer_inputs": {
                "custom_fields": [
                    {
                        "label": "Name",
                        "value": "Maria"
                    },
                    {
                        "label": "Phone",
                        "value": "6900000000"
                    }
                ]
            },
            "custom_fields": [
                {
                    "label": "Name",
                    "value": "Maria"
                },
                {
                    "label": "Phone",
                    "value": "6900000000"
                }
            ],
            "cart_items": [
                {
                    "id": "line_…",
                    "product_id": "…",
                    "name": "Burger",
                    "quantity": 2,
                    "unit_price": 8.5,
                    "total_num": 17,
                    "net_total": 13.71,
                    "vat_total": 3.29,
                    "vat_rate": 24,
                    "vat_exemption_code": null,
                    "comment": "No onions",
                    "option_labels": [
                        "Size: Large"
                    ],
                    "options": [
                        {
                            "group_id": "…",
                            "group": "Size",
                            "item_id": "…",
                            "label": "Large",
                            "price_num": 1
                        }
                    ],
                    "selections": {},
                    "thumb_url": ""
                },
                {
                    "id": "line_…",
                    "product_id": "…",
                    "name": "Coffee",
                    "quantity": 1,
                    "unit_price": 2.5,
                    "total_num": 2.5,
                    "net_total": 2.21,
                    "vat_total": 0.29,
                    "vat_rate": 13,
                    "vat_exemption_code": null,
                    "comment": "",
                    "option_labels": [],
                    "options": [],
                    "selections": {},
                    "thumb_url": ""
                }
            ],
            "cart_total": 19.5,
            "show_on_order_screen": true,
            "is_printed": true,
            "payment_method_type": 0,
            "invoice": {
                "invoice_id": "wrapp-…",
                "mark": "123456789",
                "my_data_uid": "…",
                "my_data_qr_url": "https://…",
                "wrapp_invoice_url": "https://…",
                "pdf_url": "https://…",
                "pdf_status": "ready",
                "payment_method_type": 0,
                "pos_device_id": "",
                "sandbox": false,
                "has_pdf": true,
                "receipt_printed": false,
                "request_payload": {
                    "invoice_lines": [
                        {
                            "line_number": 1,
                            "name": "Burger",
                            "quantity": 2,
                            "unit_price": 6.85,
                            "net_total_price": 13.71,
                            "vat_rate": 24,
                            "vat_total": 3.29,
                            "subtotal": 17
                        },
                        {
                            "line_number": 2,
                            "name": "Coffee",
                            "quantity": 1,
                            "unit_price": 2.21,
                            "net_total_price": 2.21,
                            "vat_rate": 13,
                            "vat_total": 0.29,
                            "subtotal": 2.5
                        }
                    ]
                }
            },
            "invoice_receipt_printed": false,
            "created_at": "2026-07-20 12:00:00",
            "updated_at": "2026-07-20 12:05:00",
            "created_at_unix": 1721476800,
            "updated_at_unix": 1721477100
        }
    ]
}
```

Every order in this feed has a non-null `invoice` object. Use `invoice` (+ `cart_items`) to print the receipt, then mark it printed.

## 4) Mark receipt as printed

```
POST https://resty.gr/api/public/orders/{orderId}/receipt-printed
```

Ορίζει invoice_receipt_printed = Ναι και ενημερώνει invoice.receipt_printed στο αποθηκευμένο JSON. Είναι ασφαλείς επανακλήσεις. Μετά την επιτυχία, η παραγγελία φεύγει από το unprinted-receipts.

### Example request

```bash
curl -sS -X POST -H "X-Api-Key: YOUR_ORDERS_API_KEY" "https://resty.gr/api/public/orders/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/receipt-printed"
```

### Example response

```json
{
    "ok": true,
    "username": "your_username",
    "currency": {
        "code": "EUR",
        "symbol": "€",
        "label": "EUR — Euro (€)",
        "position": "left"
    },
    "order_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "order_code": "A104",
    "invoice_receipt_printed": true,
    "already_printed": false
}
```

## Order object fields (list response)

| Field | Description |
| --- | --- |
| `id` | UUID παραγγελίας (χρησιμοποιήστε το ως {orderId} στη σήμανση). |
| `order_code` | Αναγνώσιμος κωδικός παραγγελίας. |
| `username` | Username εμπόρου (επιστρέφεται και στο top level της λίστας/σήμανσης). |
| `currency` | Νόμισμα εμφάνισης από τις Ρυθμίσεις: {code, symbol, label, position} όπου position είναι left ή right. Επιστρέφεται και στο top level. |
| `status_*` | Id, όνομα και χρώμα κατάστασης. |
| `order_mode` | delivery | takeaway | in_store (ή κενό για παλιές κάρτες). |
| `floor_table_*` | Id και κωδικός τραπεζιού όταν είναι στο κατάστημα. |
| `customer_inputs` | Πλήρες αντικείμενο εισόδων (περιλαμβάνει custom_fields και τυχόν επιπλέον κλειδιά). |
| `custom_fields` | Όλα τα προσαρμοσμένα πεδία ως [{label, value}, …], συμπεριλαμβανομένων κενών τιμών. Η ίδια λίστα υπάρχει και στο customer_inputs.custom_fields. |
| `cart_items` | Λεπτομερείς γραμμές καλαθιού (όνομα, product_id, ποσότητα, τιμές, ΦΠΑ, σχόλιο, επιλογές, selections, thumb). |
| `cart_items[].quantity` | Ποσότητα γραμμής (ακέραιος, ελάχ. 1). |
| `cart_items[].unit_price` | Τιμή ανά μονάδα (πριν την ποσότητα). |
| `cart_items[].total_num` | Σύνολο γραμμής = unit_price × quantity. |
| `cart_items[].net_total` | Καθαρό ποσό γραμμής (χωρίς ΦΠΑ), υπολογισμένο από total_num και vat_rate. |
| `cart_items[].vat_total` | Ποσό ΦΠΑ γραμμής. |
| `cart_items[].vat_rate` | Ποσοστό ΦΠΑ της γραμμής (π.χ. 24, 13, 6, 0). Προεπιλογή 24 αν λείπει από παλιές παραγγελίες. |
| `cart_items[].vat_exemption_code` | Κωδικός απαλλαγής myDATA όταν vat_rate = 0· αλλιώς null. |
| `cart_items[].comment` | Προαιρετική σημείωση κουζίνας/προσωπικού για τη γραμμή. |
| `cart_items[].options` | Επιλεγμένες επιλογές ως [{group, label, price_num, …}] και option_labels. |
| `cart_total` | Άθροισμα των total_num των γραμμών. |
| `show_on_order_screen` | Αν εμφανίζεται στην οθόνη παραγγελιών. |
| `invoice.request_payload.invoice_lines` | Γραμμές Wrapp με vat_rate / vat_total (αν αποθηκεύτηκαν στο invoice JSON). Χρήσιμο ως εναλλακτική πηγή για την απόδειξη. |
| `is_printed` | Σημαία εκτύπωσης δελτίου κουζίνας (πάντα false στη λίστα μη εκτυπωμένων). |
| `payment_method_type` | Τύπος πληρωμής checkout όταν έχει τιμολογηθεί: 0 = μετρητά, 3 = κάρτα, 7 = IRIS· null αν δεν έχει οριστεί / μόνο προώθηση. |
| `invoice` | Αποθηκευμένο JSON τιμολογίου/απόδειξης Wrapp όταν έχει τιμολογηθεί· αλλιώς null. Περιλαμβάνει mark, pdf_url, has_pdf, receipt_printed και σχετικά πεδία Wrapp. |
| `invoice_receipt_printed` | Σημαία εκτύπωσης απόδειξης (false στο unprinted-receipts). Σήμανση με POST …/receipt-printed. |
| `invoice.receipt_printed` | Η ίδια σημαία μέσα στο invoice.receipt_printed (συγχρονισμένη με invoice_receipt_printed). |
| `created_at` / `updated_at` | Datetime MySQL και unix timestamps. |

## Receipt print tip

Για κάθε γραμμή στο cart_items εκτυπώστε name, quantity, total_num και από κάτω το vat_rate (%) μαζί με net_total / vat_total. Τα ίδια ποσοστά υπάρχουν και στο invoice.request_payload.invoice_lines[].vat_rate.

Example line layout:

```
2× Burger                 €17.00
   VAT 24%   net €13.71   VAT €3.29
1× Coffee                  €2.50
   VAT 13%   net €2.21    VAT €0.29
```

## Recommended automation flow

1. Poll `GET …/unprinted` every 5–15 seconds for kitchen tickets.
2. Print each ticket, then `POST …/orders/{id}/printed`.
3. Poll `GET …/unprinted-receipts` for invoiced orders; print using `invoice` + `cart_items`.
4. Call `POST …/orders/{id}/receipt-printed` so the receipt leaves that feed.

## AI / integration notes

Κατεβάστε το Markdown και επισυνάψτε το στις οδηγίες του agent. Κάντε poll δελτία (…/unprinted) και αποδείξεις (…/unprinted-receipts). Στην απόδειξη δείξτε κάθε είδος με vat_rate / net_total / vat_total, μετά POST …/printed ή …/receipt-printed.
