Closed psociety closed 10 months ago
I copied your code exactly, and was able to run the API without any issues. After creating a Workspace in the Tag Manager UI and copying the workspace path into the $path
variable below (and copying your template data into template.tpl
), I ran the following script:
require 'vendor/autoload.php';
$client = new Google\Client();
$client->setScopes([
'https://www.googleapis.com/auth/tagmanager.edit.containers',
]);
$client->useApplicationDefaultCredentials();
$service = new Google\Service\TagManager($client);
$path = 'accounts/MY_ACCOUNT_ID/containers/MY_CONTAINER_ID/workspaces/2';
$template = new Google\Service\TagManager\CustomTemplate();
$template->setName("google_api_rocks");
$template->setTemplateData(file_get_contents(__DIR__ . '/template.tpl'));
$results = $service->accounts_containers_workspaces_templates->create($path, $template);
This resulted in the template being created in the workspace as expected:
I agree the error message from the API is not very helpful, but that is not the fault of this client library, but rather the API itself, so there's nothing I can do to help you. Good luck!
When i try to create a template in GTM v2 i get the following error:
How I am expected to fix the error if no proper error message is returned?
Used code:
Template data: