This guide contains examples of configuration files and links to Terraform resources you can use to create API tests, as well as associated synthetics resources such as global variables.
importosfromdateutil.parserimportparseasdateutil_parserfromdatadog_api_client.v1importApiClient,ApiException,Configurationfromdatadog_api_client.v1.apiimportsynthetics_apifromdatadog_api_client.v1.modelsimport*frompprintimportpprint//Seeconfiguration.pyforalistofallsupportedconfigurationparametersconfiguration=Configuration(host="https://api.datadoghq.com",api_key={"apiKeyAuth":"<YOUR_API_KEY>","appKeyAuth":"<YOUR_APPLICATION_KEY>"})//EnteracontextwithaninstanceoftheAPIclientwheretheApiClientconfigurationissetasapi_client://CreateaninstanceoftheAPIclassapi_instance=synthetics_api.SyntheticsApi(api_client)body=SyntheticsAPITest(config=SyntheticsAPITestConfig(assertions=[SyntheticsAssertion(operator="lessThan",type="responseTime",target=1000),],request=SyntheticsTestRequest(body="body_example",headers=SyntheticsTestHeaders(**{"User-Agent":"value"}),method=HTTPMethod("GET"),no_saving_response_body=True,query={},timeout=60.0,url="https://httpbin.org/get",),),locations=["aws:eu-west-2",],message="message_example",name="name_example",options=SyntheticsTestOptions(follow_redirects=True,min_failure_duration=1,min_location_failed=1,#monitor_name="monitor_name_example",monitor_options=SyntheticsTestOptionsMonitorOptions(renotify_interval=0,),monitor_priority=1,tick_every=30),status=SyntheticsTestPauseStatus("live"),subtype=SyntheticsTestDetailsSubType("http"),tags=["python-client",],type=SyntheticsAPITestType("api"),)# SyntheticsAPITest | Details of the test to create.//examplepassingonlyrequiredvalueswhichdon't have defaults settry://CreateanAPItestapi_response=api_instance.create_synthetics_api_test(body)pprint(api_response)exceptApiExceptionase:print("Exception when calling SyntheticsApi->create_synthetics_api_test: %s\n"%e)
If you need to run your synthetic tests from custom or secured locations, you can use the private location resource to create and manage private locations to run your tests from. Learn more on the private locations page.
Use the synthetics global variable resource to create and manage synthetics global variables, which are variables that can be securely shared across tests. You can also create test-specific local variables with builtins by defining the config_variable nested schema with type = "text" in your synthetic test resources.