TeamDesk Knowledge Base & Support

   Home      FAQ      Forum      Idea Exchange      Ask a Question      My Stuff      Help   
  
Using the REST API with Python!
Hello Teamdesk gang,

Does anybody have experience with using python to interact with the REST API? Specifically with the 'requests' module?

My following function returns 405: 'the method is not supported by the requested resource'.

I am using the same URL as the one I successfully tested in the API playground.

Any advice? =)

Function:
randy = str(randint(1, 9999)) + "API TEST"

payload = {
"PR ID": randy,
"Description": "Testing",
"Department": "TMRP",
"Mission": "Chuuk",
"Justification": "Whatever"
}

headers = {"Content-type": "application/json"}
tdurl = "https://www.teamdesk.net/secure/api/v2/49539/MYTOPSECRETAPIKEY/-/Purchase%20Request/upsert.json"
r = requests.post(tdurl, json=payload, headers=headers)
popup = Popup(title="TD", content=Label(text=str(r.json())))
popup.open()
ID
1040
Category
Integration/API
Author

james whitaker
Date Created
8/25/2016 9:12:11 AM
Date Updated
8/25/2016 9:08:35 PM
Comments
james whitaker 8/25/2016 10:26:01 AM
Whoops! Forgot to escape the '%'. Rookie error... This can be deleted
james whitaker 8/25/2016 10:30:12 AM
Although while I'm here, what could I be doing wrong here?

{u'source': u'content', u'message': u'Error converting value "[{\'PR ID\': \'4530API TEST\', \'Department\': \'TMRP\', \'Justification\': \'Whatever\', \'Description\': \'Testing\', \'Mission\': \'Chuuk\'}]" to type \'ForeSoft.TeamDesk.API.v2.DataSetRequest\'. Path \'\', line 1, position 126.', u'code': 2002, u'error': 400}

Kirill Bondar  Staff  8/25/2016 7:11:38 PM
@James: with python 3.4.3 and requests 2.11.1 the following works (try it):

import requests
payload = [ { "Text": "Python", "Date": "2016-12-31" } ]
tdurl = "https://www.teamdesk.net/secure/api/v2/21995/Test/upsert.json"
headers = { "Content-type": "application/json" }
auth = ( "test@test.com", "pwd" )
r = requests.post(tdurl, json=payload, headers=headers, auth=auth)
james whitaker 8/25/2016 9:08:35 PM
Thanks, it works!
Feedback
Back to Search Results