> For the complete documentation index, see [llms.txt](https://docs.commercelayer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.commercelayer.io/metrics-api-reference/resources/orders/search.md).

# Search

To perform a search query on the order resource send a `POST` request to the `/orders/search` endpoint specifying in the payload the [query keys](#query-keys) and [filter](/metrics-api-reference/resources/orders/filters.md) parameters like in the generic example below:

```json
{
  "search": {
    "limit": ...,
    "sort": "...",
    "sort_by": "...",
    "fields": [ "...", "...", ... ],
    "cursor": "..."
  },
  "filter": { ... }
}
```

{% hint style="info" %}
Please find more information on how search queries work [here](/metrics/getting-started/queries/search.md).
{% endhint %}

### Query keys

These are the keys you need to set when performing a search query:

<table><thead><tr><th>Key</th><th>Type</th><th data-type="checkbox">Required</th><th>Description</th><th>Values</th></tr></thead><tbody><tr><td><strong><code>limit</code></strong></td><td>Integer</td><td>false</td><td>The maximum number of records shown in the response.</td><td>Default is <code>50</code>, max is <code>100</code>.</td></tr><tr><td><strong><code>sort</code></strong></td><td>String</td><td>false</td><td>The way you want the results of the query to be sorted.</td><td>One of <code>asc</code> or <code>desc</code> (default is <code>desc</code>).</td></tr><tr><td><strong><code>sort_by</code></strong></td><td>String</td><td>false</td><td>The date field you want the results of the query sorted by.</td><td><a href="#sort_by-values">Here</a> the full list of valid values for this key. Default is <code>order.current_date</code>.</td></tr><tr><td><strong><code>fields</code></strong></td><td>Array</td><td>true</td><td>The list of fields you want to be returned for each record in the response.</td><td><a href="#field-values">Here</a> the full list of valid values for this key. Cannot be empty. Use the <code>.*</code> syntax to request all the attribute for a specific field.</td></tr><tr><td><strong><code>cursor</code></strong></td><td>String</td><td>false</td><td>The cursor pointing to a specific page in the paginated search results.</td><td>Every time you perform a search query you get the cursor to the next page in the <code>pagination</code> object.</td></tr></tbody></table>

### `sort_by` values

These are the valid values you can specify for the `sort_by` key of the search query:

* `order.approved_at`
* `order.archived_at`
* `order.cancelled_at`
* `order.created_at`
* `order.current_date`
* `order.fulfillment_updated_at`
* `order.payment_updated_at`
* `order.placed_at`
* `order.updated_at`

### `field` values

These are the valid values you can specify for the `field` key of the search query:

* `billing_address.*`
* `billing_address.business`
* `billing_address.city`
* `billing_address.company`
* `billing_address.country_code`
* `billing_address.first_name`
* `billing_address.geocoded`
* `billing_address.last_name`
* `billing_address.localized`
* `billing_address.state_code`
* `billing_address.zip_code`
* `customer.*`
* `customer.email`
* `customer.group_name`
* `customer.id`
* `customer.reference`
* `customer.reference_origin`
* `line_items.*`
* `line_items.code`
* `line_items.discount`
* `line_items.id`
* `line_items.item_id`
* `line_items.item_type`
* `line_items.name`
* `line_items.options.*`
* `line_items.options.id`
* `line_items.options.name`
* `line_items.options.quantity`
* `line_items.options.total_amount`
* `line_items.options.unit_amount`
* `line_items.options_amount`
* `line_items.quantity`
* `line_items.tax_amount`
* `line_items.tax_rate`
* `line_items.total_amount`
* `line_items.unit_amount`
* `line_items.updated_at`
* `market.*`
* `market.id`
* `market.name`
* `market.number`
* `order.*`
* `order.adjustment_amount`
* `order.adjustment_tax_amount`
* `order.adjustment_taxable_amount`
* `order.affiliate_code`
* `order.aggregated_details`
* `order.approved_at`
* `order.archived`
* `order.archived_at`
* `order.cancelled_at`
* `order.country_code`
* `order.coupon`
* `order.coupon_code`
* `order.created_at`
* `order.currency_code`
* `order.current_date`
* `order.customer_type`
* `order.discount_amount`
* `order.discounted`
* `order.duty_amount`
* `order.freight_taxable`
* `order.fulfillment_status`
* `order.fulfillment_updated_at`
* `order.gift_card`
* `order.gift_card_amount`
* `order.gift_card_code`
* `order.guest`
* `order.id`
* `order.language_code`
* `order.line_item_options_count`
* `order.link_id`
* `order.number`
* `order.options`
* `order.payment_method_amount`
* `order.payment_method_tax_amount`
* `order.payment_method_taxable_amount`
* `order.payment_status`
* `order.payment_updated_at`
* `order.placed_at`
* `order.placed_day_of_week`
* `order.reference`
* `order.reference_origin`
* `order.refunded`
* `order.refunds_total_amount_with_taxes`
* `order.returned`
* `order.seconds_in_approved`
* `order.seconds_in_draft`
* `order.seconds_in_placed`
* `order.shipments_count`
* `order.shipping_amount`
* `order.shipping_taxable_amount`
* `order.skus_count`
* `order.status`
* `order.store_id`
* `order.subtotal_amount`
* `order.subtotal_tax_amount`
* `order.subtotal_taxable_amount`
* `order.tax_included`
* `order.total_amount`
* `order.total_amount_with_taxes`
* `order.total_amount_with_taxes_net_of_refunds`
* `order.total_tax_amount`
* `order.total_taxable_amount`
* `order.updated_at`
* `order.user_id`
* `payment_method.*`
* `payment_method.card_type`
* `payment_method.id`
* `payment_method.issuer`
* `payment_method.issuer_type`
* `payment_method.moto`
* `payment_method.name`
* `payment_method.source_type`
* `refunds.*`
* `refunds.amount`
* `refunds.id`
* `refunds.number`
* `resource_errors.*`
* `resource_errors.code`
* `resource_errors.created_at`
* `resource_errors.id`
* `resource_errors.message`
* `resource_errors.name`
* `resource_errors.updated_at`
* `shipments.*`
* `shipments.cancelled_at`
* `shipments.cost_amount`
* `shipments.created_at`
* `shipments.delivered_at`
* `shipments.fulfillment_time`
* `shipments.id`
* `shipments.items`
* `shipments.items_count`
* `shipments.number`
* `shipments.on_hold_at`
* `shipments.packing_at`
* `shipments.picking_at`
* `shipments.ready_to_ship_at`
* `shipments.reference`
* `shipments.reference_origin`
* `shipments.seconds_in_picking`
* `shipments.seconds_in_ready_to_ship`
* `shipments.seconds_in_shipped`
* `shipments.shipped_at`
* `shipments.shipping_category.*`
* `shipments.shipping_category.id`
* `shipments.shipping_category.name`
* `shipments.shipping_category.reference`
* `shipments.shipping_category.reference_origin`
* `shipments.shipping_method.*`
* `shipments.shipping_method.currency_code`
* `shipments.shipping_method.id`
* `shipments.shipping_method.name`
* `shipments.shipping_method.reference`
* `shipments.shipping_method.reference_origin`
* `shipments.status`
* `shipments.stock_location.*`
* `shipments.stock_location.id`
* `shipments.stock_location.name`
* `shipments.stock_location.reference`
* `shipments.stock_location.reference_origin`
* `shipments.tags.*`
* `shipments.tags.id`
* `shipments.tags.name`
* `shipments.updated_at`
* `shipping_address.*`
* `shipping_address.business`
* `shipping_address.city`
* `shipping_address.country_code`
* `shipping_address.geocoded`
* `shipping_address.localized`
* `shipping_address.state_code`
* `shipping_address.zip_code`
* `tags.*`
* `tags.id`
* `tags.name`


---

# 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.commercelayer.io/metrics-api-reference/resources/orders/search.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.
