Get Started With the Bing Ads API

Any Bing Ads user with a developer token can begin using the Bing Ads API. For advertisers placing a large number of ads or developers building advertising tools, the Bing Ads API provides a programmatic interface to Bing Ads. You can write your Bing Ads application in any language that supports web services. To get started with a specific SDK, see Get Started in C# | Java | PHP | Python.

Get a Developer Token

To use Bing Ads APIs, you must have a developer token and valid user credentials. A developer token enables programmatic access to the accounts permitted for a user. Each provisioned user is assigned a role, for example Super Admin, and granted permissions to one or more accounts. The same accounts available in the Bing Ads web application are available to the corresponding user programmatically through the API. For more information see Account Permissions and the Developer Token.

The sandbox and production environments use separate credentials. You can sign up for a Sandbox account here. Everyone can use the universal sandbox developer token i.e., BBD37VB98.

Where to Use the API Credentials

When you call a service operation such as GetCampaignsByAccountId, you must specify request header elements such as DeveloperToken, CustomerId, and CustomerAccountId.

<s:Envelope xmlns:i="" xmlns:s="">
  <s:Header xmlns="">
    <Action mustUnderstand="1">GetCampaignsByAccountId</Action>
    <ApplicationToken i:nil="false">ValueHere</ApplicationToken>
    <AuthenticationToken i:nil="false">ValueHere</AuthenticationToken>
    <CustomerAccountId i:nil="false">ValueHere</CustomerAccountId>
    <CustomerId i:nil="false">ValueHere</CustomerId>
    <DeveloperToken i:nil="false">ValueHere</DeveloperToken>
    <Password i:nil="false">ValueHere</Password>
    <UserName i:nil="false">ValueHere</UserName>
    <GetCampaignsByAccountIdRequest xmlns="">

If you are using one of the Bing Ads SDKs, the request header elements are set using AuthorizationData. For more details about the SDK authentication library see Authentication With the SDKs.

var authorizationData = new AuthorizationData
    Authentication = <AuthenticationGoesHere>, 
    CustomerId = <CustomerIdGoesHere>,
    AccountId = <AccountIdGoesHere>,
    DeveloperToken = "<DeveloperTokenGoesHere>"
static AuthorizationData authorizationData = new AuthorizationData();
$authorizationData = (new AuthorizationData())
authorization_data = AuthorizationData(
    authentication = <AuthenticationGoesHere>,
    customer_id = <CustomerIdGoesHere>,
    account_id = <AccountIdGoesHere>,
    developer_token = '<DeveloperTokenGoesHere>'

Get Your Account and Customer Ids

To get a user's customer ID and account ID, you can sign in to the Bing Ads web application and click on the Campaigns tab. The URL will contain a cid key/value pair in the query string that identifies your customer ID, and an aid key/value pair that identifies your account ID. For example,

With the Customer Management API you can get the customer and account identifiers for each authenticated user.

Call GetUser with your Bing Ads credentials and DeveloperToken. Within the Body set the UserId nil. The response will include a User object that contains the UserId.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="">
    <h:ApplicationToken i:nil="true" xmlns:h="" xmlns:i="" />
    <h:AuthenticationToken xmlns:h="">OAuthAccessTokenGoesHere</h:AuthenticationToken>
    <h:DeveloperToken xmlns:h="">DeveloperTokenGoesHere</h:DeveloperToken>
    <h:Password i:nil="true" xmlns:h="" xmlns:i="" />
    <h:UserName i:nil="true" xmlns:h="" xmlns:i="" />
    <GetUserRequest xmlns="">
        <UserId i:nil="true" xmlns:i="" />

Then call SearchAccounts with the UserId returned via the previous step. The returned advertiser account (or accounts) will include account and customer identifiers.

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="">
    <h:ApplicationToken i:nil="true" xmlns:h="" xmlns:i="" />
    <h:AuthenticationToken xmlns:h="">OAuthAccessTokenGoesHere</h:AuthenticationToken>
    <h:DeveloperToken xmlns:h="">DeveloperTokenGoesHere</h:DeveloperToken>
    <h:Password i:nil="true" xmlns:h="" xmlns:i="" />
    <h:UserName i:nil="true" xmlns:h="" xmlns:i="" />
    <SearchAccountsRequest xmlns="">
        <Predicates xmlns:a="" xmlns:i="">
        <Ordering i:nil="true" xmlns:a="" xmlns:i="" />
        <PageInfo xmlns:a="" xmlns:i="">


See Search User Accounts Code Example for a code example that returns accounts for the current authenticated user.

Request Header Elements

Bing Ads services use Simple Object Access Protocol (SOAP) to exchange the request and response messages with the service operation. For more information, see Bing Ads Services Protocol.

Each SOAP request must include the following SOAP headers, which contain the user's credentials.

Element Description Data Type
ApplicationToken This header element is not used and should be ignored. string
AuthenticationToken The OAuth access token that represents a Microsoft Account user who has permissions to Bing Ads accounts. string
CustomerAccountId The identifier of the account that owns the entities in the request. This header element must have the same value as the AccountId body element when both are required. string
CustomerId The identifier of the customer that contains and owns the account. If you manage an account of another customer, you should use that customer ID instead of your own customer ID. string
DeveloperToken The developer token used to access the Bing Ads API. string
Password The Bing Ads managed user's sign-in password. string
UserName The Bing Ads managed user's sign-in name. You must not set this element to a Microsoft account or email address. string


The UserName and Password header elements are deprecated. In future versions of the API, Bing Ads will transition exclusively to Microsoft Account (email address) authentication. For more information, see Authentication with OAuth. UserName and Password are still required for Bing Ads managed credentials, but they are not applicable for Microsoft account authentication. To authenticate a Microsoft account, use the AuthenticationToken] header instead of UserName and Password.


Do not mistake the account number for the account identifier. The account number is the system generated account number that is used to identify the account in the Bing Ads web application. The account number has the form xxxxxxxx, where xxxxxxxx is a series of any eight alphanumeric characters. The API service requests only use the account identifier, and never use the account number.


With the exception of the Customer Billing and Customer Management services, the CustomerAccountId and CustomerId are required for most service operations. As a best practice you should always specify them in the request.

Need Help?

For troubleshooting tips, see Handling Service Errors and Exceptions.

To get help with issues that you cannot resolve, consider posting in the API Developer Forum where an active Bing Ads product team or community member will try and help. If you do not find timely information via the developer forum, or if the investigation involves sensitive account or personal details, please contact Bing Ads Support.

See Also

Bing Ads Technical Guides
Bing Ads API Reference