Please note that the AdWords API Sandbox has been deprecated, and you should now test your applications using a test account.
The sandbox environment for the AdWords API enables you to test out your applications without worrying about using up quota units or making inadvertent errors which damage live campaigns. This article shows you how to access it using the PHP client library.
Connecting To the AdWords API Sandbox
You don't need to sign up for the API in order to run your code in the sandbox environment, you can just use any Google account to login and test your software. However, there are a few additional steps that you need to follow:
Generate a sandbox developer token.
Change the URL where you send your API requests.
Create a sandbox MCC account.
Obtain a list of dummy accounts to use.
The following sections describe these steps in detail.
The Sandbox Developer Token
Although you don't need to sign up for the production API and get an official token, you do need to supply something in the header, which is simply the username that you're using to login postfixed with the string ++[currency_code]. The currency code just needs to be any valid one, so if you have a Google account called [email protected] and want to use USD for the currency, then the developer token would simply be [email protected]++USD.
This then gives us the first few lines of PHP for a script that uses the sandbox:
The Sandbox URL
To use the sandbox servers instead of live servers, you simply need to change the default URL from https://adwords.google.com/ to https://adwords-sandbox.google.com/. This can be done with the SetDefaultServer() method of the AdWordsUser object. This gives us our next few lines of code:
Creating Sandbox Accounts
The Google account that you use to login to the sandbox is always considered an MCC account; you therefore need some advertiser accounts with which to work. These are auto-generated the first time you make a call to the CampaignService. This call doesn't even need to succeed so you can simply create your accounts using the following code:
Listing Sandbox Accounts
Finally, you need to get the customerId of an account to use in the sandbox. The call to the CampaignService created five dummy accounts, and you can list them using a get call to the ManagedCustomerService:
We can now use one of the accounts to make API calls: