# Import an order

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


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

Import an order for an invoice with one or more line items. The import order bulk operation is to be applied on an imported invoice.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/orders/import_order \
     -u {site_api_key}:\
     -d invoice_id="ship_inv" \
     -d subscription_id="__test__sZEDgk5GSLmev7p7J" \
     -d order_date=1519879210 \
     -d status="QUEUED" \
     -d created_at=1517460010 \
     -d shipping_date=1522557610
```

#### .NET

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

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Order.ImportOrder()
		.InvoiceId("ship_inv")
		.SubscriptionId("__test__sZEDgk5GSLmev7p7J")
		.OrderDate(1519879210)
		.Status(Order.StatusEnum.Queued)
		.CreatedAt(1517460010)
		.ShippingDate(1522557610)
		.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.ImportOrder(&order.ImportOrderRequestParams{
        InvoiceId : "ship_inv",
        SubscriptionId : "__test__sZEDgk5GSLmev7p7J",
        OrderDate : chargebee.Int64(1519879210),
        Status : orderEnum.StatusQueued,
        CreatedAt : chargebee.Int64(1517460010),
        ShippingDate : chargebee.Int64(1522557610),
    }).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.OrderImportOrderRequest{
    InvoiceId : "ship_inv",
    SubscriptionId : "__test__sZEDgk5GSLmev7p7J",
    OrderDate : chargebee.Int64(1519879210),
    Status : chargebee.OrderStatusQueued,
    CreatedAt : chargebee.Int64(1517460010),
    ShippingDate : chargebee.Int64(1522557610),
}
  res, err := client.Order.ImportOrder(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.importOrder()
            .invoiceId("ship_inv")
            .subscriptionId("__test__sZEDgk5GSLmev7p7J")
            .orderDate(new Timestamp(1519879210L * 1000))
            .status(Order.Status.QUEUED)
            .createdAt(new Timestamp(1517460010L * 1000))
            .shippingDate(new Timestamp(1522557610L * 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.ImportOrderParams;
import com.chargebee.v4.models.order.responses.ImportOrderResponse;
import java.sql.Timestamp;

public class ImportOrder {

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

        ImportOrderParams params = ImportOrderParams.builder()
            .invoiceId("ship_inv")
            .subscriptionId("__test__sZEDgk5GSLmev7p7J")
            .orderDate(new Timestamp(1519879210L * 1000))
            .status(ImportOrderParams.Status.QUEUED)
            .createdAt(new Timestamp(1517460010L * 1000))
            .shippingDate(new Timestamp(1522557610L * 1000))
            .build();

        ImportOrderResponse response = client.orders().importOrder(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.importOrder({
        invoice_id: "ship_inv",
        subscription_id: "__test__sZEDgk5GSLmev7p7J",
        order_date: 1519879210,
        status: "queued",
        created_at: 1517460010,
        shipping_date: 1522557610
    });

    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()->importOrder([
    "invoice_id" => "ship_inv",
    "subscription_id" => "__test__sZEDgk5GSLmev7p7J",
    "order_date" => 1519879210,
    "status" => "queued",
    "created_at" => 1517460010,
    "shipping_date" => 1522557610
]);
$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.import_order(
    cb_client.Order.ImportOrderParams(
        invoice_id="ship_inv",
        subscription_id="__test__sZEDgk5GSLmev7p7J",
        order_date=1519879210,
        status=chargebee.Order.Status.QUEUED,
        created_at=1517460010,
        shipping_date=1522557610
    )
)
order = response.order
```

#### Ruby

```ruby
require 'chargebee'

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

result = ChargeBee::Order.import_order({
  :invoice_id => "ship_inv",
  :subscription_id => "__test__sZEDgk5GSLmev7p7J",
  :order_date => 1519879210,
  :status => "QUEUED",
  :created_at => 1517460010,
  :shipping_date => 1522557610
})

order = result.order
```

## Sample Response

