Permissions Issue with the Reports API Using a Service Account

Hello,

I’m creating a script in Google Apps Script to suspend users who exceed a certain amount of storage in their Google Mail account, but I’m getting the error in the screenshot.

I’m trying to use the Reports API through a service account with domain delegation, but all calls fail.

The problem is as follows:

Authentication and access token retrieval work correctly.

Calls to the Directory API to list users work perfectly with this same service account.

However, any call to a Reports API endpoint fails, returning an HTML error page instead of the expected JSON response.

We have already performed the following checks without success:

We confirmed that the Client ID and scopes (admin.directory.user and admin.reports.usage.readonly) are correct in Domain Delegation.

We enabled and restarted the Admin SDK API in the Google Cloud project.

We tried different reports (drive:storage_usage_in_bytes and account:last_login_time), and both fail with the same error. way.

We confirm that the impersonated administrator is a Super Administrator.

It appears to be a permissions issue or an internal policy in our Workspace domain that is blocking access to the Reports API. Could you please review the logs on our end to identify the cause?