How do I retrieve campaign clicks using REST API in PHP? RRS feed

  • Question

  • Hello. 

    I have just started with Bing Ads API. 


    PHP Laravel Framework


    I am trying to retrieve campaign clicks, impressions, assists, revenue, spend. manual call, etc. 

    1. How do I retrieve the data using REST API call?

    2. How do I retrieve the data in JSON format?

    3. Can I use CURL while retrieving the data?

    4. Where do I get some examples?

    I am looking for an easiest solution ASAP. Please help.



    Tuesday, April 14, 2020 7:10 PM

All replies

  • There isn't a REST API available, but to get started using Bing Ads API with PHP I suggest this guide

    Then you can modify ReportRequests.php as needed and run in place of SearchAccounts.php. 

    Please reach out if you have any follow up questions. 


    Saturday, April 18, 2020 5:54 PM
  • Hi Eric. 

    Thanks for the reply. URL you have referred is for desktop application. I want to use it in PHP web application. If there is no REST is available, then how do I retrieve the data. I wish to retrieve the data of account details, plus, the campaign metrics such as Clicks, Client Cost, Conversions, Impress, Revenue, Spent, Total Visits, etc. 

    What is current process is called? Is it called SOAP? Can I get data in JSON format? Is there any alternative library in Git/Packagist that can help me to retrieve these metrices?

    I am waiting for your feedback and reply. 

    Regards & Thanks, 


    Tuesday, May 12, 2020 4:38 PM
  • Yes the reports can be downloaded via SOAP operations i.e., SubmitGenerateReport and PollGenerateReport. Then you can download from the provisioned URL and extract/parse the report data. Here is a PHP example:

    Please let me know if you have any other questions. 

    Best regards,


    Wednesday, May 13, 2020 1:17 PM
  • Can you please clear my below doubts?

    1. How do I get all the campaigns under an account id?

    2. How do I get performance and statistics of a campaign using campaign id?

    Regards & Thanks,


    Thursday, May 14, 2020 6:33 PM
  • Hi Eric.

    Thanks for the reply so far. 

    I am trying to retrieve campaigns id and name by account id. I have got the error. I have written the below code. 


    Fatal error: Uncaught Error: Class 'BingAds\GetCampaignsByAccountIdRequest' not found in E:\wamp64\www\bingads\test.php on line 136
    Error: Class 'BingAds\GetCampaignsByAccountIdRequest' not found in E:\wamp64\www\bingads\test.php on line 136


    $GLOBALS['CustomerManagementProxy'] = new ServiceClient(

    // Set the GetUser request parameter to an empty user identifier to get the current 
    // authenticated Microsoft Advertising user, and then search for all accounts the user can access.

    $getUserRequest = new GetUserRequest();
    $getUserRequest->UserId = null;

    $user = $GLOBALS['CustomerManagementProxy']->GetService()->GetUser($getUserRequest)->User;

    // Search for the Microsoft Advertising accounts that the user can access.
    $pageInfo = new Paging();
    $pageInfo->Index = 0;    // The first page
    $pageInfo->Size = 1000;   // The first 1,000 accounts for this page of results    
    $predicate = new Predicate();
    $predicate->Field = "UserId";
    $predicate->Operator = PredicateOperator::Equals;
    $predicate->Value = $user->Id; 

    $searchAccountsRequest = new SearchAccountsRequest();
    $searchAccountsRequest->Predicates = array($predicate);
    $searchAccountsRequest->Ordering = null;
    $searchAccountsRequest->PageInfo = $pageInfo;

    $accounts = $GLOBALS['CustomerManagementProxy']->GetService()->SearchAccounts($searchAccountsRequest)->Accounts;

    foreach ($accounts->AdvertiserAccount as $account) {

         $GLOBALS['CampaignManagementProxy'] = new ServiceClient(

         $request = new GetCampaignsByAccountIdRequest();
         $request->AccountId = $account->Id;
         $request->CampaignType = 'Search';

         $campaigns = $GLOBALS['CampaignManagementProxy']->GetService()->GetCampaignsByAccountId($request)->Campaigns; // Error line number. 


    Please help me to resolve the issue. 

    Regards & Thanks,


    Friday, May 15, 2020 7:10 PM
  • Here's an example call to GetCampaignsByAccountId, although it uses the sample helper classes.

    The helper uses "Microsoft\BingAds\V13\CampaignManagement\GetCampaignsByAccountIdRequest" here:

    Does this help?



    Saturday, May 16, 2020 1:45 PM