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

# Create Certificate

> Creates a new certificate and deploys it to specified environments. The certificate must be provided as a PEM-encoded file. The certificate is automatically deployed to all specified environments.

## Endpoint

```
POST /apiops/projects/{projectName}/certificates/
```

## Authentication

Requires a Personal API Access Token.

### Header

```
Authorization: Bearer YOUR_TOKEN
```

## Request

### Headers

| Header        | Value               | Required |
| ------------- | ------------------- | -------- |
| Authorization | Bearer `{token}`    | Yes      |
| Content-Type  | multipart/form-data | Yes      |

### Path Parameters

| Parameter   | Type   | Required | Description  |
| ----------- | ------ | -------- | ------------ |
| projectName | string | Yes      | Project name |

### Form Data

| Parameter              | Type           | Required | Description                                            |
| ---------------------- | -------------- | -------- | ------------------------------------------------------ |
| certificateName        | string         | Yes      | Certificate name (unique identifier)                   |
| alias                  | string         | Yes      | Certificate alias (unique per environment)             |
| certificateDescription | string         | Yes      | Certificate description                                |
| environmentList        | array\[string] | Yes      | Comma-separated list of environment names to deploy to |
| pemEncodedFile         | file           | Yes      | PEM-encoded certificate file                           |

### Notes

* `certificateName` must be unique within the project
* `alias` must be unique per environment (can be same across environments)
* `environmentList` is comma-separated (e.g., "production,staging")
* `pemEncodedFile` must be a valid PEM-encoded certificate file
* Certificate file must not be empty
* Certificate is automatically deployed to all specified environments

### PEM File Format

The certificate file should be in PEM format:

```
-----BEGIN CERTIFICATE-----
MIIFXTCCBEWgAwIBAgIQ...
(base64 encoded certificate content)
...
-----END CERTIFICATE-----
```

## Response

### Success Response (200 OK)

```json theme={null}
{
  "success": true,
  "deploymentResult": {
    "success": true,
    "message": "Deployment completed successfully",
    "environmentResults": [
      {
        "environmentName": "production",
        "success": true,
        "message": "Deployed successfully"
      },
      {
        "environmentName": "staging",
        "success": true,
        "message": "Deployed successfully"
      }
    ]
  }
}
```

### Error Response (400 Bad Request)

```json theme={null}
{
  "error": "bad_request",
  "error_description": "certificateName value can not be empty!"
}
```

or

```json theme={null}
{
  "error": "bad_request",
  "error_description": "alias value can not be empty!"
}
```

or

```json theme={null}
{
  "error": "bad_request",
  "error_description": "pemEncodedFile value can not be empty!"
}
```

or

```json theme={null}
{
  "error": "bad_request",
  "error_description": "environmentList value can not be empty!"
}
```

or

```json theme={null}
{
  "error": "bad_request",
  "error_description": "Certificate (name: my-certificate) is already exist!"
}
```

or

```json theme={null}
{
  "error": "bad_request",
  "error_description": "Alias (my-cert-alias) is already used for another certificate, try changing this value!"
}
```

### Common Causes

* Missing required form fields
* Certificate name already exists
* Alias already exists in the environment
* Invalid PEM file format
* Empty certificate file
* Environment does not exist

## cURL Example

### Example 1: Create Certificate with Single Environment

```bash theme={null}
curl -X POST \
  "https://demo.apinizer.com/apiops/projects/MyProject/certificates/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "certificateName=my-certificate" \
  -F "alias=my-cert-alias" \
  -F "certificateDescription=SSL certificate for API" \
  -F "environmentList=production" \
  -F "pemEncodedFile=@certificate.pem"
```

### Example 2: Create Certificate with Multiple Environments

```bash theme={null}
curl -X POST \
  "https://demo.apinizer.com/apiops/projects/MyProject/certificates/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "certificateName=my-certificate" \
  -F "alias=my-cert-alias" \
  -F "certificateDescription=SSL certificate for API" \
  -F "environmentList=production,staging,development" \
  -F "pemEncodedFile=@certificate.pem"
```

## Notes and Warnings

* **Certificate Name**:
  * Must be unique within the project
  * Cannot be changed after creation

* **Alias**:
  * Must be unique per environment
  * Same alias can be used in different environments
  * Used for certificate identification in keystore

* **PEM File Format**:
  * Certificate must be in PEM format
  * File must include BEGIN and END markers
  * Base64 content between markers

* **Environment List**:
  * Comma-separated list of environment names
  * All environments must exist
  * Certificate is deployed to all specified environments

* **Automatic Deployment**:
  * Certificate is automatically deployed after creation
  * Deployment results are returned in the response
  * Failed deployments are included in `environmentResults`

* **Certificate Validation**:
  * Certificate is validated during creation
  * Invalid certificates will cause creation to fail

## Permissions

User must have **`SECRETS` + `MANAGE`** permission in the project. For deployment operations (when deploying certificates to environments), user must also have **`SECRETS` + `DEPLOY_UNDEPLOY`** permission.

## Related Documentation

* [List Certificates](/api-reference/keys-secrets/crud/list-certificates) - List all certificates
* [Get Certificate](/api-reference/keys-secrets/crud/get-certificate) - Get a specific certificate
* [Update Certificate](/api-reference/keys-secrets/crud/update-certificate) - Update a certificate
