> For the complete documentation index, see [llms.txt](https://docs.layerstack.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.layerstack.com/api-docs/layerstack-api/order.md).

# Order

## Order

`Order` is the entity that handles purchasing of our service plans.

### Endpoints Summary

<table><thead><tr><th width="285">ENDPOINT (CLICK TO READ FULL SPECIFICATION)</th><th width="110.33333333333331">METHOD</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><a href="https://developers.layerstack.com/Order.md#order"><code>/order/</code></a></td><td><code>POST</code></td><td>places an order.</td></tr><tr><td><a href="https://developers.layerstack.com/Order.md#add-to-cart"><code>/order/add-to-cart</code></a></td><td><code>POST</code></td><td>add a cart item. returns the cart item id. Carts items can be added to orders to place</td></tr><tr><td><a href="https://developers.layerstack.com/Order.md#delete-cart"><code>/order/cartItems/delete/{cart_item_id}</code></a></td><td><code>DELETE</code></td><td>deletes the specified cart item</td></tr><tr><td><a href="https://developers.layerstack.com/Order.md#change-order"><code>/order/changeorder/</code></a></td><td><code>POST</code></td><td>Places a Change order, which is for adding add ons to existing subscriptions.</td></tr><tr><td><a href="https://developers.layerstack.com/Order.md#change-order-total"><code>/order/changeorder/total</code></a></td><td><code>GET</code></td><td>Calcuates the change order total before placing the change order. Also check if the change order can be placed. This api call does not actually place a change order.</td></tr></tbody></table>

### Create Order <a href="#order" id="order"></a>

Request: `POST /order`

<table><thead><tr><th width="173.33333333333331">NAME</th><th width="125">TYPE</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><code>account</code></td><td><code>string</code></td><td>(requiried) account id referred to in format of XX-11111111</td></tr><tr><td><code>currency</code></td><td><code>string</code></td><td>currency of order. only required if account has no currency set . The currency is set when there is a first order placed in your account and cannot be changed. If the account currency is already set, this field is ignored.</td></tr><tr><td><code>label</code></td><td><code>string</code></td><td>label of cloud server</td></tr><tr><td><code>cartItems</code></td><td><code>array</code></td><td>array of cart items id, obtained from POST <a href="https://developers.layerstack.com/Order.md#add-to-cart">/order/add-to-cart</a> api</td></tr><tr><td><code>payment_type</code></td><td><code>string</code></td><td>currently, only credit cart payment is accepted, therefore the value of this parameter is <code>ccard</code>.</td></tr></tbody></table>

### Create Cart Item <a href="#add-to-cart" id="add-to-cart"></a>

Request: `POST /order/add-to-cart`

<table><thead><tr><th width="201.33333333333331">NAME</th><th width="104">TYPE</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><code>billing_cycle</code></td><td><code>int</code></td><td>(requiried) 1: monthly, 3: quarterly, 12: annually</td></tr><tr><td><code>plan_id</code></td><td><code>int</code></td><td>plan id. Refer to <a href="https://developers.layerstack.com/Plans.md">here</a> for available IDs.</td></tr><tr><td><code>plan_type</code></td><td><code>string</code></td><td>currrently only <code>cloud_servers_standard</code>(General Purpose Cloud Server), <code>cloud_servers_highmemory</code> (Memory Optimized Cloud Server), <code>cloud_servers_dedicatedcpu</code> (Dedicated CPU Cloud Server), and <code>cloud_servers_highstorage_sas</code> (High Storage Cloud Server) are supported</td></tr><tr><td><code>quantity</code></td><td><code>int</code></td><td>the quantity of this item to add to cart</td></tr><tr><td><code>addons</code></td><td><code>array</code></td><td>optional "addons":[0: {id: 6, additional_value: 1}] . Refer to <a href="https://developers.layerstack.com/Plans.md">here</a> for available IDs.</td></tr><tr><td><code>password</code></td><td><code>string</code></td><td>password of Cloud Server if the <code>plan_type</code> is <code>cloud_servers_standard</code>, <code>cloud_servers_highmemory</code>, <code>cloud_servers_highstorage</code>, <code>cloud_servers_highfrequency</code>, <code>cloud_servers_dedicatedcpu</code> or <code>cloud_servers_highstorage_sas</code>. This field is not required if the <code>plan_type</code> are other types.</td></tr><tr><td><code>os_template_id</code></td><td><code>int</code></td><td>os template id for cloud servers. this field is not required for other plan types. Refer to <a href="https://developers.layerstack.com/OSTemplate.md">this link</a> for os template ids.</td></tr><tr><td><code>custom_ssh_key</code></td><td><code>string</code></td><td>base64 encoded string of ssh key. Only default linux templates supports custom_ssh_key. Windows and custom templates do not support ssh keys.</td></tr><tr><td><code>custom_script</code></td><td><code>string</code></td><td>base64 encoded string of custom script to run at provisioning time. Only default linux templates supports custom scripts. Windows and custom templates do not support custom scripts.</td></tr></tbody></table>

Sample Response:

```
{
    "0": 995,   // cart_item_id
    "data": {
        "message": "Cart Items added successfully",
        "code": 200
    }
}
```

### Delete Cart Item <a href="#delete-cart" id="delete-cart"></a>

Request: `DELETE /order/cartItems/delete/{cart_item_id}` where `cart_item_id` is the cart item id (obtained from POST [/order/add-to-cart](https://developers.layerstack.com/Order.md#add-to-cart) api) to be deleted.

### Change Order <a href="#change-order" id="change-order"></a>

Request: `POST /order/changeorder`

<table><thead><tr><th width="208.33333333333331">NAME</th><th width="94">TYPE</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><code>subscription_id</code></td><td><code>int</code></td><td>subscription id</td></tr><tr><td><code>resources</code></td><td><code>array</code></td><td>Key-value array {resource_name: resource->name, delta_value: value} format. Available resources are <code>vm_backup</code>, <code>china_route</code>, <code>vm_antiddos</code>.</td></tr></tbody></table>

Sample Payload:

```
{
"subscription_id": 4158,
"resources" : [{"resource_name": "vm_backup", "delta_value":"1"}]

}
```

### Change Order Total <a href="#change-order-total" id="change-order-total"></a>

Request: `PUT /order/changeorder/total`

<table><thead><tr><th width="205.33333333333331">NAME</th><th width="89">TYPE</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><code>subscription_id</code></td><td><code>int</code></td><td>subscription id</td></tr><tr><td><code>resources</code></td><td><code>array</code></td><td>Key-value array {resource_name: resource->name, delta_value: value} format. Available resources are <code>vm_backup</code>, <code>china_route</code>, <code>vm_antiddos</code>.</td></tr></tbody></table>

The payload is the same as Change Order API above.

Sample Response:

```
{
    "available": true,
    "total": 19.06,
    "currency": "hkd",
    "date_from": "2020-04-23",
    "date_to": "2020-05-22",
    "inapplicable_resources": []
}
```

### Switch Order <a href="#switch-order" id="switch-order"></a>

Request: `PUT /order/switch/{subscription_id}`

<table><thead><tr><th width="163.33333333333331">NAME</th><th width="95">TYPE</th><th>DESCRIPTION</th></tr></thead><tbody><tr><td><code>plan_id</code></td><td><code>int</code></td><td>target plan's id. this plan need to have the same type as current plan</td></tr></tbody></table>

Sample Response:

```
{
    "available":true,
    "total":118.68,
    "currency":"hkd",
    "date_from":"2021-03-09",
    "date_to":"2021-03-28"
}
```

### Switch Order Total <a href="#switch-order-total" id="switch-order-total"></a>

Request: `PUT /order/switch/total`

| NAME              | TYPE  | DESCRIPTION                                                            |
| ----------------- | ----- | ---------------------------------------------------------------------- |
| `subscription_id` | `int` | subscription id                                                        |
| `plan_id`         | `int` | target plan's id. this plan need to have the same type as current plan |

Sample Response:

```
{
    "available":true,
    "total":118.68,
    "currency":"hkd",
    "date_from":"2021-03-09",
    "date_to":"2021-03-28"
}
```
