Note: This developer site is moving to developers.google.com/tag-platform and will be redirected by September 30, 2021

Container Versions: list

Requires authorization

Lists all container versions of a GTM container. Try it now or see an example.

Request

HTTP request

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

Parameters

Parameter name Value Description
Path parameters
accountId string The GTM Account ID.
containerId string The GTM Container ID.
Optional query parameters
headers boolean Retrieve headers only when true. (Default: false)
includeDeleted boolean Also retrieve deleted (archived) versions when true. (Default: false)

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

{
  "containerVersion": [
    accounts.containers.versions Resource
  ],
  "containerVersionHeader": [
    {
      "accountId": string,
      "containerId": string,
      "containerVersionId": string,
      "name": string,
      "numMacros": string,
      "numRules": string,
      "numTags": string,
      "numTriggers": string,
      "deleted": boolean,
      "numVariables": string
    }
  ]
}
Property name Value Description Notes
containerVersion[] list All versions of a GTM Container.
containerVersionHeader[] list All container version headers of a GTM Container.
containerVersionHeader[].accountId string GTM Account ID.
containerVersionHeader[].containerId string GTM Container ID.
containerVersionHeader[].containerVersionId string The Container Version ID uniquely identifies the GTM Container Version.
containerVersionHeader[].name string Container version display name.
containerVersionHeader[].numMacros string Number of macros in the container version.
containerVersionHeader[].numRules string Number of rules in the container version.
containerVersionHeader[].numTags string Number of tags in the container version.
containerVersionHeader[].deleted boolean A value of true indicates this container version has been deleted.
containerVersionHeader[].numTriggers string Number of triggers in the container version.
containerVersionHeader[].numVariables string Number of variables in the container version.

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 container versions for the authorized user.
*/
try {
  ListContainerVersionsResponse versions = tagmanager.accounts().
      containers().versions().list("123456", "54321").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 versions object.
 * The following code shows how to iterate through them.
 */
for (ContainerVersion version : versions.getContainerVersion()) {
  System.out.println("Account Id = " + version.getAccountId());
  System.out.println("Container Id = " + version.getContainerId());
  System.out.println("Container Version Id = "
      + version.getContainerVersionId());
  System.out.println("Version Name = " +  version.getName());
  System.out.println("Version Deleted = " + version.getDeleted());
  System.out.println("Version Notes = %s" + version.getNotes());
  System.out.println("Version Fingerprint = " + version.getFingerprint());

  // Print the Container details.
  Container container = version.getContainer();
  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());

  // Print the Macro details.
  for (Macro macro : version.getMacro()) {
    System.out.println("Macro Id = " + macro.getMacroId());
    System.out.println("Macro Name = " + macro.getName());
    System.out.println("Macro Type = " + macro.getType());
    System.out.println("Macro Notes = " + macro.getNotes());
    if (macro.getParameter() != null) {
      for (Parameter parameter : macro.getParameter()) {
        System.out.println("Parameter Type = " + parameter.getType());
        System.out.println("Parameter Key = " + parameter.getKey());
        System.out.println("Parameter Value = " + parameter.getValue());
      }
    }
    if (macro.getEnablingRuleId() != null) {
      for (String enabllingRuleId : macro.getEnablingRuleId()) {
        System.out.println("Macro Enabling Rule Id = " + enabllingRuleId);
      }
    }
    if (macro.getDisablingRuleId() != null) {
      for (String disablingRuleId : macro.getDisablingRuleId()) {
        System.out.println("Macro Disabling Rule Id " + disablingRuleId);
      }
    }
    System.out.println("Macro Fingerprint = " + macro.getFingerprint());
  }

  // Print the rule details.
  for (Rule rule : version.getRule()) {
    System.out.println("Rule Id = " + rule.getRuleId());
    System.out.println("Rule Name = " + rule.getName());
    System.out.println("Rule Notes = " + rule.getNotes());

    // Get the conditions.
    if (rule.getCondition() != null) {
      for (Condition condition : rule.getCondition()) {
        System.out.println("Condition Type = " + condition.getType());
        if (condition.getParameter() != null) {
          for (Parameter parameter : condition.getParameter()) {
            System.out.println("Parameter Type = " + parameter.getType());
            System.out.println("Parameter Key = " + parameter.getKey());
            System.out.println("Parameter Value = " + parameter.getValue());
          }
        }
      }
    }
    System.out.println("Rule Fingerprint = " + rule.getFingerprint());
  }

  // Print the Tag details.
  if (version.getTag() != null) {
    for (Tag tag : version.getTag()) {
      System.out.println("Tag id = " + tag.getTagId());
      System.out.println("Tag Name = " + tag.getName());
      System.out.println("Tag Type = " + tag.getType());
      if (tag.getFiringRuleId() != null) {
        for (String firingRuleId : tag.getFiringRuleId()) {
          System.out.println("Firing Rule Id  = " + firingRuleId);
        }
      }
      if (tag.getBlockingRuleId() != null) {
        for (String blockingRuleId : tag.getBlockingRuleId()) {
          System.out.println("Blocking Rule Id = " + blockingRuleId);
        }
      }
      System.out.println("Tag Live Only = " + tag.getLiveOnly());

      // Get tag priority.
      Parameter priority = tag.getPriority();
      if (priority != null) {
        System.out.println("Tag Priority Type = " + priority.getType());
        System.out.println("Tag Priority Key = " + priority.getKey());
        System.out.println("Tag Priority Value = " + priority.getValue());
      }

      // Get tag dependencies.
      Parameter dependencies = tag.getDependencies();
      if (dependencies != null) {
        System.out.println("Dependencies Type = " + dependencies.getType());
        System.out.println("Dependencies Key = " + dependencies.getKey());
        System.out.println("Dependencies Value = " + dependencies.getValue());
      }

      System.out.println("Tag Notes = " + tag.getNotes());
      System.out.println("Tag Schedule Start ms = " + tag.getScheduleStartMs());
      System.out.println("Tag Schedule End ms = " + tag.getScheduleEndMs());

      // Get tag parameters.
      if (tag.getParameter() != null) {
        for (Parameter parameter : tag.getParameter()) {
          System.out.println("Parameter Type = " + parameter.getType());
          System.out.println("Parameter Key = " + parameter.getKey());
          System.out.println("Parameter Value = " + parameter.getValue());
        }
      }
      System.out.println("Tag Fingerprint = " + tag.getFingerprint());
    }
  }
}

