Alfonso Jr
Alfonso Jr

Reputation: 39

TeamViewer API and PostMan

I'm searching for a way to parse multiple API requests using a postman snippet in python.

The following works:

import http.client

conn = http.client.HTTPSConnection("webapi.teamviewer.com")

payload = "remotecontrol_id=rxxxxxxxx&groupid=g18932019&alias=test1%20api&password=xxxxxx"

headers = {
    'authorization': "Bearer xxxxxxx-xxxxxxxxxxx",
    'cache-control': "no-cache",
    'postman-token': "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx",
    'content-type': "application/x-www-form-urlencoded"
    }

conn.request("POST", "/api/v1/devices", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

How can I do this with multiple payloads.?

Upvotes: 3

Views: 2048

Answers (1)

Baris Akar
Baris Akar

Reputation: 4965

This should do the trick:

import http.client

conn = http.client.HTTPSConnection("webapi.teamviewer.com")

headers = {
    'authorization': "Bearer xxxxxxx-xxxxxxxxxxx",
    'cache-control': "no-cache",
    'postman-token': "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx",
    'content-type': "application/x-www-form-urlencoded"
    }

ids = [35123241, 234234234, 1232312, 5644352, 234243234]
pws = ["47gj6", "fgdg6as", "saa23d", "a24asd", "gre42as"]

for i in range(len(ids)):
    payload = "remotecontrol_id=r%s&groupid=g18932019&alias=%s&password=%s" % (ids[i], ids[i], pws[i])

    conn.request("POST", "/api/v1/devices", payload, headers)

    res = conn.getresponse()
    data = res.read()

    print(data.decode("utf-8"))

You just need to initialize/populate ids and pws with your actual data somehow and they need to be of same size obviously (passwords on pws belong to the ids in ids at the same position).

Upvotes: 1

Related Questions