Problem
This article addresses an issue where API requests to the HCP Terraform Audit Trail API succeed with an HTTP 200 status code but return an empty JSON response body.
The response body contains an empty data array and zeroed pagination counts, similar to the following example.
{
"data": [],
"pagination": {
"current_page": 1,
"page_size": 1000,
"prev_page": null,
"next_page": null,
"total_pages": 0,
"total_count": 0
}
}Cause
This response occurs when the API request is authenticated with an incorrect token type, such as a user API token. API requests to the Audit Trails API require an organization token, as noted in the documentation.
Note: This endpoint cannot be accessed with a user token or team token. You must access it with an organization token.
Solution
To resolve this issue, generate a new organization API token and use it to authenticate requests to the HCP Terraform Audit Trails API.
You can generate these tokens at https://app.terraform.io/app/<organization>/settings/authentication-tokens.
Alternatively, you can generate a token from the HCP Terraform UI:
- Select your organization.
- Navigate to Settings in the top navigation bar.
- Select API tokens from the left sidebar.