# CreateCertificate

## 1. API Description

This API (CreateCertificate) is used to create a certificate.

{% hint style="info" %}
Note

* Modifications to the certificate content are not supported. To make changes, you need to create a new certificate.
  {% endhint %}

## 2. Request Parameters

The following list includes the request parameters required by the API:

| Parameter Name     | Required | Type   | Description                                                                                     |
| ------------------ | -------- | ------ | ----------------------------------------------------------------------------------------------- |
| certificateContent | Yes      | String | Certificate content                                                                             |
| certificateKey     | Yes      | String | Certificate key                                                                                 |
| certificateLabel   | No       | String | <p>Custom certificate label</p><p>Must not exceed 64 characters</p>                             |
| resourceGroupId    | No       | String | <p>ID of the resource group.</p><p>If not provided, the default resource group will be used</p> |

## 3. Output Parameters

| Parameter Name | Type   | Description                                                                                                           |
| -------------- | ------ | --------------------------------------------------------------------------------------------------------------------- |
| certificateId  | String | Certificate ID                                                                                                        |
| requestId      | String | <p>Unique request ID.</p><p>Returned with every request. This request's requestId is needed when troubleshooting.</p> |

## 4. Code Example

{% tabs %}
{% tab title="Example" %}

1. **Upload a certificate.**

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

Request:
{
  "certificateContent": "-----BEGIN CERTIFICATE----- MIIGDTCC****** -----END CERTIFICATE-----",
  "certificateKey": "-----BEGIN RSA PRIVATE KEY----- MIIEogIB****** -----END RSA PRIVATE KEY-----",
}

Response:
{
  "requestId": "T6883FCD0-3E7D-44EA-A517-A421A52A27F4",
  "response": {
    "requestId": "T6883FCD0-3E7D-44EA-A517-A421A52A27F4",
    "certificateId": "f0864***66c6fa",
  }
}
```

{% endtab %}
{% endtabs %}

## 5. Error Codes

The following includes error codes encountered in business logic. For other error codes, see [Common Error Codes](https://docs.console.zenlayer.com/api-reference/api-introduction/instruction/commonerrorcode).

| HTTP Status Code | Error Code                            | Description                                                 |
| ---------------- | ------------------------------------- | ----------------------------------------------------------- |
| 400              | CERTIFICATE\_EXPIRED                  | Certificate has expired                                     |
| 400              | CERTIFICATE\_CONTENT\_NOT\_MATCH\_KEY | Certificate does not match key                              |
| 400              | INVALID\_CERTIFICATE\_CONTENT         | Parsing failed, please check the certificate content format |
| 400              | INVALID\_CERTIFICATE\_KEY             | Parsing failed, please check the key format                 |
| 400              | CERTIFICATE\_DUPLICATED               | Certificate name or content is duplicated                   |
