Container Versions: create

Memerlukan otorisasi

Membuat versi penampung. Coba sekarang atau lihat contohnya.

Permintaan

Permintaan HTTP

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

Parameter

Nama parameter Nilai Deskripsi
Parameter jalur
accountId string ID Akun GTM.
containerId string ID Penampung GTM.

Otorisasi

Permintaan ini memerlukan otorisasi dengan cakupan berikut (baca selengkapnya tentang autentikasi dan otorisasi).

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

Isi permintaan

Dalam isi permintaan, berikan data dengan struktur berikut:

{
  "quickPreview": boolean,
  "name": string,
  "notes": string
}
Nama properti Nilai Deskripsi Catatan
quickPreview boolean Pembuatan versi ini mungkin dilakukan sebagai pratinjau cepat dan tidak boleh disimpan.
name string Nama versi penampung yang akan dibuat.
notes string Catatan versi penampung yang akan dibuat.

Respons

Jika berhasil, metode ini akan menampilkan isi respons dengan struktur berikut:

{
  "containerVersion": accounts.containers.versions Resource,
  "compilerError": boolean
}
Nama properti Nilai Deskripsi Catatan
containerVersion nested object Versi penampung dibuat.
compilerError boolean Error compiler atau tidak.

Contoh

Catatan: Contoh kode yang tersedia untuk metode ini tidak merepresentasikan semua bahasa pemrograman yang didukung (lihat halaman library klien untuk mengetahui daftar bahasa yang didukung).

Java

Menggunakan library klien Java.

/*
 * 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

Menggunakan library klien Python.

# 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')

Cobalah!

Gunakan APIs Explorer di bawah untuk memanggil metode ini pada data live dan melihat respons.