# Add Orders to an Optimization

Last updated:

<!-- -->

October 18, 2026

<!-- -->

\| 4 minutes read

<br />

<br />

This example demonstrates how to add a list of orders to an existing optimization. The newly added orders will be assigned to the optimization’s routes if the optimization is reoptimized. If reoptimization is not enabled, the added orders will be stored but not assigned to routes.

## How to Use the Sample[​](#how-to-use-the-sample "Direct link to How to Use the Sample")

When you run the example application:

1. The specified orders are added to the existing optimization.
2. If reoptimization is enabled, the optimization will be updated, and a new solution will be generated.

## Step-by-Step Guide[​](#step-by-step-guide "Direct link to Step-by-Step Guide")

### Step 1: Retrieve the existing Optimization[​](#step-1-retrieve-the-existing-optimization "Direct link to Step 1: Retrieve the existing Optimization")

To add orders to an optimization, you have to retrieve that optimization by id.

* **Method:** `GET`

* **Endpoint:** `/optimizations/{id}`

* **Headers:**

  * `Authorization: YOUR_API_KEY`
  * `Content-Type: application/json`

* **Path Parameter:**
  * `id` (integer, \**required*) - The unique optimization ID.

#### Example:[​](#example "Direct link to Example:")

* **Response Body:** (error code `200`)

