Update an existing account budget

86 views
Skip to first unread message

Алексей Рябиков

unread,
Feb 10, 2023, 12:10:08 PM2/10/23
to Google Ads API and AdWords API Forum
Hi! 

I've tried to make a script that update existing account budget and, it seems, that does not work. 
Can you help me please, what could be wrong?

My code is based on:
1) Add budget proposal example from library

Logger is enabled (and logging examples from library), but, unfortunately, not this script. Idk why. 

Full code:


<?php


namespace Google\Ads\GoogleAds\Examples\Billing;

require __DIR__ . '/../../vendor/autoload.php';

use GetOpt\GetOpt;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentNames;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentParser;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsException;
use Google\Ads\GoogleAds\Util\V12\ResourceNames;
use Google\Ads\GoogleAds\V12\Enums\AccountBudgetProposalTypeEnum\AccountBudgetProposalType;
use Google\Ads\GoogleAds\V12\Enums\TimeTypeEnum\TimeType;
use Google\Ads\GoogleAds\V12\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V12\Resources\AccountBudgetProposal;
use Google\Ads\GoogleAds\V12\Services\AccountBudgetProposalOperation;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;
use Google\Ads\GoogleAds\Util\FieldMasks;



class AddAccountBudgetProposal
{
    private const CUSTOMER_ID = '3721199407';
    //private const BILLING_SETUP_ID = 'INSERT_BILLING_SETUP_ID_HERE';

    public static function main()
    {
        // Either pass the required parameters for this example on the command line, or insert them
        // into the constants above.
        $options = (new ArgumentParser())->parseCommandArguments([
            ArgumentNames::CUSTOMER_ID => GetOpt::REQUIRED_ARGUMENT,
            //ArgumentNames::BILLING_SETUP_ID => GetOpt::REQUIRED_ARGUMENT
        ]);

        // Generate a refreshable OAuth2 credential for authentication.
        $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()->build();

        // Construct a Google Ads client configured from a properties file and the
        // OAuth2 credentials above.
        $googleAdsClient = (new GoogleAdsClientBuilder())->fromFile()
            ->withOAuth2Credential($oAuth2Credential)
            ->build();

        try {
            self::runExample(
                $googleAdsClient,
                $options[ArgumentNames::CUSTOMER_ID] ?: self::CUSTOMER_ID,
                //$options[ArgumentNames::BILLING_SETUP_ID] ?: self::BILLING_SETUP_ID
            );
        } catch (GoogleAdsException $googleAdsException) {
            printf(
                "Request with ID '%s' has failed.%sGoogle Ads failure details:%s",
                $googleAdsException->getRequestId(),
                PHP_EOL,
                PHP_EOL
            );
            foreach ($googleAdsException->getGoogleAdsFailure()->getErrors() as $error) {
               
                printf(
                    "\t%s: %s%s",
                    $error->getErrorCode()->getErrorCode(),
                    $error->getMessage(),
                    PHP_EOL
                );
            }
            exit(1);
        } catch (ApiException $apiException) {
            printf(
                "ApiException was thrown with message '%s'.%s",
                $apiException->getMessage(),
                PHP_EOL
            );
            exit(1);
        }
    }


    public static function runExample(
        GoogleAdsClient $googleAdsClient,
        int $customerId

    ) {

//Update budget proposal
$accountBudget = 'customers/3721199407/accountBudgets/6885650342';
$increaseAmount = 500000000;
$accountBudgetProposal = new AccountBudgetProposal([
  'proposal_type' => AccountBudgetProposalType::UPDATE,
  'account_budget' => $accountBudget,
  'proposed_spending_limit_micros' =>
   $increaseAmount]);

$accountBudgetProposalOperation = new AccountBudgetProposalOperation();
$accountBudgetProposalOperation->setCreate($accountBudgetProposal);
$accountBudgetProposalOperation->setUpdateMask(
  FieldMasks::allSetFieldsOf($accountBudgetProposal)
);

    }

}

AddAccountBudgetProposal::main();

?>


Pray for your help :)

Google Ads API Forum Advisor

unread,
Feb 13, 2023, 1:25:35 AM2/13/23
to house...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for reaching us out. I am Sherwin from Google Ads API support team. I hope that you are doing well today.

Moving forward to your concern, I can see that you created two threads with the same concern. Please refrain from creating two threads with the same concern to avoid confusion. With this, we highly suggest you to reply to the email where my colleague Carmela and Jinky replied.

Kind regards,
Google Logo
Sherwin Vincent
Google Ads API Team
 


ref:_00D1U1174p._5004Q2iykHj:ref
Reply all
Reply to author
Forward
0 new messages