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

# Get database TLS certificate

> Get a database's TLS file with GET /v2/databases/{database_id}/credentials/certificate: a base64 PEM with the private key and certificate.

<ParamField header="Authorization" type="string" placeholder="API Key" required>
  The API key for your account. You can find this in your [account settings](https://squarecloud.app/en/account/security).
</ParamField>

Requires an API key with the `databases:credentials` [scope](/en/api-reference/authentication#scopes).

Returns the TLS file the database uses for encrypted connections, base64-encoded. Once decoded, it is a PEM with the private key followed by the certificate, ready to be written to a `.pem` file. Managed MongoDB, MySQL and PostgreSQL databases each ship with their own certificate; check your driver's TLS options to see whether it needs one.

The database must be running when you call this, if it is stopped, [start it](/en/api-reference/endpoint/databases/start) first. To rotate the certificate instead of just reading it, use [Reset Credentials](/en/api-reference/endpoint/databases/credentials/reset) with `reset: "certificate"`, then re-fetch it here.

## Parameters

<ParamField path="database_id" type="string" placeholder="Database ID" required>
  The ID of the database.
</ParamField>

## Response

<ResponseField name="status" type="string">
  Indicates whether the call was successful: `success` if it was, `error` if not.
</ResponseField>

<ResponseField name="response" type="object">
  The contents of the response.

  <Expandable title="Toggle object">
    <ResponseField name="certificate" type="string">
      The PEM (private key followed by the certificate), encoded in base64.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseExample>
  ```json theme={"system"}
  {
      "status": "success",
      "response": {
          "certificate": "CERTIFICATE_IN_BASE_64_FORMAT"
      }
  }
  ```
</ResponseExample>

## Common errors

| Code | HTTP | Meaning |
| - | - | - |
| `DATABASE_NOT_RUNNING` | 400 | The database is stopped; start it before reading the certificate. |
| `READ_FAILED` | 400 | The certificate file could not be read from the cluster. |
| `DATABASE_NOT_FOUND` | 404 | The database does not exist or is not owned by the caller. |

## Related

* CLI: [`squarecloud db credentials certificate`](/en/cli-reference/databases#squarecloud-db-credentials-certificate)
* SDKs: [`api.databases.certificate()`](/en/sdks/js/databases) (JavaScript), [`client.databases.certificate()`](/en/sdks/py/databases) (Python), [`c.Databases.Certificate()`](/en/sdks/go/databases) (Go)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.