```json
{
  "id": 137831,
  "orders": [
    {
      "id": 879888,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791105,
        "alias": "Customer 1",
        "firstName": "Customer1",
        "lastName": "Customer1",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer1@example.com",
        "phoneNumber": "+12025550180",
        "location": [
          48.870852,
          2.356148
        ],
        "customData": ""
      },
      "location": [
        48.870852,
        2.356148
      ],
      "alias": "Customer 1",
      "firstName": "Customer1",
      "lastName": "Customer1",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550180",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 0,
      "weight": 0,
      "cube": 0,
      "revenue": 0,
      "timeWindow": [
        420,
        1086
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879887,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791104,
        "alias": "Customer 2",
        "firstName": "Customer2",
        "lastName": "Customer2",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer2@example.com",
        "phoneNumber": "+12025550181",
        "location": [
          48.827327,
          2.342267
        ],
        "customData": ""
      },
      "location": [
        48.827327,
        2.342267
      ],
      "alias": "Customer 2",
      "firstName": "Customer2",
      "lastName": "Customer2",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550181",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 0,
      "weight": 0,
      "cube": 0,
      "revenue": 0,
      "timeWindow": [
        420,
        1086
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879886,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791103,
        "alias": "Customer 3",
        "firstName": "Customer3",
        "lastName": "Customer3",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer3@example.com",
        "phoneNumber": "+12025550182",
        "location": [
          48.88025,
          2.299601
        ],
        "customData": ""
      },
      "location": [
        48.88025,
        2.299601
      ],
      "alias": "Customer 3",
      "firstName": "Customer3",
      "lastName": "Customer3",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550182",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 3,
      "weight": 5.1,
      "cube": 2.5,
      "revenue": 12,
      "timeWindow": [
        770,
        1020
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879885,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791102,
        "alias": "Customer 4",
        "firstName": "Customer4",
        "lastName": "Customer4",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer4@example.com",
        "phoneNumber": "+12025550183",
        "location": [
          48.845198,
          2.402896
        ],
        "customData": ""
      },
      "location": [
        48.845198,
        2.402896
      ],
      "alias": "Customer 4",
      "firstName": "Customer4",
      "lastName": "Customer4",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550183",
      "customData": "",
      "type": 1,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 8,
      "weight": 15.4,
      "cube": 5.8,
      "revenue": 2.7,
      "timeWindow": [
        753,
        1036
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879884,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791101,
        "alias": "Customer 5",
        "firstName": "Customer5",
        "lastName": "Customer5",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer5@example.com",
        "phoneNumber": "+12025550184",
        "location": [
          48.897163,
          2.292865
        ],
        "customData": ""
      },
      "location": [
        48.897163,
        2.292865
      ],
      "alias": "Customer 5",
      "firstName": "Customer5",
      "lastName": "Customer5",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550184",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 9,
      "weight": 16.2,
      "cube": 8.4,
      "revenue": 7.5,
      "timeWindow": [
        736,
        1086
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879883,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791100,
        "alias": "Customer 6",
        "firstName": "Customer6",
        "lastName": "Customer6",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer6@example.com",
        "phoneNumber": "+12025550185",
        "location": [
          48.90092,
          2.400039
        ],
        "customData": ""
      },
      "location": [
        48.90092,
        2.400039
      ],
      "alias": "Customer 6",
      "firstName": "Customer6",
      "lastName": "Customer6",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550185",
      "customData": "",
      "type": 1,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 9,
      "weight": 16.5,
      "cube": 9.7,
      "revenue": 10,
      "timeWindow": [
        786,
        1053
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879882,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791099,
        "alias": "Customer 7",
        "firstName": "Customer7",
        "lastName": "Customer7",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer7@example.com",
        "phoneNumber": "+12025550186",
        "location": [
          48.860914,
          2.310625
        ],
        "customData": ""
      },
      "location": [
        48.860914,
        2.310625
      ],
      "alias": "Customer 7",
      "firstName": "Customer7",
      "lastName": "Customer7",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550186",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 5,
      "weight": 7.5,
      "cube": 2.6,
      "revenue": 13.4,
      "timeWindow": [
        820,
        1020
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879881,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791098,
        "alias": "Customer 8",
        "firstName": "Customer8",
        "lastName": "Customer8",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer8@example.com",
        "phoneNumber": "+12025550187",
        "location": [
          48.827865,
          2.379216
        ],
        "customData": ""
      },
      "location": [
        48.827865,
        2.379216
      ],
      "alias": "Customer 8",
      "firstName": "Customer8",
      "lastName": "Customer8",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550187",
      "customData": "",
      "type": 1,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 11,
      "weight": 12.1,
      "cube": 4.6,
      "revenue": 14.7,
      "timeWindow": [
        753,
        1086
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879880,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791097,
        "alias": "Customer 9",
        "firstName": "Customer9",
        "lastName": "Customer9",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer9@example.com",
        "phoneNumber": "+12025550188",
        "location": [
          48.887096,
          2.283513
        ],
        "customData": ""
      },
      "location": [
        48.887096,
        2.283513
      ],
      "alias": "Customer 9",
      "firstName": "Customer9",
      "lastName": "Customer9",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550188",
      "customData": "",
      "type": 1,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 6,
      "weight": 5.2,
      "cube": 1.5,
      "revenue": 2.9,
      "timeWindow": [
        770,
        1070
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879879,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791096,
        "alias": "Customer 10",
        "firstName": "Customer10",
        "lastName": "Customer10",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer10@example.com",
        "phoneNumber": "+12025550189",
        "location": [
          48.896894,
          2.321586
        ],
        "customData": ""
      },
      "location": [
        48.896894,
        2.321586
      ],
      "alias": "Customer 10",
      "firstName": "Customer10",
      "lastName": "Customer10",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550189",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 13,
      "weight": 6.3,
      "cube": 7.5,
      "revenue": 8.1,
      "timeWindow": [
        836,
        1053
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879878,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791095,
        "alias": "Customer 11",
        "firstName": "Customer11",
        "lastName": "Customer11",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer11@example.com",
        "phoneNumber": "+120255501810",
        "location": [
          48.870449,
          2.342204
        ],
        "customData": ""
      },
      "location": [
        48.870449,
        2.342204
      ],
      "alias": "Customer 11",
      "firstName": "Customer11",
      "lastName": "Customer11",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+120255501810",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 10,
      "weight": 8,
      "cube": 4.1,
      "revenue": 6.2,
      "timeWindow": [
        903,
        1020
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879877,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791094,
        "alias": "Customer 12",
        "firstName": "Customer12",
        "lastName": "Customer12",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer12@example.com",
        "phoneNumber": "+120255501811",
        "location": [
          48.895658,
          2.344043
        ],
        "customData": ""
      },
      "location": [
        48.895658,
        2.344043
      ],
      "alias": "Customer 12",
      "firstName": "Customer12",
      "lastName": "Customer12",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+120255501811",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 6,
      "weight": 4.8,
      "cube": 11.5,
      "revenue": 2.3,
      "timeWindow": [
        870,
        1020
      ],
      "serviceTime": 0,
      "depotId": 0
    }
  ],
  "departures": [
    {
      "depotId": 0,
      "alias": "Depot 1",
      "location": [
        48.870569,
        2.356448
      ],
      "address": {
        "country": "France",
        "state": "Ile-de-France",
        "county": "Paris",
        "city": "Paris",
        "postalCode": "75001",
        "streetName": "Rue de Rivoli",
        "streetNumber": "1"
      }
    },
    {
      "depotId": 0,
      "alias": "Depot 2",
      "location": [
        48.82674,
        2.342116
      ],
      "address": {
        "country": "France",
        "state": "Ile-de-France",
        "county": "Paris",
        "city": "Paris",
        "postalCode": "75002",
        "streetName": "Rue de Richelieu",
        "streetNumber": "2"
      }
    }
  ],
  "destinations": [
    {
      "alias": "Destination 1",
      "location": [
        48.898165,
        2.34484
      ],
      "address": {
        "country": "France",
        "state": "Ile-de-France",
        "county": "Paris",
        "city": "Paris",
        "postalCode": "75001",
        "streetName": "Rue de Rivoli",
        "streetNumber": "1"
      }
    },
    {
      "alias": "Destination 2",
      "location": [
        48.872064,
        2.402497
      ],
      "address": {
        "country": "France",
        "state": "Ile-de-France",
        "county": "Paris",
        "city": "Paris",
        "postalCode": "75002",
        "streetName": "Rue de Richelieu",
        "streetNumber": "2"
      }
    }
  ],
  "vehicles": [
    {
      "id": 135932,
      "type": 0,
      "status": 0,
      "name": "Car vehicle 1",
      "manufacturer": "Renault",
      "model": "Master",
      "fuelType": 2,
      "lastPosition": [
        48.870569,
        2.356448
      ],
      "consumption": 6.5,
      "plate": "AA-123-AA",
      "maxLoadWeight": 60,
      "maxLoadCube": 50,
      "height": 0,
      "width": 0,
      "weight": 0,
      "length": 0,
      "axleLoad": 0,
      "fixedCost": 0,
      "costPerHour": 0,
      "startTime": 420,
      "endTime": 1439
    },
    {
      "id": 135933,
      "type": 0,
      "status": 0,
      "name": "Car vehicle 2",
      "manufacturer": "Renault",
      "model": "Master",
      "fuelType": 2,
      "lastPosition": [
        48.82674,
        2.342116
      ],
      "consumption": 6.5,
      "plate": "AA-124-AA",
      "maxLoadWeight": 60,
      "maxLoadCube": 50,
      "height": 0,
      "width": 0,
      "weight": 0,
      "length": 0,
      "axleLoad": 0,
      "fixedCost": 0,
      "costPerHour": 0,
      "startTime": 420,
      "endTime": 1439
    }
  ],
  "vehiclesConstraints": [
    {
      "fuelPrice": 1.09,
      "startDate": 1596758400000,
      "maxNumberOfPackages": 53,
      "minNumberOfOrders": 0,
      "maxNumberOfOrders": 99999999,
      "minDistance": 0,
      "maxDistance": 99999999,
      "maxRevenue": 85
    }
  ],
  "configurationParameters": {
    "name": "Paris - test optimization",
    "ignoreTimeWindow": false,
    "allowDroppingOrders": false,
    "groupingOrders": false,
    "balancedRoutes": 0,
    "optimizationCriterion": 0,
    "arrangeCriterion": 0,
    "optimizationQuality": 2,
    "maxTimeToOptimize": 300,
    "maxWaitTime": 18000,
    "routeType": 2,
    "restrictions": 0,
    "distanceUnit": 0,
    "orderSequenceOptions": []
  },
  "creationTimestamp": 1752745377776,
  "matrixBuildType": 1,
  "request": {
    "id": 26551,
    "optimizationId": 137831,
    "status": 1,
    "message": "Operation done successfully!",
    "creationTimestamp": 1752745377776
  }
}

```

