# 訂單品項

{% hint style="success" %}
&#x20;此 API 為 2024-10-04 後版本 v.2.62.11 開放。
{% endhint %}

## 最佳實踐

在整合過程中，訂單品項（contact-order-item）需指定產品（Product）及其所屬訂單（order）。整合步驟如下：

1. 根據訂單編號（order\_number）找到對應的訂單ID（contact\_order\_id）。
2. 根據產品編號（sku）或其他資訊取得產品ID（product\_id）。
3. 使用訂單編號（order\_number）和產品ID（product\_id）來建立或更新訂單品項。

這些步驟確保每個訂單品項正確關聯到相應的產品和訂單，提升資料整合的準確性與效率。

## 搜尋

```javascript
GET https://{API_DOMAIN}/api/v1/contact-order/{contact_order}/contact-order-item
```

```javascript
curl -X GET
    -H "Content-Type: application/json"
    '{"name": "vip"}'
    https://{API_HOST}/api/v1/{contact_order}/contact-order-item
```

### Response

| PROPERTY | TYPE             | DESCRIPTION |
| -------- | ---------------- | ----------- |
| **data** | Array of objects | 銷售單品項資料陣列   |
| **meta** | Object           | 頁籤資料        |

```json
{
    "data": [
        {
            "id": 2,
            "quantity": 1,
            "total_price_before_discounts": "3100.00",
            "total_discount": "0.00",
            "total_price_after_discounts": "3100.00",
            "product_id": 3,
            "contact_order_id": 1,
            "product":
            {
                "id": 3,
                "name": "女款 Dunk 低筒鞋 Medium Olive",
                "sku": "DD1503-120",
                "price": 3100,
            },
            "created_at": "2024-09-27 15:44:03",
            "updated_at": "2024-09-27 15:44:03"
        }
    ],
    "links": { ... },
    "meta": { ... }
}
```

## 取得單筆資料

```javascript
GET https://{API_DOMAIN}/api/v1/contact-order/{contact_order}/contact-order-item/{contact_order_item}
```

```javascript
curl -X GET
    -H "Content-Type: application/json"
    https://{API_HOST}/api/v1/contact-order/1/contact-order-item/36
```

### URL Parameters

| PARAMETER | REQUIRED | DEFAULT | TYPE   | DESCRIPTION |
| --------- | -------- | ------- | ------ | ----------- |
| **id**    | true     | NULL    | Number | 客戶標籤系統 ID   |

### Response

| PROPERTY | TYPE   | DESCRIPTION |
| -------- | ------ | ----------- |
| **data** | Object | 銷售單品項資料     |

```json
{
    "data": {
        "id": 2,
        "quantity": 1,
        "total_price_before_discounts": "3100.00",
        "total_discount": "0.00",
        "total_price_after_discounts": "3100.00",
        "product_id": 3,
        "contact_order_id": 1,
        "product":
        {
            "id": 3,
            "name": "女款 Dunk 低筒鞋 Medium Olive",
            "sku": "DD1503-120",
            "price": 3100,
        },
        "created_at": "2024-09-27 15:44:03",
        "updated_at": "2024-09-27 15:44:03"
    }
}
```

## 新增

```javascript
POST https://{API_DOMAIN}/api/v1/contact-order/{contact_order}/contact-order-item
```

```javascript
curl -X POST
    -H "Content-Type: application/json"
    '{"product_id": 3, "quantity": 2 }'
    https://{API_HOST}/api/v1/contact-order/1/contact-order-item
```

### Form Data

| PARAMETER                       | REQUIRED | DEFAULT | TYPE          | DESCRIPTION  |
| ------------------------------- | -------- | ------- | ------------- | ------------ |
| product\_id                     | true     | NULL    | Integer       | 關聯的產品唯一識別碼   |
| quantity                        | true     | NULL    | Integer       | 購買的產品數量      |
| total\_price\_before\_discounts | false    | NULL    | Decimal(10,2) | 未應用折扣的項目總價   |
| total\_discount                 | false    | NULL    | Decimal(10,2) | 應用到項目的總折扣額   |
| total\_price\_after\_discounts  | false    | NULL    | Decimal(10,2) | 應用折扣後的項目最終價格 |

### Response

```json
{
    "data": {
        "id": 2,
        "quantity": 1,
        "total_price_before_discounts": "3100.00",
        "total_discount": "0.00",
        "total_price_after_discounts": "3100.00",
        "product_id": 3,
        "contact_order_id": 1,
        "product":
        {
            "id": 3,
            "name": "女款 Dunk 低筒鞋 Medium Olive",
            "sku": "DD1503-120",
            "price": 3100,
        },
        "created_at": "2024-09-27 15:44:03",
        "updated_at": "2024-09-27 15:44:03"
    }
}
```

## 更新

```javascript
PUT https://{API_DOMAIN}/api/v1/contact-order/{contact_order}/contact-order-item/{contact_order_item}
```

```javascript
curl -X PUT
    -H "Content-Type: application/json"
    '{"product_id": 3, "quantity": 2 }'
    https://{API_HOST}/api/v1/contact-order/1/contact-order-item/36
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.firstline.cc/developer/api/contact-order-item.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
