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

# AttachDisks

## 1. API Description

This API (AttachDisks) is used to attach one or more disks to an instance.

{% hint style="info" %}
**Notes**

* Up to 10 disks can be attached in a single request.
* The target instance must exist and be in an available status (statuses such as creating and initializing are not available statuses), and the number of disks in this request must not exceed the maximum number available for the instance (for the specific number, see the quota). If any of the above is not met, the entire request fails with an error code directly, none of the disks in this request is processed, and `failedDiskIds` is **not** returned.
* If a disk is already attached to the target instance of this request, it is regarded as having reached the target status and is skipped directly.
* If a disk does not meet the attachment conditions (it is not in the same region as the instance, it is already attached to another instance, or its status does not support attachment, and so on), only this disk fails to be attached and its ID appears in the `failedDiskIds` in the response, which does not affect the normal attachment of the other disks.
* Disk IDs that do not exist in the request are silently ignored, which neither causes the request to fail nor appears in `failedDiskIds`.
  {% endhint %}

## 2. Input Parameters

The following request parameter list only provides API request parameters.

| Parameter Name | Required | Type            | Description                                                                                                                                                                   |
| -------------- | -------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| diskIds        | Yes      | Array of String | <p>ID list of the disks to be attached.</p><p>It can be obtained by calling <a href="/api-reference/zec/disk/describedisks.md">DescribeDisks</a>.</p>                         |
| instanceId     | Yes      | String          | <p>ID of the instance that the disk is attached to.</p><p>It can be obtained by calling <a href="/api-reference/zec/instance/describeinstances.md">DescribeInstances</a>.</p> |

## 3. Output Parameters

| Parameter Name | Type            | Description                                                                                                           |
| -------------- | --------------- | --------------------------------------------------------------------------------------------------------------------- |
| requestId      | String          | <p>The unique request ID, which is returned for each request.</p><p>RequestId is required for locating a problem.</p> |
| failedDiskIds  | Array of String | Cloud disk mounting failed.                                                                                           |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}
**1. Attach cloud disks to an instance.**

```json
POST /api/v2/zec HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: AttachDisks
<Common Request Params>

Request：
{
  "diskIds": [
    "your-disk-id"
  ],
  "instanceId": "your-instance-id"
}

Response：
{
  "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
  "response": {
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "failedDiskIds": []
  }
}
```

{% endtab %}
{% endtabs %}

## 5. Developer Resources

Zenlayer Cloud API 2.0 integrates [SDKs](/api-reference/api-introduction/toolkit/api-sdk.md)，to make it easier for you to call APIs. More programming languages will be supported.

## 6. Error Codes

The following only lists the error codes related to the API business logic. For other error codes, see [Common Error Codes](/api-reference/api-introduction/instruction/commonerrorcode.md).

| HTTP Status Code | Error Code                               | Description                                                 |
| ---------------- | ---------------------------------------- | ----------------------------------------------------------- |
| 404              | INVALID\_INSTANCE\_NOT\_FOUND            | Instance not found.                                         |
| 400              | UNSUPPORTED\_OPERATION\_INSTANCE\_STATUS | Operations on instances in current state are not supported. |
