teamviewer.com link icon
or
Ask The Community

TeamViewer is one of the winners of the European Customer Centricity Award 🥳


Please find more information here.

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()

Best Answer

Answers

  • RlS
    RlS Posts: 15

    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

  • Yuri_T
    Yuri_T Posts: 2,259 [Former Staff]

    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

    Former Japanese Community Moderator