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

Container Versions: create

Requires authorization

Creates a container version. Try it now or see an example.

Request

HTTP request

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

Authorization

This request requires authorization with the following scope (read more about authentication and authorization).

Scope
https://www.googleapis.com/auth/tagmanager.edit.containerversions

Request body

In the request body, supply data with the following structure:

{
  "quickPreview": boolean,
  "name": string,
  "notes": string
}
Property name Value Description Notes
quickPreview boolean The creation of this version may be for quick preview and shouldn't be saved.
name string The name of the container version to be created.
notes string The notes of the container version to be created.

Response

If successful, this method returns a response body with the following structure:

{
  "containerVersion": accounts.containers.versions Resource,
  "compilerError": boolean
}
Property name Value Description Notes
containerVersion nested object The container version created.
compilerError boolean Compiler errors or not.

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 creates a new container version.
 */

// Create the container versions options object.
CreateContainerVersionRequestVersionOptions options =
    new  CreateContainerVersionRequestVersionOptions();
options.setName("Container Version");
options.setNotes("Sample Container Version");
options.setQuickPreview(false);

try {
  CreateContainerVersionResponse response = tagmanager.accounts().
      containers().versions().create("123456", "54321", options).execute();
} catch (GoogleJsonResponseException e) {
  System.err.println("There was a service error: "
      + e.getDetails().getCode() + " : "
      + e.getDetails().getMessage());
}


/*
 * The results of the create method are stored in the response object.
 * The following code shows how to access the created id and fingerprint.
 */
System.out.println("Compiler Error = " + response.getCompilerError());
ContainerVersion version = response.getContainerVersion();
if (version != null) {
  System.out.println("Container Version Id = "
      + version.getContainerVersionId());
  System.out.println("Container Version Fingerprint = "
      + version.getFingerprint());
}

Python

Uses the Python client library.

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

# This request creates a new container version.
try:
  response = tagmanager.accounts().containers().versions().create(
      accountId='123456',
      containerId='54321',
      body={
          'name': 'Container Version',
          'notes': 'Sample Container Version',
          'quickPreview': True
      }
  ).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 create method are stored in response object.
# The following code shows how to access the created id and fingerprint.
version = response.get('containerVersion', {})
print 'Container Version Id = %s' % version.get('containerVersionId')
print 'Container Version Fingerprint = %s' % version.get('fingerprint')

Try it!

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