Trying to add new device to teamviewer from code

Highlighted
Posted by
Trigon

Trying to add new device to teamviewer from code

Hello all, using the following Python code to add a device to Teamviewer, this is

{'error': 'invalid_token', 'error_description': 'Access token does not have the required permissions for this function.', 'error_code': 2}

How do I resolve this?

Thanks

import requests
from requests.auth import HTTPDigestAuth
import json
from pandas.io.json import json_normalize
def createNewDevice():

remoteID = input("Enter Remote ID:")
groupID = input("Enter Group ID:")
descr = input("Enter Description;")
alias = input("Enter Alias:")
pword = input("Enter Password:")
#Go by Usernam
url="https://webapi.teamviewer.com/api/v1/devices"

#oAuth2 syntax for Bearer Token appears to be correct....
headers = {"content-type": "application/json", "Authorization": "Bearer xxxxxx-xxxxxxxxxxx"}

#need data
data = {"remotecontrol_id": remoteID, "groupid" : groupID, "description" : descr, "alias" : alias, "password" : pword}
r = requests.post(url, headers=headers,json=data)

print("Done")
createNewDevice()
3 Replies
1 Accepted Solution

Accepted Solutions
Highlighted
Posted by Moderator Moderator
Moderator
Solution

Re: Trying to add new device to teamviewer from code

Hi @RlS ,

Thank you for your post.

From the error message, you have not given the right permissions when you set up the API token.
You need to create a new key with the right permissions. (You could try giving all permissions)

Managemement Console: https://login.teamviewer.com/nav/profile

Create API token.png

This is the documentation for API.
https://dl.tvcdn.de/integrate/TeamViewer_API_Documentation.pdf

Hope this will help you.

All the best,
Yuri

View solution in original post

3 Replies
Highlighted
Posted by Moderator Moderator
Moderator
Solution

Re: Trying to add new device to teamviewer from code

Hi @RlS ,

Thank you for your post.

From the error message, you have not given the right permissions when you set up the API token.
You need to create a new key with the right permissions. (You could try giving all permissions)

Managemement Console: https://login.teamviewer.com/nav/profile

Create API token.png

This is the documentation for API.
https://dl.tvcdn.de/integrate/TeamViewer_API_Documentation.pdf

Hope this will help you.

All the best,
Yuri

View solution in original post

Highlighted
Posted by
Trigon

Re: Trying to add new device to teamviewer from code

Thanks, I changes it around. So Now its givimg me

{'error': 'invalid_request', 'error_description': 'RemoteControl Id is invalid.', 'error_code': 1}

 Im using r**Please do not post TeamViewer IDs**

What should I use, also the groupID is like g545456...Is this correct, or should I use something different.

Thanks Again

Highlighted
Posted by Moderator Moderator
Moderator

Re: Trying to add new device to teamviewer from code

Hi @RlS,

Thanks for posting.

Just a heads up, I can help with the API, but I am not fluent in python sorry, so anyone else - feel free to jump in if there are any code errors!

TeamViewer ID's do not need an "r" in front of them.
When posting to the API, I would recommend that you first make a request for data from the API, then return the data in JSON format matching the output data you received to make sure your entries match the convention,

I hope this helps,
Yuri