Containers: list

Requires authorization

Lists all containers that belongs to a GTM account. Try it now or see an example.

Request

HTTP request

GET https://www.googleapis.com/tagmanager/v1/accounts/accountId/containers

Parameters

Parameter name Value Description
Path parameters
accountId string The GTM Account ID.

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.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:

{
  "containers": [
    accounts.containers Resource
  ]
}
Property name Value Description Notes
containers[] list All Containers of a GTM Account.

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 containers for the authorized user.
 */
try {
  ListContainersResponse containers =
      tagmanager.accounts().containers().list("123456").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 containers object.
 * The following code shows how to iterate through them.
 */
for (Container container : containers.getContainers()) {
  System.out.println("Account Id = " + container.getAccountId());
  System.out.println("Container Id = " + container.getContainerId());
  System.out.println("Container Name = " + container.getName());
  if (container.getDomainName() != null) {
    for (String domain : container.getDomainName()) {
      System.out.println("Domain Name = " + domain);
    }
  }
  System.out.println("Timezone Country Id = "
      + container.getTimeZoneCountryId());
  System.out.println("Timezone Id = " + container.getTimeZoneId());
  System.out.println("Container Notes = " + container.getNotes());
  for (String usageContext : container.getUsageContext()) {
    System.out.println("Usage context = " + usageContext);
  }
  System.out.println("Container Fingerprint = " + container.getFingerprint());
}

Python

Uses the Python client library.

# Note: This code assumes you have an authorized tagmanager service object.

# This request lists all containers for the authorized user.
try:
  containers = tagmanager.accounts().containers().list(
      accountId='123456'
  ).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 ('There was an API error : %s : %s' %
         (error.resp.status, error.resp.reason))


# The results of the list method are stored in the containers object.
# The following code shows how to iterate through them.
for container in containers.get('containers', []):
  print 'Account Id = %s' % container.get('accountId')
  print 'Container Id = %s' % container.get('containerId')
  print 'Container Name = %s' % container.get('name')
  for domain in container.get('domainName', []):
    print 'Domain Name = %s' % domain
  print 'Timezone Country Id = %s' % container.get('timeZoneCountryId')
  print 'Timezone Id = %s' % container.get('timeZone')
  print 'Notes = %s' % container.get('notes')
  for usageContext in container.get('usageContext'):
    print 'Usage Context = %s' % usageContext
  print 'Container Fingerprint = %s\n\n' % container.get('fingerprint')

Try it!

Use the APIs Explorer below to call this method on live data and see the response.