# Thêm ảnh sản phẩm

* API này dùng để thêm ảnh cho sản phẩm từ CDN khác không thuộc Nhanh.vn, thường dùng khi bạn có website riêng và có link ảnh trên website riêng, không upload ảnh lên Nhanh.vn
* Được thêm tối đa 10 sản phẩm mỗi request, mỗi sản phẩm tối đa 20 ảnh.
* Chú ý:
  * Nhanh.vn sẽ không tải các link ảnh này về Nhanh.vn mà dùng luôn đường dẫn link ảnh bạn bắn sang để hiển thị hoặc đồng bộ đi các chỗ khác.
  * Khi dùng tính năng đồng bộ Facebook Shop, nếu sản phẩm trên Nhanh.vn không có ảnh, nhưng có ảnh (external image) bắn từ API về, Nhanh.vn sẽ dùng external images này để bắn lên Facebook Shop. Facebook yêu cầu anh có độ phân giải tối thiếu từ 500 x 500px. Chú ý: Server xử lý ảnh này cần đảm bảo tốc độ ổn định: Tốc độ nhanh, không chặn các tool crawler của Facebook (thường là IP từ United States).

## Request

* URI: /api/product/externalimage. Xem các [common request params](/v2/readme.md#request-params).
* Các key của mảng **data array** dùng để tạo **data** json string.
* Cho phép thêm ảnh cho nhiều sản phẩm cùng lúc

```javascript
data = [
    {
        "productId": int, // ID sản phẩm trên Nhanh.vn
        "externalImages": [
            "imagePath1", // link ảnh sản phẩm
            "imagePath2", // link ảnh sản phẩm
        ]
    },
    {
        "productId": int, // ID sản phẩm trên Nhanh.vn
        "externalImages": [
            "imagePath1", // link ảnh sản phẩm
            "imagePath2", // link ảnh sản phẩm
        ]
    },
    ...
]
```

| Key            | Type                          | Description                                                                                                                                                                                                                                                                                            |
| -------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| productId      | bigint $$^{{\color{red}\*}}$$ | ID sản phẩm trên Nhanh.vn                                                                                                                                                                                                                                                                              |
| mode           | string                        | <p>update (mặc định nếu không truyền giá trị) hoặc deleteall<br>- Mode update: Nhanh sẽ check nếu trên hệ thống chưa có ảnh trong mảng thì sẽ thêm mới. Các sản đã bắn sang trước đó, mà sau đó không tồn tại ở mảng mới, sẽ bị xóa khỏi hệ thống<br>- Mode deleteall: Xóa hết ảnh cũ của sản phẩm</p> |
| externalImages | array                         | <p>Link ảnh sản phẩm<br>VD:<br>imageLinks = \[ "<https://external.cdn.com/product/image1.jpg>",<br>"<https://external.cdn.com/product/image2.jpg>" ]</p>                                                                                                                                               |

### Sample request

```javascript
curl --location 'https://pos.open.nhanh.vn/api/product/externalimage' \
--form 'version="2.0"' \
--form 'appId="{{appId}}"' \
--form 'businessId="{{businessId}}"' \
--form 'accessToken="{{accessToken}}"' \
--form 'data="[{\"productId\":312311,\"externalImages\":[\"https://external.cdn.com/product/image1.jpg\",\"https://external.cdn.com/product/image2.jpg\"]},{\"productId\":312312,\"externalImages\":[\"https://external.cdn.com/product/image3.jpg\"]}]"'

```

## Response

JSON decode the response to get the structure:

| Key      | Type  | Description                               |
| -------- | ----- | ----------------------------------------- |
| code     | int   | 1 = success or 0 = failed                 |
| messages | array | is an array of error messages if code = 0 |
| data     | array | Mảng ID sản phẩm trên Nhanh.vn            |

```php
[
    "code" => 1, // 1 is success, 0 is error
    "messages" => [], // error messages if code is 0
    "data" => [
        // int ID sản phẩm Nhanh.vn
        "productId1",
        "productId2",
        "productId3",
        ...
    ]
]
```


---

# 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://apidocs.nhanh.vn/v2/product/externalimage.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.
