James Mills
James Mills

Reputation: 554

Adwords PHP API withCondition not working

$user->LoadService("ReportDefinitionService");

$selector = new Selector();
$selector->fields = $report["fields"];
$selector->dateRange = new DateRange($api_date, $api_date);
$selector->withCondition = "Name STARTS_WITH 'CTC'";

$reportDefinition = new ReportDefinition();
$reportDefinition->reportName = 'my_made_up_name_' . time();
$reportDefinition->dateRangeType = "CUSTOM_DATE";
$reportDefinition->reportType = $report["type"];
$reportDefinition->downloadFormat = "GZIPPED_CSV";
$reportDefinition->selector = $selector;

I am trying to limit the campaigns that I get back in the report so that I only get those starting with 'CTC'.

$selector->withCondition = "Name STARTS_WITH 'CTC'";

I am not sure if I have the syntax wrong I am using this page as a reference https://developers.google.com/adwords/scripts/docs/reference/adwordsapp_campaignselector#withCondition_1

The error I am getting back is:

An error has occurred: Report download failed. Underlying errors are Type = 'ReportDownloadError.INVALID_REPORT_DEFINITION_XML', Trigger = 'Invalid ReportDefinition Xml: cvc-complex-type.2.4.a: Invalid content was found starting with element 'withCondition'. One of '{"https://adwords.google.com/api/adwords/cm/v201306":ordering, "https://adwords.google.com/api/adwords/cm/v201306":paging}' is expected.', FieldPath = ''.

Thanks in advance,

James

Upvotes: 0

Views: 553

Answers (1)

James Mills
James Mills

Reputation: 554

$selector = new Selector();
$selector->fields = $report["fields"];
$selector->dateRange = new DateRange($api_date, $api_date);
//$selector->withCondition = "Name STARTS_WITH 'CTC'";
$selector->predicates[] = new Predicate('CampaignName', 'STARTS_WITH', 'CTC');

Upvotes: 0

Related Questions