# Update an order

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

Updates an order. If the status of an order is changed while updating the order, the status\_update\_at attribute is set with the current time.

## Sample Request

### Default

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/orders/1 \
     -u {site_api_key}:\
     -d status="DELIVERED" \
     -d shipped_at=1517073906 \
     -d delivered_at=1517678706
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Order.Update("1")
		.Status(Order.StatusEnum.Delivered)
		.ShippedAt(1517073906)
		.DeliveredAt(1517678706)
		.Request();

Order order = result.Order;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    orderAction "github.com/chargebee/chargebee-go/v3/actions/order"
    "github.com/chargebee/chargebee-go/v3/models/order"
    orderEnum "github.com/chargebee/chargebee-go/v3/models/order/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := orderAction.Update("1", &order.UpdateRequestParams{
        Status : orderEnum.StatusDelivered,
        ShippedAt : chargebee.Int64(1517073906),
        DeliveredAt : chargebee.Int64(1517678706),
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Order := res.Order
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.OrderUpdateRequest{
    Status : chargebee.OrderStatusDelivered,
    ShippedAt : chargebee.Int64(1517073906),
    DeliveredAt : chargebee.Int64(1517678706),
}
  res, err := client.Order.Update("1", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Order := res.Order
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;
import java.sql.Timestamp;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Order.update("1")
            .status(Order.Status.DELIVERED)
            .shippedAt(new Timestamp(1517073906L * 1000))
            .deliveredAt(new Timestamp(1517678706L * 1000))
            .request();

        Order order = result.order();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.order.Order;
import com.chargebee.v4.models.order.params.OrderUpdateParams;
import com.chargebee.v4.models.order.responses.OrderUpdateResponse;
import java.sql.Timestamp;

public class OrderUpdate {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        OrderUpdateParams params = OrderUpdateParams.builder()
            .status(OrderUpdateParams.Status.DELIVERED)
            .shippedAt(new Timestamp(1517073906L * 1000))
            .deliveredAt(new Timestamp(1517678706L * 1000))
            .build();

        OrderUpdateResponse response = client
            .orders()
            .update("1", params);

        Order order = response.getOrder();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.order.update("1", {
        status: "delivered",
        shipped_at: 1517073906,
        delivered_at: 1517678706
    });

    console.log(result);
    const order = result.order;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->order()->update("1", [
    "status" => "delivered",
    "shipped_at" => 1517073906,
    "delivered_at" => 1517678706
]);
$order = $result->order;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Order.update("1",
    cb_client.Order.UpdateParams(
        status=chargebee.Order.Status.DELIVERED,
        shipped_at=1517073906,
        delivered_at=1517678706
    )
)
order = response.order
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Order.update("1",{
  :status => "DELIVERED",
  :shipped_at => 1517073906,
  :delivered_at => 1517678706
})

order = result.order
```

### updates the order shipping address.

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/orders/__test__KyVnHhSBWlrq92oh \
     -u {site_api_key}:\
     -d "shipping_address[first_name]"="John" \
     -d "shipping_address[last_name]"="Doe" \
     -d "shipping_address[email]"="john@user.com" \
     -d "shipping_address[line1]"="PO Box 9999" \
     -d "shipping_address[city]"="Walnut" \
     -d "shipping_address[state]"="California" \
     -d "shipping_address[zip]"="91789" \
     -d "shipping_address[country]"="US"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Order.Update("__test__KyVnHhSBWlrq92oh")
		.ShippingAddressFirstName("John")
		.ShippingAddressLastName("Doe")
		.ShippingAddressEmail("john@user.com")
		.ShippingAddressLine1("PO Box 9999")
		.ShippingAddressCity("Walnut")
		.ShippingAddressState("California")
		.ShippingAddressZip("91789")
		.ShippingAddressCountry("US")
		.Request();

Order order = result.Order;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    orderAction "github.com/chargebee/chargebee-go/v3/actions/order"
    "github.com/chargebee/chargebee-go/v3/models/order"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := orderAction.Update("__test__KyVnHhSBWlrq92oh", &order.UpdateRequestParams{
        ShippingAddress : &order.UpdateShippingAddressParams{
            FirstName : "John",
            LastName : "Doe",
            Email : "john@user.com",
            Line1 : "PO Box 9999",
            City : "Walnut",
            State : "California",
            Zip : "91789",
            Country : "US",
        },
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Order := res.Order
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.OrderUpdateRequest{
    ShippingAddress : &chargebee.OrderUpdateShippingAddress{
        FirstName : "John",
        LastName : "Doe",
        Email : "john@user.com",
        Line1 : "PO Box 9999",
        City : "Walnut",
        State : "California",
        Zip : "91789",
        Country : "US",
    },
}
  res, err := client.Order.Update("__test__KyVnHhSBWlrq92oh", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Order := res.Order
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Order.update("__test__KyVnHhSBWlrq92oh")
            .shippingAddressFirstName("John")
            .shippingAddressLastName("Doe")
            .shippingAddressEmail("john@user.com")
            .shippingAddressLine1("PO Box 9999")
            .shippingAddressCity("Walnut")
            .shippingAddressState("California")
            .shippingAddressZip("91789")
            .shippingAddressCountry("US")
            .request();

        Order order = result.order();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.order.Order;
import com.chargebee.v4.models.order.params.OrderUpdateParams;
import com.chargebee.v4.models.order.responses.OrderUpdateResponse;

public class OrderUpdate {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        OrderUpdateParams.ShippingAddressParams shippingAddressParams =
            OrderUpdateParams.ShippingAddressParams.builder()
                .firstName("John")
                .lastName("Doe")
                .email("john@user.com")
                .line1("PO Box 9999")
                .city("Walnut")
                .state("California")
                .zip("91789")
                .country("US")
                .build();

        OrderUpdateParams params = OrderUpdateParams.builder()
            .shippingAddress(shippingAddressParams)
            .build();

        OrderUpdateResponse response = client
            .orders()
            .update("__test__KyVnHhSBWlrq92oh", params);

        Order order = response.getOrder();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.order.update("__test__KyVnHhSBWlrq92oh", {
        shipping_address: {
            first_name: "John",
            last_name: "Doe",
            email: "john@user.com",
            line1: "PO Box 9999",
            city: "Walnut",
            state: "California",
            zip: 91789,
            country: "US"
        }
    });

    console.log(result);
    const order = result.order;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->order()->update("__test__KyVnHhSBWlrq92oh", [
    "shipping_address" => [
        "first_name" => "John",
        "last_name" => "Doe",
        "email" => "john@user.com",
        "line1" => "PO Box 9999",
        "city" => "Walnut",
        "state" => "California",
        "zip" => "91789",
        "country" => "US"
    ]
]);
$order = $result->order;
```

#### Python

```python
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Order.update("__test__KyVnHhSBWlrq92oh",
    cb_client.Order.UpdateParams(
        shipping_address=cb_client.Order.UpdateShippingAddressParams(
            first_name="John",
            last_name="Doe",
            email="john@user.com",
            line1="PO Box 9999",
            city="Walnut",
            state="California",
            zip="91789",
            country="US"
        )
    )
)
order = response.order
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Order.update("__test__KyVnHhSBWlrq92oh",{
  :shipping_address => {
    :first_name => "John",
    :last_name => "Doe",
    :email => "john@user.com",
    :line1 => "PO Box 9999",
    :city => "Walnut",
    :state => "California",
    :zip => "91789",
    :country => "US"
  }
})

order = result.order
```

## Sample Response

```json
{
  "order": {
    "amount_adjusted": 0,
    "amount_paid": 40000,
    "base_currency_code": "USD",
    "created_at": 1517505909,
    "created_by": "Auto generated by system",
    "currency_code": "USD",
    "customer_id": "__test__KyVnHhSBWlr4r2o7",
    "deleted": false,
    "delivered_at": 1517678706,
    "discount": 0,
    "document_number": "1",
    "exchange_rate": 1,
    "id": "1",
    "invoice_id": "__demo_inv__1",
    "is_gifted": false,
    "linked_credit_notes": {},
    "object": "order",
    "order_date": 1517505907,
    "order_line_items": [
      {
        "amount": 40000,
        "amount_adjusted": 0,
        "amount_paid": 40000,
        "description": "MB1S1P",
        "discount_amount": 0,
        "entity_id": "MB1S1P",
        "entity_type": "plan",
        "fulfillment_amount": 40000,
        "fulfillment_quantity": 1,
        "id": "o_li__test__KyVnGlSBWlrF727W",
        "invoice_id": "__demo_inv__1",
        "invoice_line_item_id": "li___test__KyVnHhSBWlr692o9",
        "is_shippable": true,
        "item_level_discount_amount": 0,
        "object": "order_line_item",
        "refundable_credits": 40000,
        "refundable_credits_issued": 0,
        "status": "queued",
        "tax_amount": 0,
        "unit_price": 40000
      },
      {..}
    ],
    "order_type": "system_generated",
    "paid_on": 1517505907,
    "payment_status": "paid",
    "price_type": "tax_exclusive",
    "refundable_credits": 40000,
    "refundable_credits_issued": 0,
    "resource_version": 1517678706000,
    "rounding_adjustement": 0,
    "shipped_at": 1517073906,
    "shipping_date": 1517505907,
    "status": "delivered",
    "status_update_at": 1517678706,
    "sub_total": 40000,
    "subscription_id": "__test__KyVnHhSBWlr4r2o7",
    "tax": 0,
    "total": 40000,
    "updated_at": 1517678706
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/orders/{order-id}

## Input Parameters

- `reference_id` (optional, string, max chars=50)
  Reference id is the unique identifier of the order in the shipping/order management application.

- `batch_id` (optional, string, max chars=50)
  Unique id to identify a group of orders.

- `note` (optional, string, max chars=600)
  The custom note for the order.

- `shipping_date` (optional, timestamp(UTC) in seconds)
  The date on which the order should be shipped to the customer.

- `order_date` (optional, timestamp(UTC) in seconds)
  The order date.

- `cancelled_at` (optional, timestamp(UTC) in seconds)
  The time at which the order was cancelled.

- `cancellation_reason` (optional, enumerated string)
  Cancellation reason.
  Possible enum values:
    - `shipping_cut_off_passed`
      The invoice has been paid late and Chargebee cancel's the first order for the invoice.
    - `product_unsatisfactory`
      Product unsatisfactory.
    - `third_party_cancellation`
      Third party cancellation.
    - `product_not_required`
      Product not required.
    - `delivery_date_missed`
      Delivery date missed.
    - `alternative_found`
      Alternative found.
    - `invoice_written_off`
      The invoice has been completely written off. Orders are generated by Chargebee in cancelled state.
    - `invoice_voided`
      The invoice for which the order was createed has been voided.
    - `fraudulent_transaction`
      Fraudulent transaction.
    - `payment_declined`
      Payment declined.
    - `subscription_cancelled`
      The subsctiption for which the order was created has been cancelled.
    - `product_not_available`
      Product not available.
    - `others`
      Other reason
    - `order_resent`
      Order resent

- `shipped_at` (optional, timestamp(UTC) in seconds)
  The time at which the order was shipped.

- `delivered_at` (optional, timestamp(UTC) in seconds)
  The time at which the order was delivered.

- `tracking_url` (optional, string, max chars=255)
  The tracking url of the order.

- `tracking_id` (optional, string, max chars=50)
  The tracking id of the order.

- `shipment_carrier` (optional, string, max chars=50)
  The carrier used to ship the goods to the customer. Ex:- FedEx.

- `fulfillment_status` (optional, string, max chars=50)
  The fulfillment status of an order as reflected in the shipping/order management application. Typical statuses include Shipped,Awaiting Shipment,Not fulfilled etc;.

- `status` (optional, enumerated string, default=new)
  The order status.
  Possible enum values:
    - `new`
      Order has been created. Applicable only if you are using Chargebee's legacy order management system.
    - `processing`
      Order is being processed. Applicable only if you are using Chargebee's legacy order management system
    - `complete`
      Order has been processed successfully. Applicable only if you are using Chargebee's legacy order management system
    - `cancelled`
      Order has been cancelled. Applicable only if you are using Chargebee's legacy order management system
    - `voided`
      Order has been voided. Applicable only if you are using Chargebee's legacy order management system
    - `queued`
      Order is yet to be processed by any system, these are scheduled orders created by Chargebee
    - `awaiting_shipment`
      The order has been picked up by an integration system, and synced to a shipping management platform
    - `on_hold`
      The order is paused from being processed.
    - `delivered`
      The order has been delivered to the customer.
    - `shipped`
      The order has moved from order management system to a shipping system.
    - `partially_delivered`
      The order has been partially delivered to the customer.
    - `returned`
      The order has been returned after delivery.

- `shipping_address` (optional, string)
  Parameters for shipping\_address
  - `first_name` (optional, string, max chars=150)
    The first name of the contact.
  - `last_name` (optional, string, max chars=150)
    The last name of the contact.
  - `email` (optional, string, max chars=70)
    The email address.
  - `company` (optional, string, max chars=250)
    The company name.
  - `phone` (optional, string, max chars=50)
    The phone number.
  - `line1` (optional, string, max chars=150)
    Address line 1
  - `line2` (optional, string, max chars=150)
    Address line 2
  - `line3` (optional, string, max chars=150)
    Address line 3
  - `city` (optional, string, max chars=50)
    The name of the city.
  - `state_code` (optional, string, max chars=50)
    The [ISO 3166-2 state/province code](https://www.iso.org/obp/ui/#search/code) without the country prefix. Currently supported for USA, Canada, India and UAE. For instance, for Arizona (USA), set `state_code` as `AZ` (not `US-AZ` ). For Tamil Nadu (India), set as `TN` (not `IN-TN` ). For British Columbia (Canada), set as `BC` (not `CA-BC` ). For Dubai (UAE), set as `DU` (not `AE-DU` ).
  - `state` (optional, string, max chars=50)
    The state/province name. Is set by Chargebee automatically for US, Canada, India and UAE, if `state_code` is provided.
  - `zip` (optional, string, max chars=20)
    Zip or postal code. The number of characters is validated according to the rules [specified here](https://chromium-i18n.appspot.com/ssl-address) .
  - `country` (optional, string, max chars=50)
    The billing address country of the customer. Must be one of [ISO 3166 alpha-2 country code](https://www.iso.org/iso-3166-country-codes.html) .
    
    **Note**: If you enter an invalid country code, the system will return an error.
    
    **Brexit**
    
    If you have enabled [EU VAT](https://www.chargebee.com/docs/eu-vat.html) in 2021 or later, or have [manually enable](https://www.chargebee.com/docs/brexit.html#what-needs-to-be-done-in-chargebee) the Brexit configuration, then `XI` (the code for **United Kingdom - Northern Ireland**) is available as an option.
  - `validation_status` (optional, enumerated string, default=not_validated)
    The address verification status.
    Possible enum values:
      - `not_validated`
        Address is not yet validated.
      - `valid`
        Address was validated successfully.
      - `partially_valid`
        The address is valid for taxability but has not been validated for shipping.
      - `invalid`
        Address is invalid.

- `order_line_items` (optional, array)
  Parameters for order\_line\_items
  - `id` (optional, string, max chars=40)
    The identifier for the order line item.
  - `status` (optional, enumerated string)
    The order line item's delivery status
    Possible enum values:
      - `queued`
        Not processed for shipping yet.
      - `awaiting_shipment`
        Moved to shipping platform.
      - `on_hold`
        The delivery has been moved to "On hold" status.
      - `delivered`
        The order line item has been delivered.
      - `shipped`
        The order line item has been shipped.
      - `partially_delivered`
        The order has been partially delivered to the customer.
      - `returned`
        The order has been returned after delivery.
      - `cancelled`
        The order has been returned after delivery.
  - `sku` (optional, string, max chars=250)
    The SKU code for the order line item product

## Returns

- `order` (Order object)
  Resource object representing order
