# Create/Update/Delete Tests Using the ThousandEyes API

The ThousandEyes API supports creating, editing, and deleting tests programmatically.

This feature is restricted to users with Account Admin privileges or higher. Users without account admin privileges will receive an HTTP/403 error when attempting to post a write request.

The NEW, UPDATE and DELETE endpoints have been added to each test endpoint. Content must be submitted using a POST request, and all POST requests must contain a "Content-Type: application/JSON" header.

```
/tests/agent-to-server/new
/tests/agent-to-server/{testId}/update
/tests/agent-to-server/{testId}/delete

/tests/agent-to-agent/new
/tests/agent-to-agent/{testId}/update
/tests/agent-to-agent/{testId}/delete

/tests/dns-trace/new
/tests/dns-trace/{testId}/update
/tests/dns-trace/{testId}/delete

/tests/dns-server/new
/tests/dns-server/{testId}/update
/tests/dns-server/{testId}/delete

/tests/dns-dnssec/new
/tests/dns-dnssec/{testId}/update
/tests/dns-dnssec/{testId}/delete

/tests/http-server/new
/tests/http-server/{testId}/update
/tests/http-server/{testId}/delete

/tests/page-load/new
/tests/page-load/{testId}/update
/tests/page-load/{testId}/delete

/tests/web-transactions/new
/tests/web-transactions/{testId}/update
/tests/web-transactions/{testId}/delete
```

To show a basic example of an add request, using cURL:

```
curl -X POST https://api.thousandeyes.com/v7/tests/agent-to-server \
-H "Authorization: Bearer $BEARER_TOKEN" \
-H "Content-Type: application/json"
-d '{"interval": 300, "agents": [{"agentId": "113"}], "testName": "API network test addition for www.thousandeyes.com", "server": "www.thousandeyes.com:80"}' \
```

this will return successfully once the test has been created:

```
{
 "test": [
  {
     "enabled":1,
     "testId":1586,
     "testName":"API network test addition for www.thousandeyes.com",
     "interval":300,
     "server":"www.thousandeyes.com:80",
     "agents":[
       {
          "agentId":113,
          "agentName":"Bucharest, Romania",
          "location":"Bucuresti, Romania",
          "countryId":"RO",
          "ipAddress":"89.36.27.146",
          "prefix":"89.36.24.0/21",
          "network":"HOSTWAY ROMANIA SRL (AS 39756)",
          "public":1
       }
     ],
     "createdBy":"Dave Fraleigh (dave@thousandeyes.com)",
     "createdDate":"2013-06-12 01:22:40"
     }
  ]
}
```

I can then update the same request by modifying the JSON data:

```
curl -X PUT https://api.thousandeyes.com/v7/tests/agent-to-server/1586 \
-H "Authorization: Bearer $BEARER_TOKEN" \
-H "Content-Type:application/json"
-d '{"interval": 900, "agents": [{"agentId": "113"}], "testName": "this is a new name and interval for my test"}' \ 
```

Note that only certain fields can be updated in an update request:

* interval
* testName
* agents

```
{
 "test": [
  {
     "enabled":1,
     "testId":1586,
     "testName":"this is a new name and interval for my test",
     "interval":900,
     "server":"www.thousandeyes.com:80",
     "agents":[
       {
          "agentId":113,
          "agentName":"Bucharest, Romania",
          "location":"Bucuresti, Romania",
          "countryId":"RO",
          "ipAddress":"89.36.27.146",
          "prefix":"89.36.24.0/21",
          "network":"HOSTWAY ROMANIA SRL (AS 39756)",
          "public":1
       }
     ],
     "createdBy":"Dave Fraleigh (dave@thousandeyes.com)",
     "createdDate":"2013-06-12 01:22:40",
     "modifiedBy":"Dave Fraleigh (dave@thousandeyes.com)",
     "modifiedDate":"2013-06-12 02:10:13",
     }
  ]
}
```

Then, to delete the same test, run the following command:

```
curl -X DELETE https://api.thousandeyes.com/v7/tests/agent-to-server/1586 \
-H "Authorization: Bearer $BEARER_TOKEN"
-H "Content-Type:application/json"
```

You'll get an empty JSON response back, and the test will be gone from the front end.

## Terraform

The ThousandEyes Terraform provider leverages the ThousandEyes Go SDK to allow users to manage tests and create alerts using [Terraform](https://www.terraform.io/).

For comprehensive documentation on using the ThousandEyes provider, see the links below:

* [ThousandEyes provider documentation](https://registry.terraform.io/providers/thousandeyes/thousandeyes/latest/docs).
* [ThousandEyes Go SDK repository](https://github.com/thousandeyes/thousandeyes-sdk-go).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.thousandeyes.com/product-documentation/api/create-update-delete-tests-using-the-thousandeyes-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
