Connecting to Bing Ads
You need to register a Bing Ads account, get a developer token, and authenticate using OAuth to connect to the Bing Ads APIs.
Register a Bing Ads Account
Complete the following steps to sign up for a Bing Ads account and obtain the CustomerId and (optional) AccountId:
- Sign up for a Bing Ads account in the Bing Ads Web application or at the Sandbox Site for a sandbox account.
- Select Settings > Accounts and Billing and select a single account. The AccountId and CustomerId (cid) are displayed on the account's page and in the page's URL.
Get a Developer Token
To use the Bing Ads APIs, you must have a DeveloperToken in addition to the CustomerId. You must have the Super Admin role in Bing Ads to create a developer token, though you do not need special permissions to use the token.
- Log in at the Bing Ads Developer Portal as a Microsoft Account user with the Bing Ads Super Admin role.
- Click Request Token and take note of your developer token. You will set it in the DeveloperToken connection property.
Authenticate via OAuth Authentication
The Bing Ads APIs use the OAuth 2 standard. See Using OAuth Authentication for an authentication guide.
Using OAuth Authentication
OAuth requires the authenticating user to interact with Bing Ads using the browser. The provider facilitates this in various ways as described below.
Embedded Credentials
Desktop Applications
See Embedded Credentials to connect with the provider's embedded credentials and skip creating a custom OAuth app. The provider has embedded OAuth credentials for both sandbox and production.Headless Machines
See Headless Machines to skip creating a custom OAuth app and authenticate an application running on a headless server or another machine where the provider is not authorized to open a browser.Custom Credentials
Instead of connecting with the provider's embedded credentials, you can register an app to obtain the OAuthClientId and OAuthClientSecret.
When to Create a Custom OAuth App
Web Applications
You need to create a custom OAuth app in the web flow.
Desktop Applications
Creating a custom OAuth app is optional as the provider is already registered with Bing Ads and you can connect with its embedded credentials. You might want to create a custom OAuth app to change the information displayed when users log into the Bing Ads OAuth endpoint to grant permissions to the provider.
Headless Machines
Creating a custom OAuth app is optional to authenticate a headless machine; the provider is already registered with Bing Ads and you can connect with its embedded credentials. In the headless OAuth flow, users need to authenticate via a browser on another machine. You might want to create a custom OAuth app to change the information displayed when users log into the Bing Ads OAuth endpoint to grant permissions to the provider.
Creating a Custom OAuth App
See Creating a Custom OAuth App for a procedure.
Embedded Credentials
Authenticate using the Embedded OAuth Credentials
Register a Bing Ads Account
Follow the steps below to sign up for a Bing Ads account and obtain the CustomerId and AccountId:
- Sign up for a Bing Ads account in the Bing Ads Web application or at the Sandbox Site for a sandbox account.
- Click Settings -> Accounts and Billing and select a single account. The AccountId and CustomerId (cid) are displayed on the account's page and in the page's URL.
Get a Developer Token
To use the Bing Ads APIs, you must have a DeveloperToken in addition to the CustomerId and AccountId. You must have the Super Admin role in Bing Ads to create a developer token, though you do not need special permissions to use the token.
- Log in at the Bing Ads Developer Portal as a Microsoft Account user with the Bing Ads Super Admin role.
- Click the Request Token button and take note of your developer token. You will set it in the DeveloperToken connection property.
Desktop Authentication with the Embedded OAuth App
You can connect without setting any connection properties for your user credentials. After setting the following, you are ready to connect:
- InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal. BBD37VB98 may be used for sandbox accounts.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
- Extracts the access token from the callback URL and authenticates requests.
- Obtains a new access token when the old one expires.
- Saves OAuth values in OAuthSettingsLocation to be persisted across connections.
Custom Credentials
You might want to create a custom OAuth app to change the information displayed when users log into Bing Ads to grant permissions to the provider.
Registering a Bing Ads Account
Follow the steps below to sign up for a Bing Ads account and obtain the CustomerId and AccountId:
- Sign up for a Bing Ads account in the Bing Ads Web application or at the Sandbox Site for a sandbox account.
- Click Settings -> Accounts and Billing and select a single account. The AccountId and CustomerId (cid) are displayed on the account's page and in the page's URL.
Getting a Developer Token
To use the Bing Ads APIs, you must have a DeveloperToken in addition to the CustomerId and AccountId. You must have the Super Admin role in Bing Ads to create a developer token, though you do not need special permissions to use the token.
- Log in at the Bing Ads Developer Portal as a Microsoft Account user with the Bing Ads Super Admin role.
- Click the Request Token button and take note of your developer token. You will set it in the DeveloperToken connection property.
Desktop Authentication with a Custom OAuth App
Follow the steps below to authenticate with the credentials for a custom OAuth app. See Creating a Custom OAuth App.Get and Refresh the OAuth Access Token
After setting the following, you are ready to connect:
- OAuthClientId: Set this to the client Id assigned when you registered your app.
- OAuthClientSecret: Set this to the client secret assigned when you registered your app.
- CallbackURL: Set this to the redirect URI defined when you registered your app.
- InitiateOAuth: Set this to GETANDREFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
- Extracts the access token from the callback URL and authenticates requests.
- Refreshes the access token when it expires.
- Saves OAuth values in OAuthSettingsLocation to be persisted across connections.
Web Authentication with a Custom OAuth App
When connecting via a Web application, you need to register a custom OAuth app with Bing Ads. See Creating a Custom OAuth App. You can then use the provider to get and manage the OAuth token values.
Get an OAuth Access Token
Set the following connection properties to obtain the OAuthAccessToken:
- OAuthClientId: Set this to the Client Id in your app settings.
- OAuthClientSecret: Set this to the Client Secret in your app settings.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
You can then call stored procedures to complete the OAuth exchange:
-
Call the GetOAuthAuthorizationURL stored procedure. Set the AuthMode input to WEB and set the CallbackURL input to the Redirect URI you specified in your app settings.
The stored procedure returns the URL to the OAuth endpoint.
- Open the URL, log in, and authorize the application. You are redirected back to the callback URL.
- Call the GetOAuthAccessToken stored procedure. Set the AuthMode input to WEB. Set the Verifier input to the "code" parameter in the query string of the callback URL.
Refresh the OAuth Access Token
You can set InitiateOAuth to REFRESH to automatically refresh the OAuth access token when it expires, or you can call the RefreshOAuthAccessToken stored procedure to refresh the token manually.
Automatic Refresh
To refresh the token with InitiateOAuth, set the following on the first data connection:
- OAuthAccessToken: Set this to the access token returned by GetOAuthAccessToken.
- InitiateOAuth: Set this to REFRESH. You can use InitiateOAuth to avoid repeating the OAuth exchange and manually setting the OAuthAccessToken.
- OAuthSettingsLocation: Set this to the path where the provider will save the OAuth values, to be persisted across connections.
- OAuthClientId: Set this to the Client Id in your app settings.
- OAuthClientSecret: Set this to the Client Secret in your app settings.
- OAuthRefreshToken: Set this to the refresh token returned by GetOAuthAccessToken.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
On subsequent data connections, set the following:
- InitiateOAuth
- OAuthSettingsLocation
- DeveloperToken
- AccountId
- CustomerId
Manual Refresh
You can use the RefreshOAuthAccessToken stored procedure to manually refresh the OAuthAccessToken. Call the stored procedure after the ExpiresIn parameter value returned by GetOAuthAccessToken has elapsed. You need the following connection properties to be set:
- OAuthClientId: Set this to the Client Id in your app settings.
- OAuthClientSecret: Set this to the Client Secret in your app settings.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
You can then call RefreshOAuthAccessToken with the following parameter set:
- OAuthRefreshToken: Set this to the OAuthRefreshToken returned by GetOAuthAccessToken.
Headless Machines
Using OAuth on a Headless Machine
To create Bing Ads data sources on headless servers or other machines on which the provider cannot open a browser, you need to authenticate from another machine. Authentication is a two-step process.
- Instead of installing the provider on another machine, you can follow the steps below to obtain the OAuthVerifier value. Or, you can install the provider on another machine and transfer the OAuth authentication values, after you authenticate through the usual browser-based flow.
- You can then configure the provider to automatically refresh the access token from the headless machine.
Using the Embedded OAuth Credentials
Obtain a Verifier Code
Follow the steps below to authenticate from another machine and obtain the OAuthVerifier connection property:
- Click the following link to open the Bing Ads OAuth endpoint in your browser.
- Log in and grant permissions to the provider. You are then redirected to the callback URL, which contains the verifier code.
- Save the value of the verifier code. You will set this in the OAuthVerifier connection property.
On the headless machine, set the following connection properties to obtain the OAuth authentication values.
- OAuthVerifier: Set this to the verifier code.
- InitiateOAuth: Set this to REFRESH.
- OAuthSettingsLocation: Set this to persist the encrypted OAuth authentication values to the specified file.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
After the OAuth settings file is generated, set the following properties to connect to data:
- OAuthSettingsLocation: Set this to the file containing the encrypted OAuth authentication values. Make sure this file gives read and write permissions to the provider to enable the automatic refreshing of the access token.
- InitiateOAuth: Set this to REFRESH.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
Transfer OAuth Settings
Follow the steps below to install the provider on another machine, authenticate, and then transfer the resulting OAuth values.
On a second machine, install the provider and connect with the following properties set:
- OAuthSettingsLocation: Set this to a writable text file.
- InitiateOAuth: Set this to GETANDREFRESH.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
On the headless machine, set the following connection properties to connect to data:
- InitiateOAuth: Set this to REFRESH.
- OAuthSettingsLocation: Set this to the path to your OAuth settings file. Make sure this file gives read and write permissions to the provider to enable the automatic refreshing of the access token.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
Using the Credentials for a Custom OAuth App
Create a Custom OAuth App
Creating a custom OAuth app is optional in the headless OAuth flow; you can skip creating an app by connecting with the provider's embedded OAuth credentials. You might want to create a custom OAuth app to change the information displayed when users log into Bing Ads to grant permissions to the provider.
See Creating a Custom OAuth App for a procedure. You can then follow the procedures below to authenticate and connect to data.
Obtain a Verifier Code
Set the following properties on the headless machine:
- InitiateOAuth: Set this to OFF.
- OAuthClientId: Set this to the Client Id in your app settings.
- OAuthClientSecret: Set this to the Client Secret in your app settings.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
You can then follow the steps below to authenticate from another machine and obtain the OAuthVerifier connection property.
- Call the GetOAuthAuthorizationURL stored procedure with the CallbackURL input parameter set to the exact Redirect URI you specified in your app settings.
- Open the returned URL in a browser. Log in and grant permissions to the provider. You are then redirected to the callback URL, which contains the verifier code.
- Save the value of the verifier code. You will set this in the OAuthVerifier connection property.
On the headless machine, set the following connection properties to obtain the OAuth authentication values:
- OAuthVerifier: Set this to the verifier code.
- OAuthSettingsLocation: Set this to persist the encrypted OAuth authentication values to the specified file.
- InitiateOAuth: Set this to REFRESH.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
Connect to Data
After the OAuth settings file is generated, set the following properties to connect to data:
- OAuthSettingsLocation: Set this to the file containing the encrypted OAuth authentication values. Make sure this file gives read and write permissions to the provider to enable the automatic refreshing of the access token.
- InitiateOAuth: Set this to REFRESH.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
Transfer OAuth Settings
Follow the steps below to install the provider on another machine, authenticate, and then transfer the resulting OAuth values.
On a second machine, install the provider and connect with the following properties set:
- OAuthSettingsLocation: Set this to a writable text file.
- InitiateOAuth: Set this to GETANDREFRESH.
- OAuthClientId: Set this to the client Id assigned when you registered your app.
- OAuthClientSecret: Set this to the client secret assigned when you registered your app.
- CallbackURL: Set this to the Redirect URI you specified in your app settings.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
Test the connection to authenticate. The resulting authentication values are written, encrypted, to the path specified by OAuthSettingsLocation. Once you have successfully tested the connection, copy the OAuth settings file to your headless machine. On the headless machine, set the following connection properties to connect to data:
- InitiateOAuth: Set this to REFRESH.
- OAuthSettingsLocation: Set this to the path to your OAuth settings file. Make sure this file gives read and write permissions to the provider to enable the automatic refreshing of the access token.
- DeveloperToken: Set this to the token you generated in the Bing Ads Developer Portal.
- AccountId: Set this to the account Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Account.
- CustomerId: Set this to the customer Id value found in the Bing Ads Web application, under Settings -> Accounts and Billing -> Your Account -> Customer.
Creating a Custom OAuth App
When to Create a Custom OAuth App
Creating a custom OAuth app is required in the web flow. Creating a custom OAuth app is optional for desktop and headless applications; the provider is already registered with Bing Ads and you can connect with its embedded credentials.You might want to create a custom OAuth app to change the information displayed when users log into the Bing Ads OAuth endpoint to grant permissions to the provider.
Follow the steps below to create a custom OAuth app and obtain the connection properties in a specific OAuth authentication flow.
Create a Custom OAuth App: Desktop
- If you have not done so already, sign up for a Bing Ads account in the Bing Ads Web application or at the Sandbox Site for a sandbox account.
- Go to the Azure portal (Azure test portal for sandbox accounts), and login with your Microsoft Account credentials when prompted.
- Under Azure Active Directory --> App registrations, click New registration.
- Provide the application name and select an appropriate Supported account type. Not selecting to allow personal Microsoft accounts will prevent users with personal accounts from authenticating.
- In the Redirect URI section, you must set an appropriate URL. For desktop applications a value such as "http://localhost:33333" or another port of your choice may be set.
- Register your application and take note of your Application (client) Id. You will use it as the OAuthClientId value in the OAuth grant flow.
- In the Certificates & secrets section, click New client secret to generate a client secret and take note of the resulting value. You will use it as the OAuthClientSecret value.
Create a Custom OAuth App: Web Apps
In the OAuth flow for Web apps, you must create a Bing Ads application to obtain the OAuthClientId, OAuthClientSecret, and redirect URI.
- If you have not done so already, sign up for a Bing Ads account in the Bing Ads Web application or at the Sandbox Site for a sandbox account.
- Go to the Azure portal (Azure test portal for sandbox accounts), and login with your Microsoft Account credentials when prompted.
- Under Azure Active Directory --> App registrations, click New registration.
- Provide the application name and select an appropriate Supported account type. Not selecting to allow personal Microsoft accounts will prevent users with personal accounts from authenticating.
- Set the Redirect URI to the page in your Web application where you would like users to be redirected with the OAuthVerifier
- Register your application and take note of your Application (client) Id. You will use it as the OAuthClientId value in the OAuth grant flow.
- In the Certificates & secrets section, click New client secret to generate a client secret and take note of the resulting value. You will use it as the OAuthClientSecret value.
Create a Custom OAuth App: Headless Machines
- If you have not done so already, sign up for a Bing Ads account in the Bing Ads Web application or at the Sandbox Site for a sandbox account.
- Go to the Azure portal (Azure test portal for sandbox accounts), and login with your Microsoft Account credentials when prompted.
- Under Azure Active Directory --> App registrations, click New registration.
- Provide the application name and select an appropriate Supported account type. Not selecting to allow personal Microsoft accounts will prevent users with personal accounts from authenticating.
- In the Redirect URI section, you must set an appropriate URL. For desktop applications a value such as "http://localhost:33333" or another port of your choice may be set.
- Register your application and take note of your Application (client) Id. You will use it as the OAuthClientId value in the OAuth grant flow.
- In the Certificates & secrets section, click New client secret to generate a client secret and take note of the resulting value. You will use it as the OAuthClientSecret value.
Connecting Through a Firewall or Proxy
HTTP Proxies
To connect through the Windows system proxy, you do not need to set any additional connection properties. To connect to other proxies, set ProxyAutoDetect to false.
In addition, to authenticate to an HTTP proxy, set ProxyAuthScheme, ProxyUser, and ProxyPassword, in addition to ProxyServer and ProxyPort.
Other Proxies
Set the following properties:
- To use a proxy-based firewall, set FirewallType, FirewallServer, and FirewallPort.
- To tunnel the connection, set FirewallType to TUNNEL.
- To authenticate, specify FirewallUser and FirewallPassword.
- To authenticate to a SOCKS proxy, additionally set FirewallType to SOCKS5.
Troubleshooting the Connection
To show provider activity from query execution to network traffic, use Logfile and Verbosity. The examples of common connection errors below show how to use these properties to get more context. Contact the support team for help tracing the source of an error or circumventing a performance issue.
- Authentication errors: Typically, recording a Logfile at Verbosity 4 is necessary to get full details on an authentication error.
- Queries time out: A server that takes too long to respond will exceed the provider's client-side timeout. Often, setting the Timeout property to a higher value will avoid a connection error. Another option is to disable the timeout by setting the property to 0. Setting Verbosity to 2 will show where the time is being spent.