yooouuri
yooouuri

Reputation: 2658

Get campaign and budget

$campaignId = 123456789;

$selector = new Selector();
$selector->setFields([
    'Id',
    'Name',
    'Status',
    'BudgetId',
]);
$selector->setPredicates([
    new Predicate('Id', PredicateOperator::EQUALS, [$campaignId])
]);

This gives me the following result (i am using Laravel):

array:1 [▼
  0 => Campaign {#244 ▼
    #id: 123456789
    #name: "Test campagne"
    #status: "PAUSED"
    #servingStatus: null
    #startDate: null
    #endDate: null
    #budget: Budget {#241 ▼
      #budgetId: 123456789
      #name: null
      #amount: null
      #deliveryMethod: null
      #referenceCount: null
      #isExplicitlyShared: null
      #status: null
    }
    #conversionOptimizerEligibility: null
    #adServingOptimizationStatus: null
    #frequencyCap: null
    #settings: null
    #advertisingChannelType: null
    #advertisingChannelSubType: null
    #networkSetting: null
    #labels: null
    #biddingStrategyConfiguration: null
    #campaignTrialType: null
    #baseCampaignId: null
    #forwardCompatibilityMap: null
    #trackingUrlTemplate: null
    #urlCustomParameters: null
    #vanityPharma: null
    #selectiveOptimization: null
  }
]

When i add 'Budget' to the setFields array, the following error occur

[SelectorError.INVALID_FIELD_NAME @ serviceSelector; trigger:'Budget']

Do i need the BudgetService to retrieve information about the budget?

Upvotes: 2

Views: 862

Answers (2)

AnhellO
AnhellO

Reputation: 1059

Just to complement the previous answers, I think you are looking at the wrong way to get the budget for a campaign. If you want to get that stat, and any other stats, you should give a look to the reporting part of the API. See this question: Getting campaign stats (e.g. Clicks, CTR, CPC, etc.) via AdWords API.

Once you have the reporting API working fine, the report you should look for is the CAMPAIGN_PERFORMANCE_REPORT:

After this, if you are successfully pulling the data for that report, you should specify the Amount field (as pointed out by @fabrigm), which is the field you are looking for.

Yes, you can use the services part of the API, but things get more complex and you have to do more API calls. The services part of the API is more intended for create/update/delete rather than simple stats read calls.

Finally, if you are using the API, I'd suggest you to give a look to these packages, they might make your implementation easier:

Upvotes: 0

Marcel Bezerra
Marcel Bezerra

Reputation: 179

Select the budget fields that you want to use on your script. The field names are like the reports query.

$campaignId = 123456789;

$selector = new Selector();
$selector->setFields([
    'Id',
    'Name',
    'Status',
    'BudgetId',
    'BudgetName',
    'Amount',
    'DeliveryMethod',
    'BudgetReferenceCount',
    'IsBudgetExplicitlyShared',
    'BudgetStatus'
]);

$selector->setPredicates([
    new Predicate('Id', PredicateOperator::EQUALS, [$campaignId])
]);

Upvotes: 1

Related Questions