phpbing-ads-api

There was an error while trying to deserialize parameter AdPerformanceReportColumn::AdTitle in PHP microsoft/bingads


The package I am using: microsoft/bingads

I am trying to get a report of all my ads in a report, so I am using AdPerformanceReportRequest. In the report columns, I want to include AdPerformanceReportColumn::AdTitle, but it seems to be getting an exception and not sure what to not get the deserialize error.

This is the error I am getting:

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter
https://bingads.microsoft.com/Reporting/v13:ReportRequest. The InnerException message was 'Invalid enum value 'AdTitle' cannot be deserialized into type
'Microsoft.AdCenter.Advertiser.Reporting.Api.DataContracts.Enum.CampaignPerformanceReportColumn'. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.'. Please see InnerException for more details.

The code snippet of how I have it setup.

$report = new AdPerformanceReportRequest();
$report->ReportName = 'Ad Performance Report';
$report->Format = ReportFormat::Csv;
$report->ReturnOnlyCompleteData = false;
$report->Aggregation = ReportAggregation::Monthly;

$report->Scope = new AccountThroughAdGroupReportScope();
$account = [XXXXX, YYYYY, ZZZZZ];
$report->Scope->AccountIds = $accounts;

$report->Time = new ReportTime();
$report->Time->PredefinedTime = ReportTimePeriod::ThisMonth;

// choose columns
$report->Columns = [
    AdPerformanceReportColumn::AccountName,
    AdPerformanceReportColumn::AccountId,
    AdPerformanceReportColumn::CampaignId,
    AdPerformanceReportColumn::CampaignName,
    AdPerformanceReportColumn::AdTitle
];

try {
    // setup service client
    $serviceClient = (new ServiceClient(ServiceClientType::ReportingVersion13, $this->authorizationData, ApiEnvironment::Production));

    $encodedReport = new SoapVar($report, SOAP_ENC_OBJECT, 'CampaignPerformanceReportRequest', $serviceClient->GetNamespace());

    $request = new SubmitGenerateReportRequest();
    $request->ReportRequest = $encodedReport;

    $reportRequestId = $serviceClient->GetService()->submitGenerateReport($request)->ReportRequestId;

    return $reportRequestId;
}
  1. I looked over BingAds API documentation and there is AdTitle (https://learn.microsoft.com/en-us/advertising/reporting-service/adperformancereportcolumn?view=bingads-13)
  2. I tried removing everything except AdTitle, but that didn't really work either.

What am I missing that it keeps giving me the deserialize error?


Solution

  • I found the issue, I forgot to replace CampaignPerformanceReportRequest with AdPerformanceReportRequest