REST API call execution tool
The Trade Desk offers a Platform API endpoint to allow enterprise clients to build DSP-related automation services. This article describes how to execute a Python-based code tool to test a Platform API call on The Trade Desk platform. The tool facilitates verification and validation of an API call during client setup and testing on API services. This tool also measures performance in terms of time.
NOTE: To download a ZIP file with the complete code sample for executing an API call, use this download link. The code was tested in Python version 3.9.10.
Prerequisites
To be able to use the downloaded Python-based code tool to test a Platform API call on The Trade Desk platform, be sure to do the following:
Install Python on a local machine:
- For Windows, use https://www.python.org/downloads/windows/.
- For Mac, use https://www.python.org/downloads/mac-osx/.
Execute an API call
To execute an enterprise API call using the tool, complete the following steps:
- Inspect the code and provide the required values.
- Execute the code.
Inspect and update the code
To inspect and update the code, complete the following steps:
- If you have not done so, download the tool.
- Open up the downloaded Python code file in a text editor.
- In SECTION 1, in the
LoginandPasswordproperties, provide your platform username and password. - In SECTION 2, instead of the provided sample
/adgroup/query/advertiserendpoint, specify the URL of the endpoint that you want to use and provide the required input parameter values. - Save the updated file.
The following code snippet shows the two sections where you need to make changes.
###################################
# SECTION 1: Call for an authentication token
type = 'application/json'
#Input parameters
url = "https://api.thetradedesk.com/v3/authentication"
payload = {
"Login": "", # Your platform username.
"Password": "" # Your platform password.
}
myResponse = requests.post(url, headers={"Content-Type": type}, json=payload)
if(myResponse.ok):
jData = json.loads(str(myResponse.content, "utf-8"))
authToken = jData["Token"]
print(authToken)
else:
#If response code is not ok (200), print the resulting HTTP error code with description
myResponse.raise_for_status()
###################################
# SECTION 2: Call the API endpoint you want to test
#Input parameters
url = "https://api.thetradedesk.com/v3/adgroup/query/advertiser"
payload = {
"AdvertiserId": "",
"PageStartIndex": 0,
"PageSize": 1
}
#######################
Execute the code
NOTE: The general execution sequence is very similar on Windows and Linux-based machines. If needed, before proceeding with execution of the Python tool on Windows, see Python on Windows FAQ.
To run the tool, do the following:
- Open the command line and navigate to the directory where the updated Python code script is located.
- Enter the following command, where
name_of_Python_code_scriptis the name of the file with the Python code, and press Enter or Return on the keyboard.
python ./name_of_Python_code_script.py
An execution output similar to the following example should appear:
python ./name_of_Python_code_script.py
('Execution time in seconds: ', 15.1524427163986613)
This sample execution took approximately 15 seconds, but execution time may vary from machine to machine. The full output with the response in JSON format appears in the same directory.