Q:

Error accessing Google Tagmanager account: (404) Not found or permission denied

I started research Google Tag Manager API and use php language to call API function to list all containers with accountId:
$containers = $service->listAccountsContainers('accountId');

but get error as below:
Error calling GET https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers: (404) Not found or permission denied

Otherwise, I've tested on https://developers.google.com/tag-manager/api/v1/reference/accounts/containers/list and get response successfully: 200 OK.
P/s: I've set service account name, .p12 file, scopes and got access_token return.

A:

A service account by default does not have access to any Google Tag Manager accounts.   If you want it to be able to access your  account you need to grant it access to the account.
Go to the admin section of Google tagmanager

Go to user management

click add new user

Take the service account email address and use this in the email field of the form above.

