I am trying to get ads metrics through microsoft ads api, such as costs, impressions, clicks, and more. I am not used to using SOAP APIs, but I haven't found any documentations other then the api SDK and SOAP.
I was able to get my User info through the SOAP api, the campaigns of the customer account and the ad groups, because I understand that I need the campaign ids and the adgroups ids, right?
Okay, to get the metrics that I want, I found the SubmitGenerateReport and PollGenerateReport operations, and since I want daily metrics per ads, I think the best report for me is the AdPerformanceReportRequest.
Now let's get to the point where I'm stuck. When I call the SubmitGenerateReport operation, I am getting as response this error:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode>s:Server</faultcode>
<faultstring>Invalid client data. Check the SOAP fault details for more information. TrackingId: 0182f18c-cad8-4497-8e81-9a63f6f42055.</faultstring>
<detail>
<ApiFaultDetail xmlns="https://bingads.microsoft.com/Reporting/v13" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<TrackingId xmlns="https://adapi.microsoft.com">0182f18c-cad8-4497-8e81-9a63f6f42055</TrackingId>
<BatchErrors/>
<OperationErrors>
<OperationError>
<Code>2015</Code>
<Details>No Dimension selected.</Details>
<ErrorCode>RequiredColumnsNotSelected</ErrorCode>
<Message>The specified report request does not specify all the required columns for this report type. Please submit a report request with the required columns for this report type, and optionally additional columns that are to be included in the report.</Message>
</OperationError>
</OperationErrors>
</ApiFaultDetail>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
As you can see, I am unnable to see which column is missing through the response, and that's why I am here.
This is my request:
url: https://reporting.api.bingads.microsoft.com/Api/Advertiser/Reporting/v13/ReportingService.svc
headers:
Content-Type:text/xml
SOAPAction:SubmitGenerateReport
body:
<s:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header xmlns="https://bingads.microsoft.com/Reporting/v13">
<AuthenticationToken i:nil="false">$token</AuthenticationToken>
<CustomerAccountId i:nil="false">$accountId</CustomerAccountId>
<CustomerId i:nil="false">$customerId</CustomerId>
<DeveloperToken i:nil="false">$developerToken</DeveloperToken>
</s:Header>
<s:Body>
<SubmitGenerateReportRequest xmlns="https://bingads.microsoft.com/Reporting/v13">
<ReportRequest i:nil="false" i:type="AdPerformanceReportRequest">
<ExcludeColumnHeaders i:nil="false">false</ExcludeColumnHeaders>
<ExcludeReportFooter i:nil="false">false</ExcludeReportFooter>
<ExcludeReportHeader i:nil="false">false</ExcludeReportHeader>
<Format i:nil="false">Csv</Format>
<FormatVersion i:nil="false">2.0</FormatVersion>
<ReportName i:nil="false">Ad Report</ReportName>
<ReturnOnlyCompleteData i:nil="false">false</ReturnOnlyCompleteData>
<!--These fields are applicable if the derived type attribute is set to AdPerformanceReportRequest-->
<Aggregation>Daily</Aggregation>
<Columns i:nil="false">
<AdPerformanceReportColumn>Clicks</AdPerformanceReportColumn>
</Columns>
<Filter i:nil="false">
<AccountStatus i:nil="false">Active Paused Inactive</AccountStatus>
<AdDistribution i:nil="false">Search Audience</AdDistribution>
<AdGroupStatus i:nil="false">Active Deleted Expired Paused</AdGroupStatus>
<AdStatus i:nil="false">Active Rejected Deleted Pending Paused</AdStatus>
<AdType i:nil="false">AppInstall DynamicSearchAd ExpandedText Product ResponsiveAd ResponsiveSearchAd Text</AdType>
<CampaignStatus i:nil="false">Active BudgetPaused Deleted Paused Suspended</CampaignStatus>
<DeviceType i:nil="false">Computer NonSmartPhone SmartPhone Tablet</DeviceType>
<Language i:nil="false">Portuguese English</Language>
</Filter>
<Scope i:nil="false">
<AccountIds i:nil="false" xmlns:a1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a1:long>$accountId</a1:long>
</AccountIds>
<AdGroups i:nil="false">
<AdGroupReportScope>
<AccountId>$accountId</AccountId>
<CampaignId>518735525</CampaignId>
<AdGroupId>1323813659647082</AdGroupId>
</AdGroupReportScope>
</AdGroups>
<Campaigns i:nil="false">
<CampaignReportScope>
<AccountId>$accountId</AccountId>
<CampaignId>518735525</CampaignId>
</CampaignReportScope>
</Campaigns>
</Scope>
<Time i:nil="false">
<CustomDateRangeEnd i:nil="false">
<Day>30</Day>
<Month>05</Month>
<Year>2024</Year>
</CustomDateRangeEnd>
<CustomDateRangeStart i:nil="false">
<Day>01</Day>
<Month>01</Month>
<Year>2024</Year>
</CustomDateRangeStart>
<ReportTimeZone i:nil="false">Brasilia</ReportTimeZone>
</Time>
</ReportRequest>
</SubmitGenerateReportRequest>
</s:Body>
</s:Envelope>
I usually test the api endpoint through Postman and when I understand how it works I start coding the integration, so this is just me testing how the api works, does someone what I'm missing?
Okay, I have spoken to Microsoft Ads support, and this is the answer:
Since I'm using Daily Aggregation, there is a Column that is expected called "TimePeriod", and this is true for all aggregation types except Summary. as is described here
I have added the TimePeriod column and now I can submit a AdPerformanceReport!
Addind this column fix the error, and now I'm getting the id of the report as a response, YAY!
This answers my question, BUT, since I have to download the report now, I need to test that, and I did test it.
The result? I call PollGenerateReport request passing de id from the report that I just generated, and I get a url to download my report. Sadly, that's not the end of the story.
When I try to request the report with the url that was given to me, that looks like this: https://bingadsappsstorageprod.blob.core.windows.net/hpr-reportdataapi.../Ad_Report.zip?...
I am getting a <404 The specified resource does not exist.> error.
So, to get a valid download URL, you have to replace "amp;" with "" (empty), just like the example below:
Initial URL
https://bingadsappsstorageprod.blob.core.windows.net:443/hpr-reportdataapi-24-06-17/bb74e670-f6f3-4463-bdf4-57b89379d76d/Ad_Report.zip?sv=2018-03-28&sr=b&sig=R1npske0kxLK2S9s0FkfJkJ9PKRyCmN3LVyL6Birr0E%3D&st=2024-06-17T113A20%3A29Z&se=2024-06-17T11%3A353A29Z&sp=r
Download URL