> For the complete documentation index, see [llms.txt](https://docs.bulkmail.shop/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bulkmail.shop/orders.md).

# Orders

Order management and purchases

## GET /orders

> List user orders

```json
{"openapi":"3.1.0","info":{"title":"BulkMail API","version":"2.0.0"},"tags":[{"name":"Orders","description":"Order management and purchases"}],"servers":[{"url":"https://bulkmail.shop/api/v2","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authentication. Get your key from the dashboard."}},"schemas":{"Order":{"type":"object","properties":{"id":{"type":"integer"},"order_number":{"type":"string"},"product_name":{"type":"string"},"quantity":{"type":"integer"},"unit_price":{"type":"number","format":"float"},"total_amount":{"type":"number","format":"float"},"status":{"type":"string","enum":["pending","processing","completed","cancelled"]},"created_at":{"type":"string","format":"date-time"}}},"PaginationMeta":{"type":"object","properties":{"current_page":{"type":"integer"},"per_page":{"type":"integer"},"total":{"type":"integer"},"total_pages":{"type":"integer"}}},"Error":{"type":"object","properties":{"success":{"type":"boolean"},"error":{"type":"string"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}}},"responses":{"Unauthorized":{"description":"Authentication required or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"paths":{"/orders":{"get":{"tags":["Orders"],"summary":"List user orders","parameters":[{"name":"page","in":"query","schema":{"type":"integer","default":1}},{"name":"per_page","in":"query","schema":{"type":"integer","default":20}},{"name":"status","in":"query","schema":{"type":"string","enum":["pending","processing","completed","cancelled"]}}],"responses":{"200":{"description":"List of orders","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"type":"array","items":{"$ref":"#/components/schemas/Order"}},"meta":{"$ref":"#/components/schemas/PaginationMeta"}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}}}}
```

## Create new order (purchase)

> Purchase products using wallet balance. Stock is delivered immediately upon successful purchase.\
> \
> \*\*Error Codes:\*\*\
> \- \`INSUFFICIENT\_BALANCE\` - Not enough balance\
> \- \`INSUFFICIENT\_STOCK\` - Not enough stock available<br>

```json
{"openapi":"3.1.0","info":{"title":"BulkMail API","version":"2.0.0"},"tags":[{"name":"Orders","description":"Order management and purchases"}],"servers":[{"url":"https://bulkmail.shop/api/v2","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authentication. Get your key from the dashboard."}},"schemas":{"Error":{"type":"object","properties":{"success":{"type":"boolean"},"error":{"type":"string"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}}},"responses":{"Unauthorized":{"description":"Authentication required or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"paths":{"/orders":{"post":{"tags":["Orders"],"summary":"Create new order (purchase)","description":"Purchase products using wallet balance. Stock is delivered immediately upon successful purchase.\n\n**Error Codes:**\n- `INSUFFICIENT_BALANCE` - Not enough balance\n- `INSUFFICIENT_STOCK` - Not enough stock available\n","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["product_id","quantity"],"properties":{"product_id":{"type":"integer"},"quantity":{"type":"integer","minimum":1}}}}}},"responses":{"201":{"description":"Order created","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"message":{"type":"string"},"data":{"type":"object","properties":{"id":{"type":"integer"},"order_number":{"type":"string"},"quantity":{"type":"integer"},"total_amount":{"type":"number","format":"float"},"status":{"type":"string"},"stock_items":{"type":"array","items":{"type":"string"},"description":"Array of email:password strings"}}}}}}}},"400":{"description":"Bad request (insufficient balance/stock)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"$ref":"#/components/responses/Unauthorized"}}}}}}
```

## GET /orders/{id}

> Get order details

```json
{"openapi":"3.1.0","info":{"title":"BulkMail API","version":"2.0.0"},"tags":[{"name":"Orders","description":"Order management and purchases"}],"servers":[{"url":"https://bulkmail.shop/api/v2","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authentication. Get your key from the dashboard."}},"schemas":{"Order":{"type":"object","properties":{"id":{"type":"integer"},"order_number":{"type":"string"},"product_name":{"type":"string"},"quantity":{"type":"integer"},"unit_price":{"type":"number","format":"float"},"total_amount":{"type":"number","format":"float"},"status":{"type":"string","enum":["pending","processing","completed","cancelled"]},"created_at":{"type":"string","format":"date-time"}}},"Error":{"type":"object","properties":{"success":{"type":"boolean"},"error":{"type":"string"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}}},"responses":{"Unauthorized":{"description":"Authentication required or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"NotFound":{"description":"Resource not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"paths":{"/orders/{id}":{"get":{"tags":["Orders"],"summary":"Get order details","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Order details with stock items","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"data":{"type":"object","allOf":[{"$ref":"#/components/schemas/Order"},{"type":"object","properties":{"stock_items":{"type":"array","items":{"type":"string"}}}}]}}}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}}}}
```

## Cancel order

> Only pending orders can be cancelled. Refund will be credited to wallet.

```json
{"openapi":"3.1.0","info":{"title":"BulkMail API","version":"2.0.0"},"tags":[{"name":"Orders","description":"Order management and purchases"}],"servers":[{"url":"https://bulkmail.shop/api/v2","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authentication. Get your key from the dashboard."}},"responses":{"Unauthorized":{"description":"Authentication required or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"NotFound":{"description":"Resource not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"schemas":{"Error":{"type":"object","properties":{"success":{"type":"boolean"},"error":{"type":"string"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}}}},"paths":{"/orders/{id}/cancel":{"post":{"tags":["Orders"],"summary":"Cancel order","description":"Only pending orders can be cancelled. Refund will be credited to wallet.","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"responses":{"200":{"description":"Order cancelled","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"message":{"type":"string"},"data":{"type":"object","properties":{"refunded_amount":{"type":"number","format":"float"}}}}}}}},"400":{"description":"Order cannot be cancelled"},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}}}}
```

## GET /orders/{id}/export

> Export order stock

```json
{"openapi":"3.1.0","info":{"title":"BulkMail API","version":"2.0.0"},"tags":[{"name":"Orders","description":"Order management and purchases"}],"servers":[{"url":"https://bulkmail.shop/api/v2","description":"Production server"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","in":"header","name":"X-API-Key","description":"API key for authentication. Get your key from the dashboard."}},"responses":{"Unauthorized":{"description":"Authentication required or invalid","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"NotFound":{"description":"Resource not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}},"schemas":{"Error":{"type":"object","properties":{"success":{"type":"boolean"},"error":{"type":"string"},"errors":{"type":"object","additionalProperties":{"type":"array","items":{"type":"string"}}}}}}},"paths":{"/orders/{id}/export":{"get":{"tags":["Orders"],"summary":"Export order stock","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}},{"name":"format","in":"query","schema":{"type":"string","enum":["txt","csv","json"],"default":"txt"}}],"responses":{"200":{"description":"Exported data","content":{"text/plain":{"schema":{"type":"string"}},"text/csv":{"schema":{"type":"string"}},"application/json":{"schema":{"type":"object"}}}},"401":{"$ref":"#/components/responses/Unauthorized"},"404":{"$ref":"#/components/responses/NotFound"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.bulkmail.shop/orders.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
