> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xhuoapi.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Artistic QR Tasks API 的对接和使用

> Art QR Code Generation 集成指南 - XHuoAPI

Artistic QR Tasks API 的主要功能是通过输入 Artistic QR Generation API 生成的任务ID来查询该任务的执行情况。

本文档将详细介绍  Artistic QR Tasks API  的对接说明，帮助您轻松集成并充分利用该 API 的强大功能。通过  Artistic QR Tasks API ，您可以轻松实现查询 Artistic QR Generation API 的任务执行情况。

## 申请流程

要使用 Artistic QR Tasks API，需要先到 申请页面 [Artistic QR Generation API ](https://api.xhuoapi.ai/documents/ee085d2a-a0b9-4f0e-8b4d-8da407345138)申请相应的服务，然后复制 Artistic QR Generation API 的任务ID，如图所示：

<p>
  <img src="https://cdn.xhuoapi.ai/2wicjy.png" width="500" className="m-auto" />
</p>

最后进入 Artistic QR Tasks API页面 [Artistic QR Tasks API ](https://api.xhuoapi.ai/documents/21de9d76-6e39-4ac3-b8b9-20e7194c02b4)申请相应的服务，进入页面之后，点击「Acquire」按钮，如图所示：

![申请页面](https://cdn.xhuoapi.ai/rci31i.png)

如果您尚未登录或注册，会自动跳转到[登录页面](https://api.xhuoapi.ai)邀请您来注册和登录，登录注册之后会自动返回当前页面。

首次申请时会有免费额度赠送，可以免费使用该 API。

## 请求示例

Artistic QR Tasks API 可以用于查询 Artistic QR Generation API 一个 API 的结果。关于怎样使用 Artistic QR Generation API，请参考文档 [Artistic QR Generation API ](https://api.xhuoapi.ai/documents/ee085d2a-a0b9-4f0e-8b4d-8da407345138)。

我们以 Artistic QR Generation API 服务返回的任务ID一个为例，演示如何使用该 API。假设我们有一个任务ID：e2c65b20-a970-431e-99c1-76721e799df8，接下来演示如何通过传入一个任务ID来。

### 任务示例图

<p>
  <img src="https://cdn.xhuoapi.ai/2wicjy.png" width="500" className="m-auto" />
</p>

### 设置请求头和请求体

**Request Headers** 包括：

* `accept`：指定接收 JSON 格式的响应结果，这里填写为 `application/json`。
* `authorization`：调用 API 的密钥，申请之后可以直接下拉选择。

**Request Body** 包括：

* `id`：上传的任务ID。
* `action`：对任务的操作方式。

设置如下图所示：

<p>
  <img src="https://cdn.xhuoapi.ai/use825.png" width="500" className="m-auto" />
</p>

### 代码示例

可以发现，在页面右侧已经自动生成了各种语言的代码，如图所示：

<p>
  <img src="https://cdn.xhuoapi.ai/jejwy6.png" width="500" className="m-auto" />
</p>

部分代码示例如下：

#### CURL

```bash theme={null}
curl -X POST 'https://api.xhuoapi.ai/v1/qrart/tasks' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "id": "e2c65b20-a970-431e-99c1-76721e799df8",
  "action": "retrieve"
}'
```

#### Python

```python theme={null}
import requests

url = "https://api.xhuoapi.ai/v1/qrart/tasks"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "id": "e2c65b20-a970-431e-99c1-76721e799df8",
    "action": "retrieve"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)
```

### 响应示例

请求成功后，API 将返回此处二维码任务的详情信息。例如：

```json theme={null}
{
  "_id": "668cb62c550a4144a582e372",
  "id": "e2c65b20-a970-431e-99c1-76721e799df8",
  "application_id": "3d25be99-4676-44d3-90bb-23086bc25300",
  "created_at": 1720497708.318,
  "credential_id": "6e80fca1-9a49-4507-ae8e-601dbd0ab3ca",
  "request": {
    "aspect_ratio": "1:1",
    "callback_url": null,
    "content": "https://api.xhuoapi.ai",
    "content_image_url": null,
    "ecl": "H",
    "image_origin": null,
    "marker_shape": "square",
    "negative_prompt": null,
    "padding_level": 5,
    "padding_noise": 0,
    "pattern": "custom",
    "pixel_style": "square",
    "position": "center",
    "preset": "",
    "prompt": "mexican tacos",
    "qrw": 2,
    "ratio": null,
    "rotate": 0,
    "seed": null,
    "steps": 20,
    "sub_marker": "square",
    "timeout": null,
    "trace_id": "a99ecc24-eda0-45c6-bb5f-98060c30b490",
    "type": "link"
  },
  "response": {
    "image_url": "https://platform.cdn.xhuoapi.ai/qrart/e2c65b20-a970-431e-99c1-76721e799df8.png",
    "image_width": 768,
    "image_height": 768,
    "seed": 5324369603686616,
    "success": true
  }
}
```

返回结果一共有多个字段，request 字段就是发起任务时的 request body，同时response 字段是任务完成后返回的response body，其结果和 Artistic QR Generation API 的请求和返回一致。字段介绍如下。

* `id`，生成此二维码任务的 ID，用于唯一标识此次二维码生成任务。
* `request`，查询二维码任务中的请求信息。
* `response`，查询二维码任务中的返回信息。

## 批量查询操作

这是是针对多个二维码任务ID来进行查询二维码任务详情，与上面不同的是需要将action选中为retrieve\_batch

**Request Body** 包括：

* `ids`：上传的任务ID数组。
* `action`：对任务的操作方式。

设置如下图所示：

<p>
  <img src="https://cdn.xhuoapi.ai/mrbxmr.png" width="500" className="m-auto" />
</p>

### 代码示例

可以发现，在页面右侧已经自动生成了各种语言的代码，如图所示：

<p>
  <img src="https://cdn.xhuoapi.ai/u3b61d.png" width="500" className="m-auto" />
</p>

部分代码示例如下：

#### CURL

```bash theme={null}
curl -X POST 'https://api.xhuoapi.ai/v1/qrart/tasks' \
-H 'accept: application/json' \
-H 'authorization: Bearer {token}' \
-H 'content-type: application/json' \
-d '{
  "ids": ["8c89e97b-6a79-4406-b2ce-e00f92540b4e","e2c65b20-a970-431e-99c1-76721e799df8"],
  "action": "retrieve_batch"
}'
```

#### Python

```python theme={null}
import requests

url = "https://api.xhuoapi.ai/v1/qrart/tasks"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {token}",
    "content-type": "application/json"
}

payload = {
    "ids": ["8c89e97b-6a79-4406-b2ce-e00f92540b4e","e2c65b20-a970-431e-99c1-76721e799df8"],
    "action": "retrieve_batch"
}

response = requests.post(url, json=payload, headers=headers)
print(response.text)
```

### 响应示例

请求成功后，API 将返回此次所有批量二维码任务的具体详情信息。例如：

```json theme={null}
{
  "items": [
    {
      "_id": "668cb90e550a4144a5834557",
      "id": "8c89e97b-6a79-4406-b2ce-e00f92540b4e",
      "application_id": "3d25be99-4676-44d3-90bb-23086bc25300",
      "created_at": 1720498446.039,
      "credential_id": "b7f9aaa1-43d8-471f-a826-cd0f4733fec5",
      "request": {
        "aspect_ratio": "1:1",
        "callback_url": null,
        "content": "https://huyinfu.space",
        "content_image_url": null,
        "ecl": "H",
        "image_origin": null,
        "marker_shape": "square",
        "negative_prompt": null,
        "padding_level": 5,
        "padding_noise": 0,
        "pattern": "custom",
        "pixel_style": "square",
        "position": "center",
        "preset": "",
        "prompt": "mexican tacos",
        "qrw": 2,
        "ratio": null,
        "rotate": 0,
        "seed": null,
        "steps": 20,
        "sub_marker": "square",
        "timeout": null,
        "trace_id": "44d33486-0527-451f-afc2-df11aab7e049",
        "type": "link"
      },
      "response": {
        "image_url": "https://platform.cdn.xhuoapi.ai/qrart/8c89e97b-6a79-4406-b2ce-e00f92540b4e.png",
        "image_width": 768,
        "image_height": 768,
        "seed": 2701847236953402,
        "success": true
      }
    },
    {
      "_id": "668cb62c550a4144a582e372",
      "id": "e2c65b20-a970-431e-99c1-76721e799df8",
      "application_id": "3d25be99-4676-44d3-90bb-23086bc25300",
      "created_at": 1720497708.318,
      "credential_id": "6e80fca1-9a49-4507-ae8e-601dbd0ab3ca",
      "request": {
        "aspect_ratio": "1:1",
        "callback_url": null,
        "content": "https://api.xhuoapi.ai",
        "content_image_url": null,
        "ecl": "H",
        "image_origin": null,
        "marker_shape": "square",
        "negative_prompt": null,
        "padding_level": 5,
        "padding_noise": 0,
        "pattern": "custom",
        "pixel_style": "square",
        "position": "center",
        "preset": "",
        "prompt": "mexican tacos",
        "qrw": 2,
        "ratio": null,
        "rotate": 0,
        "seed": null,
        "steps": 20,
        "sub_marker": "square",
        "timeout": null,
        "trace_id": "a99ecc24-eda0-45c6-bb5f-98060c30b490",
        "type": "link"
      },
      "response": {
        "image_url": "https://platform.cdn.xhuoapi.ai/qrart/e2c65b20-a970-431e-99c1-76721e799df8.png",
        "image_width": 768,
        "image_height": 768,
        "seed": 5324369603686616,
        "success": true
      }
    }
  ],
  "count": 2
}
```

返回结果一共有多个字段，其中items是包含了批量二维码任务的具体详情信息，每个二维码任务的具体信息与上文的字段一样，字段信息如下。

* `items`，批量二维码任务的所有具体详情信息。它是一个数组，每个数组的元素和上文查询单个任务的返回结果格式是一样的。
* `count`，此处批量查询二维码任务的个数。

## 错误处理

在调用 API 时，如果遇到错误，API 会返回相应的错误代码和信息。例如：

* `400 token_mismatched`：Bad request, possibly due to missing or invalid parameters.
* `400 api_not_implemented`：Bad request, possibly due to missing or invalid parameters.
* `401 invalid_token`：Unauthorized, invalid or missing authorization token.
* `429 too_many_requests`：Too many requests, you have exceeded the rate limit.
* `500 api_error`：Internal server error, something went wrong on the server.

### 错误响应示例

```
{
  "success": false,
  "error": {
    "code": "api_error",
    "message": "fetch failed"
  },
  "trace_id": "2cf86e86-22a4-46e1-ac2f-032c0f2a4e89"
}
```

## 结论

通过本文档，您已经了解了如何使用 Artistic QR Tasks API 进行查询单个或批量二维码任务的所有具体详情信息。希望本文档能帮助您更好地对接和使用该 API。如有任何问题，请随时联系我们的技术支持团队。
