Requires authorization
Lists all GTM accounts that a user has access to. Try it now or see an example.
Request
HTTP request
GET https://www.googleapis.com/tagmanager/v1/accounts
Authorization
This request requires authorization with at least one of the following scopes (read more about authentication and authorization).
Scope |
---|
https://www.googleapis.com/auth/tagmanager.readonly |
https://www.googleapis.com/auth/tagmanager.manage.accounts |
https://www.googleapis.com/auth/tagmanager.edit.containers |
Request body
Do not supply a request body with this method.
Response
If successful, this method returns a response body with the following structure:
{ "accounts": [ accounts Resource ] }
Property name | Value | Description | Notes |
---|---|---|---|
accounts[] |
list |
List of GTM Accounts that a user has access to. |
Examples
Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).
Java
Uses the Java client library.
/* * Note: This code assumes you have an authorized tagmanager service object. */ /* * This request lists all accounts for the authorized user. */ try { ListAccountsResponse accounts = tagmanager.accounts().list().execute(); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } /* * The results of the list method are stored in the accounts object. * The following code show how to iterate through them. */ for (Account account : accounts.getAccounts()) { System.out.println("Account Id = " + account.getAccountId()); System.out.println("Account Name = " + account.getName()); System.out.println("Account Share Data = " + account.getShareData()); System.out.println("Account Fingerprint = " + account.getFingerprint()); }
Python
Uses the Python client library.
# Note: This code assumes you have an authorized tagmanager service object. # This request lists all accounts for the authorized user. try: accounts = tagmanager.accounts().list().execute() except TypeError, error: # Handle errors in constructing a query. print 'There was an error in constructing your query : %s' % error except HttpError, error: # Handle API errors. print dir(error) print ('There was an API error : %s : %s' % (error.resp.status, error.resp.reason)) # The results of the list method are stored in the accounts object. # The following code shows how to iterate through them. for account in accounts.get('accounts', []): print 'Account Id = %s' % account.get('accountId') print 'Account Name = %s' % account.get('name') print 'Account Share Data = %s' % account.get('shareData') print 'Account Fingerprint = %s' % account.get('fingerprint')
Try it!
Use the APIs Explorer below to call this method on live data and see the response.