How to add device(desktop,mobile,tablet) bid modifiers at campaign level in Ads API Beta

108 views
Skip to first unread message

Christoph Lanz

unread,
Mar 20, 2019, 5:49:08 AM3/20/19
to AdWords API and Google Ads API Forum
Hello,

I am trying to create a mobile and tablet bid modifier at campaign level, using the new Ads API Beta. I used the example "AddAdGroupBidModifier.php" from the examples library and tried to modify it to do the same function at campaign level, but I receive an error message. 

Does anyone know how to solve this? Or is there any further documentation or an example to see how to build the request?

Many thanks in advance,

Christoph


This is part of my code where I define the request: (Full code in the attachment)

        $CampaignBidModifier = new CampaignBidModifier([
            'campaign' => new StringValue(
                ['value' => ResourceNames::forCampaign($customerId, $CampaignId)]
            ),
            'bid_modifier' => new DoubleValue(['value' => $bidModifierValue]),
            'device' => new DeviceInfo(['type' => Device::MOBILE])
        ]);



This is the error that I get:

Fatal error: Uncaught UnexpectedValueException: Invalid message property: device in /www/htdocs/w01745db/api.thegoodtraffic.com/google-ads-php-master/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php:992 Stack trace: #0 /www/htdocs/w01745db/api.thegoodtraffic.com/google-ads-php-master/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php(79): Google\Protobuf\Internal\Message->mergeFromArray(Array) #1 /www/htdocs/w01745db/api.thegoodtraffic.com/google-ads-php-master/src/Google/Ads/GoogleAds/V0/Resources/CampaignBidModifier.php(70): Google\Protobuf\Internal\Message->__construct(Array) #2 /www/htdocs/w01745db/api.thegoodtraffic.com/google-ads-php-master/api/management/AddCampaignBidModifier.php(122): Google\Ads\GoogleAds\V0\Resources\CampaignBidModifier->__construct(Array) #3 /www/htdocs/w01745db/api.thegoodtraffic.com/google-ads-php-master/api/management/AddCampaignBidModifier.php(74): Google\Ads\GoogleAds\Management\AddCampaignBidModifier::runExample(Object(Google\Ads\GoogleAds\Lib\GoogleAdsClient), in /www/htdocs/w01745db/api.thegoodtraffic.com/google-ads-php-master/vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php on line 992
AddCampaignBidModifier.php

googleadsapi...@google.com

unread,
Mar 20, 2019, 11:52:06 AM3/20/19
to thegood...@gmail.com, AdWords API and Google Ads API Forum
Hello Christoph,

The only criteria type you can adjust bid modifiers for using CampaignBidModifierService are CALLS. If you want to adjust device bid modifiers, you will need to use the CampaignCriterionService to adjust the CampaignCriterion.

Regards,
Anthony
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/abb48e4b-49ef-49d0-9be5-5142f80583ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christoph Lanz

unread,
Mar 21, 2019, 7:57:52 AM3/21/19
to AdWords API and Google Ads API Forum
Hello Anthony,

Many thanks for your reply!

As you suggested I tried to use the CampaignCriterionService, and have the following code. It gives me an error message "Resource_Name_Missing", but I am unsure how to add this parameter. I tried to include it in several ways but was not successful. Maybe you can help me out?

Again, many thanks for your help!

Kind regards,

Christoph

    private static function createDeviceCampaignCriterionOperation(
        $languageId,
        $campaignResourceName
    ) {
        $campaignCriterion = new CampaignCriterion([
            'campaign' => new StringValue(['value' => $campaignResourceName]),
            'device' => new DeviceInfo (['type' => Device::MOBILE]),
'bid_modifier' => new FloatValue(['value' => '2'])
]);
        return new CampaignCriterionOperation(['update' => $campaignCriterion]);
    }


Error Message:
ApiException was thrown with message '{ "message": "Request contains an invalid argument.", "code": 3, "status": "INVALID_ARGUMENT", "details": [ { "@type": 0, "data": "type.googleapis.com\/google.ads.googleads.v0.errors.GoogleAdsFailure" }, { "@type": 0, "data": [ { "errorCode": { "requestError": "RESOURCE_NAME_MISSING" }, "message": "Resource name is missing.", "location": { "fieldPathElements": [ { "fieldName": "operations", "index": "0" }, { "fieldName": "update" }, { "fieldName": "resource_name" } ] } } ] } ] }'. 

googleadsapi...@google.com

unread,
Mar 21, 2019, 1:51:55 PM3/21/19
to thegood...@gmail.com, AdWords API and Google Ads API Forum
Hi Christoph,

Please have a look at this example. It shows how to update a keyword which you can use a reference on how to define the resource name.

Regards,
Anthony
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Christoph Lanz

unread,
Mar 22, 2019, 6:11:49 AM3/22/19
to AdWords API and Google Ads API Forum
Hi Anthony,

Awesome, this example helped me to create a working Device Bid Modifier at campaign level. I attach the working code in case someone else finds it useful.
Many thanks for your help and have a nice day!

Kind regards,

Christoph
UpdateDeviceBidModifiers.php
Reply all
Reply to author
Forward
0 new messages