### Step 2: Create Customers and Orders[​](#step-2-create-customers-and-orders "Direct link to Step 2: Create Customers and Orders")

Note

Each order must have a customer associated with it. You can either:

* Create a new customer and assign it to the order.
* Use an existing customer (refer to the [Get Customer](/docs/cloud-rest-api/guides/fleet-management/core-concepts/customer.md#3-get-a-customer-by-id)).

#### Initializing and Adding Customers[​](#initializing-and-adding-customers "Direct link to Initializing and Adding Customers")

1. **Initialize Customers**: Create two `Customer` objects and populate their fields (e.g., name, address, contact details).
2. **Send Request**: Call the `Add Customers` endpoint to save these customers in the system.

* **Method:** `POST`

* **Endpoint:** `/customers`

* **Headers:**

  * `Authorization: YOUR_API_KEY`
  * `Content-Type: application/json`

* **URL:** `https://api.magiclane.net/api/v1/fleetmanagement/customers`

#### Example:[​](#example-1 "Direct link to Example:")

* **Request Body:**

```json
[
  {
    "alias": "Customer 13",
    "firstName": "Customer13",
    "lastName": "Customer13",
    "address": {
      "country": "",
      "state": "",
      "county": "",
      "city": "",
      "postalCode": "",
      "streetName": "",
      "streetNumber": ""
    },
    "email": "customer13@example.com",
    "phoneNumber": "+120255501813",
    "location": [
      48.868507,
      2.359727
    ],
    "customData": ""
  },
  {
    "alias": "Customer 14",
    "firstName": "Customer14",
    "lastName": "Customer14",
    "address": {
      "country": "",
      "state": "",
      "county": "",
      "city": "",
      "postalCode": "",
      "streetName": "",
      "streetNumber": ""
    },
    "email": "customer14@example.com",
    "phoneNumber": "+120255501814",
    "location": [
      48.867329,
      2.348105
    ],
    "customData": ""
  }
]

```

* **Response Body:** (error code `200`)
*

```json
[
  {
    "id": 1811911,
    "alias": "Customer 13",
    "firstName": "Customer13",
    "lastName": "Customer13",
    "address": {
      "country": "",
      "state": "",
      "county": "",
      "city": "",
      "postalCode": "",
      "streetName": "",
      "streetNumber": ""
    },
    "email": "customer13@example.com",
    "phoneNumber": "+120255501813",
    "location": [
      48.868507,
      2.359727
    ],
    "customData": ""
  },
  {
    "id": 1811912,
    "alias": "Customer 14",
    "firstName": "Customer14",
    "lastName": "Customer14",
    "address": {
      "country": "",
      "state": "",
      "county": "",
      "city": "",
      "postalCode": "",
      "streetName": "",
      "streetNumber": ""
    },
    "email": "customer14@example.com",
    "phoneNumber": "+120255501814",
    "location": [
      48.867329,
      2.348105
    ],
    "customData": ""
  }
]

```

#### Initializing and Adding Orders[​](#initializing-and-adding-orders "Direct link to Initializing and Adding Orders")

1. **Initialize Orders**: Create two `Order` objects and associate each with a customer. Populate fields such as time windows, package details, and weights.
2. **Send Request**: Call the `Add Orders` endpoint to save these orders in the system.

* **Method:** `POST`

* **Endpoint:** `/orders`

* **Headers:**

  * `Authorization: YOUR_API_KEY`
  * `Content-Type: application/json`

* **URL:** `https://api.magiclane.net/api/v1/fleetmanagement/orders`

#### Example:[​](#example-2 "Direct link to Example:")

* **Request Body:**

```json
[
  {
    "customerId": 1811911,
    "location": [
      48.868507,
      2.359727
    ],
    "alias": "Customer 13",
    "firstName": "Customer13",
    "lastName": "Customer13",
    "address": {
      "country": "",
      "state": "",
      "county": "",
      "city": "",
      "postalCode": "",
      "streetName": "",
      "streetNumber": ""
    },
    "phoneNumber": "+120255501813",
    "customData": "",
    "type": 0,
    "status": 0,
    "state": 1,
    "priority": 0,
    "numberOfPackages": 3,
    "weight": 3.1,
    "cube": 0.2,
    "revenue": 3.1,
    "timeWindow": [
      420,
      1086
    ],
    "serviceTime": 0,
    "depotId": 0
  },
  {
    "customerId": 1811912,
    "location": [
      48.867329,
      2.348105
    ],
    "alias": "Customer 14",
    "firstName": "Customer14",
    "lastName": "Customer14",
    "address": {
      "country": "",
      "state": "",
      "county": "",
      "city": "",
      "postalCode": "",
      "streetName": "",
      "streetNumber": ""
    },
    "phoneNumber": "+120255501814",
    "customData": "",
    "type": 1,
    "status": 0,
    "state": 1,
    "priority": 0,
    "numberOfPackages": 4,
    "weight": 4.1,
    "cube": 0.3,
    "revenue": 4.2,
    "timeWindow": [
      420,
      1086
    ],
    "serviceTime": 0,
    "depotId": 0
  }
]

```

* **Response Body:** (error code `200`)

```json
[
  {
    "id": 899037,
    "customerId": 1811911,
    "location": [
      48.868507,
      2.359727
    ],
    "alias": "Customer 13",
    "firstName": "Customer13",
    "lastName": "Customer13",
    "address": {
      "country": "",
      "state": "",
      "county": "",
      "city": "",
      "postalCode": "",
      "streetName": "",
      "streetNumber": ""
    },
    "phoneNumber": "+120255501813",
    "customData": "",
    "type": 0,
    "status": 0,
    "state": 1,
    "priority": 0,
    "numberOfPackages": 3,
    "weight": 3.1,
    "cube": 0.2,
    "revenue": 3.1,
    "timeWindow": [
      420,
      1086
    ],
    "serviceTime": 0,
    "depotId": 0
  },
  {
    "id": 899038,
    "customerId": 1811912,
    "location": [
      48.867329,
      2.348105
    ],
    "alias": "Customer 14",
    "firstName": "Customer14",
    "lastName": "Customer14",
    "address": {
      "country": "",
      "state": "",
      "county": "",
      "city": "",
      "postalCode": "",
      "streetName": "",
      "streetNumber": ""
    },
    "phoneNumber": "+120255501814",
    "customData": "",
    "type": 1,
    "status": 0,
    "state": 1,
    "priority": 0,
    "numberOfPackages": 4,
    "weight": 4.1,
    "cube": 0.3,
    "revenue": 4.2,
    "timeWindow": [
      420,
      1086
    ],
    "serviceTime": 0,
    "depotId": 0
  }
]

```

### Step 3: Add Orders to Optimization and Reoptimize[​](#step-3-add-orders-to-optimization-and-reoptimize "Direct link to Step 3: Add Orders to Optimization and Reoptimize")

Once the orders are created, they need to be added to the optimization.

* **Method:** `POST`

* **Endpoint:** `/optimizations/{id}/orders`

* **Headers:**

  * `Authorization: YOUR_API_KEY`
  * `Content-Type: application/json`

* **URL:** `https://api.magiclane.net/api/v1/fleetmanagement/optimizations/{id}/orders`

* **Path Parameter:**
  * `id` (integer, \**required*) - The unique optimization ID.

* **Query Parameters:**

  * `reoptimize` (integer, *optional*)

    <!-- -->

    * `0`: (default) - If the optimization will not be re-optimized, the orders will be added to the optimization's order list, but will not be in a route, so they won't be visited by any vehicle.
    * `1`: The route will be re-optimized.

#### Example:[​](#example-3 "Direct link to Example:")

* **Request Body:**

```json
{ 
    "orders":[
        898241,
        898242
    ]
}

```

* **Response Body:** (error code `200`)

note

There are two possible responses:

1. If the optimization is reoptimized, the response will be a request object with the status of the request.
2. If the optimization is not reoptimized, the response will be the updated optimization.

```json
{
  "id": 137831,
  "orders": [
    {
      "id": 879888,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791105,
        "alias": "Customer 1",
        "firstName": "Customer1",
        "lastName": "Customer1",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer1@example.com",
        "phoneNumber": "+12025550180",
        "location": [
          48.870852,
          2.356148
        ],
        "customData": ""
      },
      "location": [
        48.870852,
        2.356148
      ],
      "alias": "Customer 1",
      "firstName": "Customer1",
      "lastName": "Customer1",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550180",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 0,
      "weight": 0,
      "cube": 0,
      "revenue": 0,
      "timeWindow": [
        420,
        1086
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879887,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791104,
        "alias": "Customer 2",
        "firstName": "Customer2",
        "lastName": "Customer2",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer2@example.com",
        "phoneNumber": "+12025550181",
        "location": [
          48.827327,
          2.342267
        ],
        "customData": ""
      },
      "location": [
        48.827327,
        2.342267
      ],
      "alias": "Customer 2",
      "firstName": "Customer2",
      "lastName": "Customer2",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550181",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 0,
      "weight": 0,
      "cube": 0,
      "revenue": 0,
      "timeWindow": [
        420,
        1086
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879886,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791103,
        "alias": "Customer 3",
        "firstName": "Customer3",
        "lastName": "Customer3",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer3@example.com",
        "phoneNumber": "+12025550182",
        "location": [
          48.88025,
          2.299601
        ],
        "customData": ""
      },
      "location": [
        48.88025,
        2.299601
      ],
      "alias": "Customer 3",
      "firstName": "Customer3",
      "lastName": "Customer3",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550182",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 3,
      "weight": 5.1,
      "cube": 2.5,
      "revenue": 12,
      "timeWindow": [
        770,
        1020
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879885,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791102,
        "alias": "Customer 4",
        "firstName": "Customer4",
        "lastName": "Customer4",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer4@example.com",
        "phoneNumber": "+12025550183",
        "location": [
          48.845198,
          2.402896
        ],
        "customData": ""
      },
      "location": [
        48.845198,
        2.402896
      ],
      "alias": "Customer 4",
      "firstName": "Customer4",
      "lastName": "Customer4",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550183",
      "customData": "",
      "type": 1,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 8,
      "weight": 15.4,
      "cube": 5.8,
      "revenue": 2.7,
      "timeWindow": [
        753,
        1036
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879884,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791101,
        "alias": "Customer 5",
        "firstName": "Customer5",
        "lastName": "Customer5",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer5@example.com",
        "phoneNumber": "+12025550184",
        "location": [
          48.897163,
          2.292865
        ],
        "customData": ""
      },
      "location": [
        48.897163,
        2.292865
      ],
      "alias": "Customer 5",
      "firstName": "Customer5",
      "lastName": "Customer5",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550184",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 9,
      "weight": 16.2,
      "cube": 8.4,
      "revenue": 7.5,
      "timeWindow": [
        736,
        1086
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879883,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791100,
        "alias": "Customer 6",
        "firstName": "Customer6",
        "lastName": "Customer6",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer6@example.com",
        "phoneNumber": "+12025550185",
        "location": [
          48.90092,
          2.400039
        ],
        "customData": ""
      },
      "location": [
        48.90092,
        2.400039
      ],
      "alias": "Customer 6",
      "firstName": "Customer6",
      "lastName": "Customer6",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550185",
      "customData": "",
      "type": 1,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 9,
      "weight": 16.5,
      "cube": 9.7,
      "revenue": 10,
      "timeWindow": [
        786,
        1053
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879882,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791099,
        "alias": "Customer 7",
        "firstName": "Customer7",
        "lastName": "Customer7",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer7@example.com",
        "phoneNumber": "+12025550186",
        "location": [
          48.860914,
          2.310625
        ],
        "customData": ""
      },
      "location": [
        48.860914,
        2.310625
      ],
      "alias": "Customer 7",
      "firstName": "Customer7",
      "lastName": "Customer7",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550186",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 5,
      "weight": 7.5,
      "cube": 2.6,
      "revenue": 13.4,
      "timeWindow": [
        820,
        1020
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879881,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791098,
        "alias": "Customer 8",
        "firstName": "Customer8",
        "lastName": "Customer8",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer8@example.com",
        "phoneNumber": "+12025550187",
        "location": [
          48.827865,
          2.379216
        ],
        "customData": ""
      },
      "location": [
        48.827865,
        2.379216
      ],
      "alias": "Customer 8",
      "firstName": "Customer8",
      "lastName": "Customer8",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550187",
      "customData": "",
      "type": 1,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 11,
      "weight": 12.1,
      "cube": 4.6,
      "revenue": 14.7,
      "timeWindow": [
        753,
        1086
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879880,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791097,
        "alias": "Customer 9",
        "firstName": "Customer9",
        "lastName": "Customer9",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer9@example.com",
        "phoneNumber": "+12025550188",
        "location": [
          48.887096,
          2.283513
        ],
        "customData": ""
      },
      "location": [
        48.887096,
        2.283513
      ],
      "alias": "Customer 9",
      "firstName": "Customer9",
      "lastName": "Customer9",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550188",
      "customData": "",
      "type": 1,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 6,
      "weight": 5.2,
      "cube": 1.5,
      "revenue": 2.9,
      "timeWindow": [
        770,
        1070
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879879,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791096,
        "alias": "Customer 10",
        "firstName": "Customer10",
        "lastName": "Customer10",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer10@example.com",
        "phoneNumber": "+12025550189",
        "location": [
          48.896894,
          2.321586
        ],
        "customData": ""
      },
      "location": [
        48.896894,
        2.321586
      ],
      "alias": "Customer 10",
      "firstName": "Customer10",
      "lastName": "Customer10",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+12025550189",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 13,
      "weight": 6.3,
      "cube": 7.5,
      "revenue": 8.1,
      "timeWindow": [
        836,
        1053
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879878,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791095,
        "alias": "Customer 11",
        "firstName": "Customer11",
        "lastName": "Customer11",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer11@example.com",
        "phoneNumber": "+120255501810",
        "location": [
          48.870449,
          2.342204
        ],
        "customData": ""
      },
      "location": [
        48.870449,
        2.342204
      ],
      "alias": "Customer 11",
      "firstName": "Customer11",
      "lastName": "Customer11",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+120255501810",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 10,
      "weight": 8,
      "cube": 4.1,
      "revenue": 6.2,
      "timeWindow": [
        903,
        1020
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 879877,
      "creationTimestamp": 1752745377776,
      "customerInfo": {
        "id": 1791094,
        "alias": "Customer 12",
        "firstName": "Customer12",
        "lastName": "Customer12",
        "address": {
          "country": "",
          "state": "",
          "county": "",
          "city": "",
          "postalCode": "",
          "streetName": "",
          "streetNumber": ""
        },
        "email": "customer12@example.com",
        "phoneNumber": "+120255501811",
        "location": [
          48.895658,
          2.344043
        ],
        "customData": ""
      },
      "location": [
        48.895658,
        2.344043
      ],
      "alias": "Customer 12",
      "firstName": "Customer12",
      "lastName": "Customer12",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+120255501811",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 6,
      "weight": 4.8,
      "cube": 11.5,
      "revenue": 2.3,
      "timeWindow": [
        870,
        1020
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 899037,
      "customerId": 1811911,
      "location": [
        48.868507,
        2.359727
      ],
      "alias": "Customer 13",
      "firstName": "Customer13",
      "lastName": "Customer13",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+120255501813",
      "customData": "",
      "type": 0,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 3,
      "weight": 3.1,
      "cube": 0.2,
      "revenue": 3.1,
      "timeWindow": [
        420,
        1086
      ],
      "serviceTime": 0,
      "depotId": 0
    },
    {
      "id": 899038,
      "customerId": 1811912,
      "location": [
        48.867329,
        2.348105
      ],
      "alias": "Customer 14",
      "firstName": "Customer14",
      "lastName": "Customer14",
      "address": {
        "country": "",
        "state": "",
        "county": "",
        "city": "",
        "postalCode": "",
        "streetName": "",
        "streetNumber": ""
      },
      "phoneNumber": "+120255501814",
      "customData": "",
      "type": 1,
      "status": 0,
      "state": 1,
      "priority": 0,
      "numberOfPackages": 4,
      "weight": 4.1,
      "cube": 0.3,
      "revenue": 4.2,
      "timeWindow": [
        420,
        1086
      ],
      "serviceTime": 0,
      "depotId": 0
    }
  ],
  "departures": [
    {
      "depotId": 0,
      "alias": "Depot 1",
      "location": [
        48.870569,
        2.356448
      ],
      "address": {
        "country": "France",
        "state": "Ile-de-France",
        "county": "Paris",
        "city": "Paris",
        "postalCode": "75001",
        "streetName": "Rue de Rivoli",
        "streetNumber": "1"
      }
    },
    {
      "depotId": 0,
      "alias": "Depot 2",
      "location": [
        48.82674,
        2.342116
      ],
      "address": {
        "country": "France",
        "state": "Ile-de-France",
        "county": "Paris",
        "city": "Paris",
        "postalCode": "75002",
        "streetName": "Rue de Richelieu",
        "streetNumber": "2"
      }
    }
  ],
  "destinations": [
    {
      "alias": "Destination 1",
      "location": [
        48.898165,
        2.34484
      ],
      "address": {
        "country": "France",
        "state": "Ile-de-France",
        "county": "Paris",
        "city": "Paris",
        "postalCode": "75001",
        "streetName": "Rue de Rivoli",
        "streetNumber": "1"
      }
    },
    {
      "alias": "Destination 2",
      "location": [
        48.872064,
        2.402497
      ],
      "address": {
        "country": "France",
        "state": "Ile-de-France",
        "county": "Paris",
        "city": "Paris",
        "postalCode": "75002",
        "streetName": "Rue de Richelieu",
        "streetNumber": "2"
      }
    }
  ],
  "vehicles": [
    {
      "id": 135932,
      "type": 0,
      "status": 0,
      "name": "Car vehicle 1",
      "manufacturer": "Renault",
      "model": "Master",
      "fuelType": 2,
      "lastPosition": [
        48.870569,
        2.356448
      ],
      "consumption": 6.5,
      "plate": "AA-123-AA",
      "maxLoadWeight": 60,
      "maxLoadCube": 50,
      "height": 0,
      "width": 0,
      "weight": 0,
      "length": 0,
      "axleLoad": 0,
      "fixedCost": 0,
      "costPerHour": 0,
      "startTime": 420,
      "endTime": 1439
    },
    {
      "id": 135933,
      "type": 0,
      "status": 0,
      "name": "Car vehicle 2",
      "manufacturer": "Renault",
      "model": "Master",
      "fuelType": 2,
      "lastPosition": [
        48.82674,
        2.342116
      ],
      "consumption": 6.5,
      "plate": "AA-124-AA",
      "maxLoadWeight": 60,
      "maxLoadCube": 50,
      "height": 0,
      "width": 0,
      "weight": 0,
      "length": 0,
      "axleLoad": 0,
      "fixedCost": 0,
      "costPerHour": 0,
      "startTime": 420,
      "endTime": 1439
    }
  ],
  "vehiclesConstraints": [
    {
      "fuelPrice": 1.09,
      "startDate": 1596758400000,
      "maxNumberOfPackages": 53,
      "minNumberOfOrders": 0,
      "maxNumberOfOrders": 99999999,
      "minDistance": 0,
      "maxDistance": 99999999,
      "maxRevenue": 85
    }
  ],
  "configurationParameters": {
    "name": "Paris - test optimization",
    "ignoreTimeWindow": false,
    "allowDroppingOrders": false,
    "groupingOrders": false,
    "balancedRoutes": 0,
    "optimizationCriterion": 0,
    "arrangeCriterion": 0,
    "optimizationQuality": 2,
    "maxTimeToOptimize": 300,
    "maxWaitTime": 18000,
    "routeType": 2,
    "restrictions": 0,
    "distanceUnit": 0,
    "orderSequenceOptions": []
  },
  "creationTimestamp": 1752745377776,
  "matrixBuildType": 1,
  "request": {
    "id": 26551,
    "optimizationId": 137831,
    "status": 1,
    "message": "Operation done successfully!",
    "creationTimestamp": 1752745377776
  }
}

```

## Conclusion[​](#conclusion "Direct link to Conclusion")

This example demonstrates how to add a list of orders to an existing optimization. The added orders can be assigned to the routes if reoptimization is enabled. By following these steps, you can integrate order additions into your fleet management workflow.
