I am working with the Google Cloud PHP API. I am hooked up and everything works great when pulling admin info like accounts and properties.
I am trying to create a basic property within an account using the API. I am running across either a bug, or I am missing something glaring. The example I am using is HERE and this is the code I am attempting to use:
function createNewProperty($accountName){
echo "Account Name: $accountName \n\n"; // accounts/123456789
$client = new AnalyticsAdminServiceClient();
echo "Create Property \n\n";
$property = ( new Property() )
->setDisplayName("Zaks Test GA4 Property")
->setTimeZone('America/Chicago');
try {
$createdProperty = $client->createProperty($accountName, $property);
echo 'Property created: ' . "\n"; // . $createdProperty->getName();
print_r( $createdProperty );
} catch (\Exception $e) {
echo 'An error occurred: ' . $e->getMessage() . "\n";
}
}
And I call it simply by:
$createAccountName = 'accounts/123456789';
createNewProperty($createAccountName);
I feel I am following the EXAMPLE verbatim. But I get:
Account Name: accounts/123456789
Create Property
PHP Fatal error: Uncaught TypeError: Google\Analytics\Admin\V1alpha\Gapic\AnalyticsAdminServiceGapicClient::createProperty(): Argument #2 ($optionalArgs) must be of type array, Google\Analytics\Admin\V1alpha\Property given, called in /var/www/GA/GA4/test.php on line 75 and defined in /var/www/GA/GA4/vendor/google/analytics-admin/src/V1alpha/Gapic/AnalyticsAdminServiceGapicClient.php:2618
Stack trace:
#0 /var/www/GA/GA4/test.php(75): Google\Analytics\Admin\V1alpha\Gapic\AnalyticsAdminServiceGapicClient->createProperty()
#1 /var/www/GA/GA4/test.php(32): createNewProperty()
#2 {main}
thrown in /var/www/GA/GA4/vendor/google/analytics-admin/src/V1alpha/Gapic/AnalyticsAdminServiceGapicClient.php on line 2618
Obviously this part:
Argument #2 ($optionalArgs) must be of type array, Google\Analytics\Admin\V1alpha\Property given
is the $property
argument that I am passing through to the function $client->createProperty($accountName, $property);
I have also seen it done this way:
$property = new Property([
'display_name' => 'Zaks Test GA4 Property',
'time_zone' => 'America/Chicago'
]);
So me being me .. I am like hmm .. Arg #2 needs to be an array. OK I'll make it an array. I do the following:
$property = [
'display_name' => 'Zaks Test GA4 Property',
'time_zone' => 'America/Chicago'
];
But I get a different error.
An error occurred: Expect Google\Analytics\Admin\V1alpha\Property.
Which is it? Is argument #2 supposed to be an array? Or is it supposed to be a Google/.../Property
?
Is this a bug in the API or am I doing something wrong?