# Export new orders

Send details about new orders placed in your store to an external service automatically.

<figure><img src="/files/sEksFnyraHtoJ8HMU5ol" alt=""><figcaption></figcaption></figure>

### Step 1. Connect order webhooks

To start receiving automatic notifications about new orders placed in your store, you need to set up webhooks in your store: [Set up webhooks](/webhook-automations/setup-webhooks/set-up-webhooks-for-your-app.md)

Request only one `order.created` event required for this flow.

### Step 2. Parse webhooks for order ID

With webhooks set up, when a new order is placed in the store, Ecwid automatically sends a POST request to your server. It contains the order ID and its payment and fulfillment statuses in a body JSON.

For further automation, you need to automate webhook processing. Check out the following articles to get started:

[Code example for webhook processing](/webhook-automations/setup-webhooks/code-example-for-webhook-handling.md)

[Event data in webhooks](/webhook-automations/learn-ecwid-webhooks/event-data-in-webhooks.md)

Get the **order ID** from the webhook body and save it as a variable.

### Step 3. Automate REST API calls

Now you have everything to automate making a REST API call upon receiving a webhook. The [Get order](/api-reference/rest-api/orders/get-order.md) call requires 3 variables:

* **Store ID**
* **Order ID**
* **App's** `secret_token`

You can "hardcode" the **store ID** and `secret_token` on your server's backend as they are constants (as long as the app is not uninstalled/reinstalled in the store). This leaves only one variable – **order ID** – that you can get from the webhook body.

Additionally, you can pre-define the data you want to receive by limiting Ecwid API's response with specific fields. If not limited, you'll receive full order details with hundreds of fields, which can slow down your application.

```php
<?php

$storeId = '1003'; // your store ID
$orderId = 'K8XTQ'; // order ID from webhook body
$rfields = urlencode('responseFields=id,total,email,paymentMethod'); // Specify fields for the response, changes ',' to %2C
$sToken = 'secret_J9fKJHgiw5PPNJdcLUvucV6gvtXmScjP'; // your app's secret_token
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://app.ecwid.com/api/v3/$storeId/orders/$orderId?$rfields',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Bearer $sToken'
  ),
));

$response = curl_exec($curl);

curl_close($curl);

// $response variable is a JSON with order details
```

### Step 4. Parse the REST API response and send the data

Now you have the details of the new order on your server. Parse the `$response` variable from the example above and send the details to an external service of your choice.


---

# Agent Instructions: 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:

```
GET https://docs.ecwid.com/webhook-automations/webhook-flow-examples/export-new-orders.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
