API Python Example Code


  11 months ago by Admin

The following python code demonstrates how to call API functions within python.



#this code is written for python3+, to use it with python2.6 
#remove the () from all of the print statements

#see: http://docs.python-requests.org/en/master/user/quickstart/
import requests

#this is a python built in library
import json

#set this to your api key (found on the account settings page)
TAVEO_API_KEY =  

#step 1, use API to get an overview of your account
payload = {'apikey': TAVEO_API_KEY}
r = requests.get('https://api.taveo.net/1/overview', params=payload)
#convert the json string into a python dict
data = json.loads(r.text)
#check the HTTP status code
if r.status_code != 200:
    print("ERROR: %s" % (data["msg"]))
else:
    print(data)
    print(data["account"])


#Step 2,create a link

#the multidest parameter is complicated, create it here first
#we create a python dict object, then "convert" it to a JSON string
multidest = {
    "type": "random" ,
    "data" : {
         "0" : "http://thisisa.localtest/1",
         "1" : "http://thisisa.localtest/2",
         "2" : "http://thisisa.localtest/3"
     }
}

payload = {
    'apikey': TAVEO_API_KEY,
    'destination': 'https://google.com/',
    'comment' : 'Test link,
    'multidest' : json.dumps(multidest)
}
r = requests.get('https://api.taveo.net/1/create', params=payload)
#convert the json result string into a python dict
data = json.loads(r.text)

if r.status_code != 200:
    print("ERROR: %s" % (data["msg"]))
else:
    print(data)
    print("Success your Link URL is %s" % (data["url"]))











Can't find the answer to your question? Contact our support team