# Dbt Cloud

## **Prerequisites**

Before proceeding with the template configuration, the following must be set up in the environment:

1. **Variable**:
   * **`dbt_account_id`**: The unique identifier for the dbt Cloud account.
2. **Secret**:
   * **`dbt_personal_token`**: A personal API token used for authentication. This token ensures secure access to the dbt Cloud API and must be stored securely.

{% hint style="info" %}
**Note**: Using securely stored secrets like `dbt_personal_token` is strongly recommended to protect sensitive credentials.
{% endhint %}

{% hint style="warning" %}
To access the dbt Cloud API, you must be on the 'Team' or 'Enterprise' plan. The API is not available on the free plan.
{% endhint %}

## Authentication

* Ensure that the **`dbt_account_id`** variable is correctly set and matches the dbt Cloud account you wish to interact with.
* Generate the **`dbt_personal_token`** from dbt Cloud:
  * Navigate to your dbt Cloud account settings.
  * Create a personal token under the **API Access** section.
  * Save this token securely in your environment as **`dbt_personal_token`**.

## Triggering Dbt cloud

When a registered job in Erathos successfully completes, the specified Job will be triggered.

POST Payload:

```json
{
  "description": "Trigger DBT job run on Cloud",
  "is_active": true,
  "method": "POST",
  "url": "https://cloud.getdbt.com/api/v2/accounts/${{variables.dbt_account_id}}/jobs/<DBT_JOB_ID/run/",
  "header": {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": "Bearer ${{secrets.dbt_personal_token}}"
  },
  "body": {
    "cause": "finished job on Erathos platform triggered by ${{erathos.triggered_by}}"
  },
  "rules": [
  ],
  "jobs": [
    "<ERATHOS_JOB_ID>",
  ]
}
```
