Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createProperty Analytics example is inaccurate, plus possibly a bug #6561

Closed
YWPZak opened this issue Aug 15, 2023 · 1 comment
Closed

createProperty Analytics example is inaccurate, plus possibly a bug #6561

YWPZak opened this issue Aug 15, 2023 · 1 comment
Assignees

Comments

@YWPZak
Copy link

YWPZak commented Aug 15, 2023

When viewing this example:

https://github.com/googleapis/google-cloud-php/blob/main/AnalyticsAdmin/samples/V1alpha/AnalyticsAdminServiceClient/create_property.php

Per the example: $response = $analyticsAdminServiceClient->createProperty($property);

The only parameter passed is $property, within the createProperty() function. There need to be two arguments, the Parent's accountName and the $property Object/Array. Otherwise you end up with :

An error occurred: {
    "message": "The value for the 'parent' field was invalid but must be in format 'accounts\/123'.",
    "code": 3,
    "status": "INVALID_ARGUMENT",
    "details": []
}

If you pass the parent AND $property --> createProperty('accounts/123456789', $property); You get the following error:

Uncaught TypeError: Google\Analytics\Admin\V1alpha\Gapic\AnalyticsAdminServiceGapicClient::createProperty(): 
    Argument #2 ($optionalArgs) must be of type array, Google\Analytics\Admin\V1alpha\Property given

I have also tried to pass $property by doing the following:

    $property = new Property([
        'display_name' => 'Zaks Test GA4 Property',
        'time_zone' => 'America/Chicago'
    ]);

Based on the error, I even thought ... hmmm ... Maybe if I create a raw array Like so

 $property = [
        'display_name' => 'Zaks Test GA4 Property',
        'time_zone' => 'America/Chicago'
    ];

To no avail. Then we just get:

An error occurred: Expect Google\Analytics\Admin\V1alpha\Property.

So which is it? Does it need argument #2 to be of type array(), or does it need to be Google\Analytics\Admin\V1alpha\Property?

Please update the example with the correct format in creating an Analytics property, or explain why what I am doing is incorrect, when I am trying to follow the example verbatim.

@ajupazhamayil
Copy link
Contributor

I see the property type is not array, it is of type Google\Analytics\Admin\V1alpha\Property. Please see here: https://github.com/googleapis/google-cloud-php/blob/72417b6d0789f892b3fa8a6fea503747db950b52/AnalyticsAdmin/samples/V1alpha/AnalyticsAdminServiceClient/create_property.php#L51C1-L54C42

Hence, the parent can be set by setParent function like this:

    $property = (new Property())
        ->setDisplayName($propertyDisplayName)
        ->setTimeZone($propertyTimeZone)
        ->setParent('accounts/101');

Hope this helps, please let me know if not. Thank you!

@ajupazhamayil ajupazhamayil self-assigned this Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants