# Create New Iperf, Network Speed or VoIP Tests Using the API

**URL:** <https://community.netbeez.net/t/create-new-iperf-network-speed-or-voip-tests-using-the-api/111>\
**Category:** APIs & Developer Support\
**Tags:** api\
**Created:** [October 3, 2023, 8:26pm UTC](https://community.netbeez.net/t/create-new-iperf-network-speed-or-voip-tests-using-the-api/111 "2023-10-03T20:26:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![panickos](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.netbeez.net/panickos/32/8_2.png) [@panickos](https://community.netbeez.net/u/panickos)\
**Post date:** [October 3, 2023, 8:26pm UTC](https://community.netbeez.net/t/create-new-iperf-network-speed-or-voip-tests-using-the-api/111/1 "2023-10-03T20:26:31Z")

</div>

# Introduction

Managing scheduled tests via API offers significant advantages, especially for large-scale deployments with hundreds of agents. It streamlines configuration, ensures consistency, and facilitates automation.

# Setting Up API Variables

Before running any test, you need to configure the Bearer token and base URL. Here’s how to set them up in Python.

```python
import requests

BEARER_TOKEN = "API_TOKEN_HERE"
BASE_URL = "https://YOUR_BEEZKEEPER_HOSTNAME"

headers = {
    'Authorization': f'Bearer {BEARER_TOKEN}',
}

```

# Creating an Iperf Test

To create an Iperf test, make a POST request to the `/scheduled_nb_test_templates.json` endpoint with the appropriate payload.

### Python Snippet

```python
iperf_payload_1_to_1 = {
	"scheduled_nb_test_template": {
		"test_type_id": 5,
		"agent_ids": [
			6
		],
		"bandwidth": null,
		"cron_schedule": "0 9,15,21 * * 1,2,3,4,5",
		"iperf_port": 5001,
		"iperf_time": 10,
		"iperf_type": 1,
		"iperf_version": 2,
		"label": "Test API POST",
		"multicast": false,
		"multicast_ip": false,
		"parallel_streams": 1,
		"reverse": false,
		"target_is_agent": 5,
		"tcp_window": 1,
		"ttl": 5,
		"warning_conditions": {}
	}
}

response = requests.post(
    f"{BASE_URL}/scheduled_nb_test_templates.json",
    headers=headers,
    json=iperf_payload_1_to_1
)

```

Notice that the `target_is_agent` is set to a non-zero number which indicates the agent id of the destination agent. Make sure that agent is able to receive connections on the `iperf_port`.

For a _ **M-to-1 test** _ use this payload:

```python
iperf_payload_M_to_1 = {
	"scheduled_nb_test_template": {
		"test_type_id": 5,
		"agent_ids": [
			14,
			7,
			6,
			5,
			4,
			2,
			1
		],
		"bandwidth": null,
		"cron_schedule": "0 * * * *",
		"iperf_port": 5001,
		"iperf_time": 10,
		"iperf_type": 1,
		"iperf_version": 2,
		"label": "M-to-1 Iperf Test API",
		"multicast": false,
		"multicast_ip": false,
		"parallel_streams": 1,
		"reverse": false,
		"target": "myiperf.example.com",
		"tcp_window": 1,
		"ttl": 5,
		"warning_conditions": {}
	}
}

```

# Creating a Network Speed Test

To create a Network Speed test, the process is similar, but with a different payload.

### Python Snippet

```python
network_speed_payload = {
{
	"scheduled_nb_test_template": {
		"test_type_id": 7,
			"agent_ids": [
				14,
				7,
				6,
				5,
				4,
				2,
				1
			],
			"cron_schedule": "0 8,14,20 * * 1,2,3,4,5",
			"target": "",
			"label": "Network Speed Test API",
			"secure": true,
			"speedtest_type": 2,
			"server": "",
			"mini_server": "",
			"warning_conditions": {}
		}
	}
}

response = requests.post(
    f"{BASE_URL}/scheduled_nb_test_templates.json",
    headers=headers,
    json=network_speed_payload
)

```

# Creating a VoIP Test

For a VoIP test, again, change the payload to match the test type and its parameters.

### Python Snippet

```python
voip_payload = {
	"scheduled_nb_test_template": {
		"test_type_id": 8,
		"agent_ids": [
			5
		],
		"cron_schedule": "0 9,15,21 * * *",
		"target": "",
		"label": "VoIP Test API",
		"codec": "g711",
		"num_of_concurrent_calls": 1,
		"target_is_agent": 6,
		"voip_port": 12001,
		"voip_time": 30,
		"warning_conditions": {}
	}
}

response = requests.post(
    f"{BASE_URL}/scheduled_nb_test_templates.json",
    headers=headers,
    json=voip_payload
)

```

# Summary and Further Reading

Using the API to manage your tests offers efficiency and scalability, especially when configuring tests over multiple agents. For more details, consult the [API Documentation](https://api.netbeez.net).

* * *

By understanding and implementing these examples, you can effectively manage your network tests through API calls.
