TeamViewer provides a web-based API that allows you to access data and control various aspects of your TeamViewer account. You can use the API to develop apps that integrate TeamViewer functionality into your own corporate environment or you can develop apps that everyone can use.
Imagine that you need to remove a group with devices inside, one by one and then delete a group. That’s OK when you have a couple of devices, but when you have hundreds may be a hassle. Let’s get advantage of the API technology, by creating a script that will delete a group for you automatically, including devices inside of it. All you need to do provide the API token and the group name. This article will show you how.
From a detailed perspective, we will be using the Group Management and Device Management API functions. Windows PowerShell was used to implement of the solution. Using a user token, the code will retrieve the devices and groups from your management console, display them and let you choose what group you will like to delete. After making the selection, the result will be a neat console.
Make sure you have a TeamViewer account. If you don’t have one you may get one free at http://login.teamviewer.com
To create a script, you please log in to the TeamViewer Management Console with your TeamViewer account and create a script token.
In the Console, open your profile settings in the top right of the website. Then select Apps and click Create script token. Complete the form to define your token
• Enter your script name
• Enter a description for your script token
• Choose the permissions of your script token
• Group Management – View, create delete edit and share groups
• Computers & Contacts – View, add, edit and delete entries
• Save the script token
Now, save the token in a safe place. This will be requested by the script when it’s running.
$token = Read-Host -Prompt "Paste your account token code here"
$bearer = "Bearer",$token
$header = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$webrequest = Invoke-RestMethod -Uri "https://webapi.teamviewer.com/api/v1/groups/" -Method Get -Headers $header
$machine = Invoke-RestMethod -Uri "Https://webapi.teamviewer.com/api/v1/devices/" -Method Get -Headers $header
$grpArr = @()
ForEach($grp in $webrequest.groups)
Write-Host $i ")" $grp.name " - " $grp.id
$grpArr += $grp.id;
ForEach($dev in $machine.devices)
If($dev.groupid -eq $grp.id)
Write-Host " " $dev.alias
$i += 1
$ig = Read-Host -Prompt "Select the group you will like to remove"
ForEach ($dgrp in $machine.devices)
if($dgrp.groupid -eq $grpArr[$ig - 1])
Write-Host "Delete device: " $dgrp.alias
$item = $dgrp.device_id
$delete = Invoke-WebRequest -Uri "Https://webapi.teamviewer.com/api/v1/devices/$item" -Method Delete -Headers $header
Write-Host "Delete group id: " $grpArr[$ig - 1]
$gid = $grpArr[$ig - 1]
$remove = Invoke-WebRequest -Uri "Https://webapi.teamviewer.com/api/v1/groups/$gid" -Method Delete -Headers $header
Running the Script
Copy the script code into your favorite text editor (ex. Notepad), and save as .ps1 file. (test.ps1)
Please watch the following video for detailed information on how the script works.
The Bottom Line
TeamViewer API is a valuable tool when you need to get the most from your management console. By combining this with a programming language and your imagination you might get instant results like this for your everyday tasks. Enjoy!