PHPackages                             bim/bing-ads-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. bim/bing-ads-sdk

ActiveLibrary[API Development](/categories/api)

bim/bing-ads-sdk
================

An alternate Bing Ads SDK

v13.3.0(4y ago)035MITPHPPHP ^7.4

Since Apr 29Pushed 4y ago1 watchersCompare

[ Source](https://github.com/kirill533/bing-ads-sdk)[ Packagist](https://packagist.org/packages/bim/bing-ads-sdk)[ RSS](/packages/bim-bing-ads-sdk/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (6)Used By (0)

Bing Ads SDK for PHP
====================

[](#bing-ads-sdk-for-php)

This is an alternative to the [official Bing Ads PHP SDK](https://github.com/BingAds/BingAds-PHP-SDK).

It's heavily inspired by [Google AdWords PHP SDK](https://github.com/googleads/googleads-php-lib)and has some things the official Bing SDK is missing:

1. No `SoapVar` required
2. Automatic access token refreshes

It leverages [`league/oauth2-client`](http://oauth2-client.thephpleague.com/) to deal with the oauth flow.

Core Concepts
-------------

[](#core-concepts)

- A *session* objects acts as a contain for all pre-request configuration (oauth creds, developer token, api environment, etc).
- A *service* is instantiated with a session and extends `SoapClient`. Services are used to make the actual requests to the API.

Usage Example
-------------

[](#usage-example)

```
use PMG\BingAds\BingSession;
use PMG\BingAds\BingServices;
use PMG\BingAds\CustomerManagement as cm;

$session = BingSession::builder()
    ->withEnvironment(BingSession::PROD) // or use BingSession::SANDBOX
    ->withOAuthClientId('changeme')
    ->withOAuthClientSecret('changeme')
    ->withOAuthRedirectUri('https://yourapp.com/oauth/microsoft')
    ->withRefreshToken('someRefreshToken')
    ->withDeveloperToken('someDeveloperToken')
    ->build()
    ;

$services = new BingServices();

$service = $services->create(cm\CustomerManagementService::class, $session);

$response = $service->getCustomersInfo(new cm\GetCustomersInfoRequest('a', 10));
print_r($response);
```

Error Handling
--------------

[](#error-handling)

If a soap fault occurs, it will be wrapped up in `PMG\BingAds\Exception\ApiException`. This exception *may* be specific to a service or it may be the generic `PMG\BingAds\Exception\SoapFault`.

To see the actual HTTP requests and response, set `trace` to true in the soap client options.

```
use PMG\BingAds\BingSession;
use PMG\BingAds\BingServices;
use PMG\BingAds\CustomerManagement as cm;

$session = BingSession::builder()
    /* build a session as above */
    ->build()
    ;

$services = new BingServices();

$service = $services->create(cm\CustomerManagementService::class, $session, [
    'trace' => true,
]);

try {
    $response = $service->getCustomersInfo(new cm\GetCustomersInfoRequest('a', 10));
} catch (cm\ApplicationFault $fault) {
    echo $fault->getTrackingId(), PHP_EOL; // a UUID to help the bing team debug

    /** @var Psr\Http\Message\RequestInterface $request */
    $request = $fault->getRequest();
    if ($request) {
        // request will be there if `trace => true` otherwise this will be null
        // show the SOAP XML request. The credentials here (access token,
        // developer token) will be redacted
        echo $request->getBody(), PHP_EOL;
    }

    /** @var Psr\Http\Message\ResponseInterface $response */
    $response = $fault->getResponse();
    if ($response) {
        // respone will be there if `trace => true` otherwise it's null
        // display the SOAP XML response
        echo $response->getBody(), PHP_EOL;
    }

    // show actual errors
    if ($fault instanceof cm\ApiFault) {
        print_r($fault->getOperationErrors());
    } elseif ($fault instanceof cm\AdApiFault) {
        print_r($fault->getErrors());
    }
}
```

Alternatively, each service provides a `lastRequest` and `lastResponse` method to view the HTTP requests/responses.

```
use PMG\BingAds\BingSession;
use PMG\BingAds\BingServices;
use PMG\BingAds\CustomerManagement as cm;

$session = BingSession::builder()
    /* build a session as above */
    ->build()
    ;

$services = new BingServices();

$service = $services->create(cm\CustomerManagementService::class, $session, [
    'trace' => true,
]);

$response = $service->getCustomersInfo(new cm\GetCustomersInfoRequest('a', 10));

print_r($service->lastRequest());
print_r($service->lastResponse());
```

Authentication
--------------

[](#authentication)

See [examples/auth](examples/auth) for an example.

Instantiate a `PMG\BingAds\Auth\MicrosoftProvider` and use it like any other [`oauth2-client` provider](http://oauth2-client.thephpleague.com/usage/).

```
use PMG\BingAds\Auth\MicrosoftProvider;

$provider = MicrosoftProvider::production([
    'clientId' => 'changeme',
    'clientSecret' => 'changeme',
    'redirectUri' => 'https://youramp.com/oauth/microsft',
]);

// get an authorization URL
$authurl = $provider->getAuthorizationUrl(['prompt' => 'login']);
// may want to $pvodier->getState() to save the state some place

// exchange a `code` for an access token
$token = $provider->getAccessToken('authorization_code', [
    'code' => $_GET['code'],
]);
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

5

Last Release

1464d ago

Major Versions

v12.0.0 → v13.0.02022-04-29

PHP version history (2 changes)v12.0.0PHP ~7.2

v13.1.0PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/700ac7b222a8c9d077e94925919a89627c435062043c199fa64dd74f7dc533c2?d=identicon)[bim](/maintainers/bim)

---

Top Contributors

[![chrisguitarguy](https://avatars.githubusercontent.com/u/1010392?v=4)](https://github.com/chrisguitarguy "chrisguitarguy (86 commits)")[![kirill533](https://avatars.githubusercontent.com/u/6292292?v=4)](https://github.com/kirill533 "kirill533 (3 commits)")[![ahuggins](https://avatars.githubusercontent.com/u/1791228?v=4)](https://github.com/ahuggins "ahuggins (2 commits)")

---

Tags

bing

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bim-bing-ads-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/bim-bing-ads-sdk/health.svg)](https://phpackages.com/packages/bim-bing-ads-sdk)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[saloonphp/saloon

Build beautiful API integrations and SDKs with Saloon

2.4k9.6M468](/packages/saloonphp-saloon)[irazasyed/telegram-bot-sdk

The Unofficial Telegram Bot API PHP SDK

3.3k4.5M84](/packages/irazasyed-telegram-bot-sdk)[algolia/algoliasearch-client-php

API powering the features of Algolia.

69333.0M114](/packages/algolia-algoliasearch-client-php)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[php-heroku-client/php-heroku-client

A PHP client for the Heroku Platform API

24404.8k4](/packages/php-heroku-client-php-heroku-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