```json
{
  "order": {
    "amount_adjusted": 0,
    "amount_paid": 0,
    "base_currency_code": "USD",
    "created_at": 1517460010,
    "created_by": "Auto generated by system",
    "currency_code": "USD",
    "customer_id": "__test__sZEDgk5GSLmev7p7J",
    "deleted": false,
    "discount": 0,
    "exchange_rate": 1,
    "id": "2",
    "invoice_id": "ship_inv",
    "is_gifted": false,
    "linked_credit_notes": {},
    "object": "order",
    "order_date": 1519879210,
    "order_line_items": [
      {
        "amount": 2000,
        "amount_adjusted": 0,
        "amount_paid": 0,
        "description": "shippable plan",
        "discount_amount": 0,
        "entity_id": "shippable",
        "entity_type": "plan",
        "fulfillment_amount": 2000,
        "fulfillment_quantity": 1,
        "id": "o_li__test__sZEDgk5GSLmevt27U",
        "invoice_id": "ship_inv",
        "invoice_line_item_id": "li___test__sZEDgk5GSLmevGj7R",
        "is_shippable": true,
        "item_level_discount_amount": 0,
        "object": "order_line_item",
        "refundable_credits": 0,
        "refundable_credits_issued": 0,
        "status": "queued",
        "tax_amount": 0,
        "unit_price": 2000
      },
      {..}
    ],
    "order_type": "system_generated",
    "payment_status": "not_paid",
    "price_type": "tax_exclusive",
    "refundable_credits": 0,
    "refundable_credits_issued": 0,
    "resource_version": 1517657205622,
    "rounding_adjustement": 0,
    "shipping_date": 1522557610,
    "status": "queued",
    "sub_total": 2000,
    "subscription_id": "__test__sZEDgk5GSLmev7p7J",
    "tax": 0,
    "total": 2000,
    "updated_at": 1517657205
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/orders/import_order

## Input Parameters

- `id` (optional, string, max chars=40)
  Uniquely identifies the order. It is the api identifier for the order.
  
  \*Order id will always be assigned incrementally from the last generated Order ID.
  
  If Orders imported has an Order ID which is a string, Chargebee will just validate if the Order ID is unique
  
  Recommendation: For orders being imported, set the same prefix and the serial number that is used for the Document number, which will make this into a string. This will ensure that imported orders don't conflict with orders created by Chargebee. Chargebee will ensure there aren't orders with duplicate Order IDs.\* .

- `document_number` (optional, string, max chars=50)
  The order's serial number.
  
  _Document number passed cannot be greater than the series mentioned in the configuration. For instance, if you have set Document number series in Order Configurations with a Prefix as 'ORDER' and Starting number as '1000', orders up to the sequence number 'ORDER999' can be imported into Chargebee_
  
  _Recommendation: Set a different prefix at the Order Configuration, than the ones that are imported. If your Order Configuration has a Prefix of 'NEW', with Starting number as '1', i.e. 'NEW1', then, set Prefix for imported orders to be as 'OLD', with Starting number as '1', i.e, 'OLD1'_ .

- `invoice_id` (required, string, max chars=50)
  The invoice number which acts as an identifier for invoice and is generated sequentially.

- `status` (required, enumerated string)
  The status of this order.
  Possible enum values:
    - `cancelled`
      Order has been cancelled. 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.

- `subscription_id` (optional, string, max chars=50)
  The subscription for which the order is created.

- `customer_id` (optional, string, max chars=50)
  The customer for which the order is created.

- `created_at` (required, timestamp(UTC) in seconds)
  The time at which the order was created.

- `order_date` (required, timestamp(UTC) in seconds)
  The date on which the order will start getting processed.

- `shipping_date` (required, timestamp(UTC) in seconds)
  This is the date on which the order has to be shipped to the customer.

- `reference_id` (optional, string, max chars=50)
  Reference id can be used to map the orders in the shipping/order management application to the orders in ChargeBee. The reference\_id generally is the same as the order id in the third party application.
  
  _Recommendation:  
  If this order is in any of these statuses, awaiting\_shipment, on\_hold, delivered, shipped, partially\_delivered, returned, and has already been processed, through a 3rd party system, and you have a reference id of the entity in the 3rd party tool, pass in the entity id to this field. If not, set the same prefix and the serial number that is used for the Document number, which will make this into a string._
  
  _If this order hasn't been processed and is in 'queued' status, do not pass any value to this field. Chargebee, when it syncs your Orders through the fulfilment integrations such as Shipstation or Shopify, would auto assign the reference id from the connected system._ .

- `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;.
  
  \*If this order is in any of these statuses, awaiting\_shipment, on\_hold, delivered, shipped, partially\_delivered, returned, and has already been processed, through a 3rd party system, and you have a corresponding status from the 3rd party tool, pass in the status to this field.
  
  If this order hasn't been processed and is in 'queued' status, do not pass any value to this field. Chargebee, when it syncs your Orders through the fulfilment integrations such as Shipstation or Shopify, would auto assign the fulfilment status from the connected system.\* .

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

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

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

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

- `shipment_carrier` (optional, string, max chars=50)
  Shipment carrier.

- `shipping_cut_off_date` (optional, timestamp(UTC) in seconds)
  The time after which an order becomes unservicable.

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

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

- `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

- `refundable_credits_issued` (optional, in cents, min=0)
  If there are any credits that were issued at the order level, you can make use of the field, refundable\_credits\_issued. This will lead to Chargebee creating a Refundable Credit note against the order. When the next invoice is raised against the customer, this credit note will be utilised.

- `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.

- `billing_address` (optional, string)
  Parameters for billing\_address
  - `first_name` (optional, string, max chars=150)
    The first name of the billing contact.
  - `last_name` (optional, string, max chars=150)
    The last name of the billing 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.

## Returns

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