# Certificate API

> An introduction to the Bitiful Certificate Center API.

## Get a console API token

Get one from the console: <https://console.bitiful.com/apiToken>

## List certificates

No parameters.

**Example request**:

```shell
curl -H "Authorization: {API Token from: https://console.bitiful.com/apiToken}" "https://api.bitiful.com/cert/list"
```

## Get certificate content

> **Tip**
>
> Best practice
>
> Run the **get certificate content API** on a schedule in your own infrastructure and combine it with your deployment scripts to **automatically apply the latest domain certificates** everywhere.

No parameters.

**Example request**:

```shell
curl -H "Authorization: {API Token from: https://console.bitiful.com/apiToken}" "https://api.bitiful.com/cert/data/<cert_name>/content"
```

**Example response**:

```json
// curl -H "Authorization: {API-Token}" "https://api.bitiful.com/cert/data/usercontents.somecdn.com-rsa-auto/content"
{
    "crt": "-----BEGIN CERTIFICATE-----\n<certificate content>\n-----END CERTIFICATE-----",
    "key": "-----BEGIN PRIVATE KEY-----\n<private key content>\n-----END PRIVATE KEY-----",
    "auto": true //whether this is an auto certificate
}
```

> **Warning**
>
> In workflows that fetch certificates automatically, put proper safeguards in place to **prevent your API token from leaking**.

## Add a certificate

**Example request**:

```shell
curl --request POST 'https://api.bitiful.com/cert/add' \
  -H 'Authorization: {API Token from: https://console.bitiful.com/apiToken}' \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "cert_name": "certificate name",
    "cert_private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----",
    "cert_content": "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"
  }'
```