Python

Uses the Python client library.

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

# This request lists all container versions for the authorized user.
try:
  versions = tagmanager.accounts().containers().versions().list(
      accountId='123456',
      containerId='54321'
  ).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 versions object.
# The following code shows how to iterate through them.
for version in versions.get('containerVersion', []):

  print 'Account Id = %s' % version.get('accountId')
  print 'Container Id = %s' % version.get('containerId')
  print 'Container Version Id = %s' % version.get('containerVersionId')
  print 'Version Name = %s' % version.get('name')
  print 'Version Deleted = %s' % version.get('deleted')
  print 'Version Notes = %s' % version.get('notes')
  print 'Version Fingerprint = %s\n\n' % version.get('fingerprint')

  # Get the container object.
  container = version.get('container', {})
  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')

  # Get the macro objects.
  for macro in version.get('macro', []):
    print 'Macro Id = %s' % macro.get('macroId')
    print 'Macro Name = %s' % macro.get('name')
    print 'Macro Type = %s' % macro.get('type')
    print 'Macro notes = %s' % macro.get('notes')
    print 'Schedule Start ms = %s' % macro.get('scheduleStartMs')
    print 'Schedule End ms = %s' % macro.get('scheduleEndMs')
    for parameter in macro.get('parameter', []):
      print 'Parameter Type = %s' % parameter.get('type')
      print 'Parameter Key = %s' % parameter.get('key')
      print 'Parameter Value = %s' % parameter.get('value')
    for enablingRuleId in macro.get('enablingRuleId', []):
      print 'Macro Enabling Rule Id = %s' % enablingRuleId
    for disablingRuleId in macro.get('disablingRuleId', []):
      print 'Macro Disabling Rule Id = %s' % disablingRuleId
    print 'Macro Fingerprint = %s\n\n' % macro.get('fingerprint')

  # Get the rule object.
  for rule in version.get('rule'):
    print 'Rule Id = %s' % rule.get('ruleId')
    print 'Rule Name = %s' % rule.get('name')
    print 'Rule Notes = %s' % rule.get('notes')
    for condition in rule.get('condition', []):
      print 'Condition Type = %s' % condition.get('type')
      for parameter in condition.get('parameter', []):
        print 'Condition Parameter Type = %s' % condition.get('type')
        print 'Condition Parameter Key = %s' % condition.get('key')
        print 'Condition Parameter Value = %s' % condition.get('value')
    print 'Rule Fingerprint = %s\n\n' % rule.get('fingerprint')

  # Get the tag objects.
  for tag in version.get('tag', []):
    print 'Tag Id = %s' % tag.get('tagId')
    print 'Tag Name = %s' % tag.get('name')
    print 'Tag Type = %s' % tag.get('type')
    for firingRuleId in tag.get('firingRuleId', []):
      print 'Tag Firing Rule Id = %s' % firingRuleId
    for blockingRuleId in tag.get('blockingRuleId', []):
      print 'Tag Blocking Rule Id = %s' % blockingRuleId
    print 'Tag Live Only = %s' % tag.get('liveOnly')

    # Get tag priority.
    priority = tag.get('priority', {})
    print 'Tag Priority Type = %s' % priority.get('type')
    print 'Tag Priority Key = %s' % priority.get('key')
    print 'Tag Priority value = %s' % priority.get('value')

    # Get tag dependencies.
    dependencies = tag.get('dependencies', {})
    print 'printing Dependencies: %s' % dependencies
    print 'Dependencies Type = %s' % dependencies.get('type')
    print 'Dependencies Key = %s' % dependencies.get('key')
    print 'Dependencies Value = %s' % dependencies.get('value')

    print 'Tag Notes = %s' % tag.get('notes')
    print 'Tag Schedule Start ms = %s' % tag.get('scheduleStartMs')
    print 'Tag Schedule End ms = %s' % tag.get('scheduleEndMs')
    for parameter in tag.get('parameter', []):
      print 'Parameter Type = %s' % parameter.get('type')
      print 'Parameter Key = %s' % parameter.get('key')
      print 'Parameter Value = %s' % parameter.get('value')
    print 'Tag Fingerprint = %s\n\n' % tag.get('fingerprint')

Try it!

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