BingAds / BingAds-PHP-SDK

Other
56 stars 45 forks source link

AdPerformanceReportRequest Error #190

Closed BryanYeh closed 1 year ago

BryanYeh commented 1 year ago

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 do.

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 it's 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
];
BryanYeh commented 1 year ago

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

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;

            Log::info('got a report id: ' . $reportRequestId);

            return $reportRequestId;
        }