https://support.teamgantt.com/article/132-teamgantt-api
Note that "Bearer" is required at the beginning of the bearer token! (One space is included)
Press the Body tab and replace user and pass with your own.
If successful, Response will be in the 200s. If it is in the 400s, it is an error, so please review the settings.
The strings api_key and user_token are returned in Response Body, so make a note of them.
You can test your API on the API Reference page. Using the API GetList for tasks as an example, I will explain the procedure for getting the task list for your day.
Select Task ⇒ Tasks from the heading on the left and press Get List. The window on the right is ready to try the __ / tasks? Today__ command.
Next, add __bearer token, user token, API key __ to the URL header.
Press Headers and then Add new header to enter the item name and value.
item | 入力するitem名 | Description of the value to enter |
---|---|---|
Bearer token | TG-Authorization | 取得したBearer tokenの先頭に"Bearer "Add |
API key | TG-Api-Key | Create Sessionで取得したAPI key |
User token | TG-User-Token | Create Sessionで取得したUser token |
The screen like ↓ is displayed when the above three are set as Header. If you press Call Resource and Response 200 series is returned, it is OK.
With the above procedure, you can try the API in the API document on your browser.
__ API headers can be pinned! __ You can pin it by moving the mouse cursor to the right side of the input box. If you pin it, you don't have to enter the header every time you change the API command, which is easy.
The TeamGant API documentation also has a Python example. Here's an example I've tried.
# -*- coding: utf-8 -*-
import urllib.request
import codecs
import json
########################################################################
# TeamGant
########################################################################
class TeamGant():
'''
constructor
'''
def __init__(self):
self.APIheader={'TG-Authorization':'Bearer <Own bearer token>'
,'TG-Api-Key' :'<Own API key>'
,'TG-User-Token' :'<Own user token>'
}
self.UrlBase = 'https://api.teamgantt.com/v1/'
'''
Make a request to TeamGant
Argument ApiCmd: API command(Mandatory)
Argument iSaveName: File name specified when you want to write the result to a json file Body
'''
def _gatTGjson(self, ApiCmd="",iSaveName=""):
__request = urllib.request.Request(self.UrlBase + ApiCmd, headers=self.APIheader)
__response = urllib.request.urlopen(__request)
__json = __response.read().decode("utf-8")
if not len(iSaveName) == 0:
print(__json, file=codecs.open('./' + iSaveName + '.json' , mode='w')) #Export
return __json
'''
Get today's task
'''
def GetTodayTask(self):
cmd='tasks?today' #Today's task
return self._gatTGjson(cmd, 'TaskToday')
########################################################################
#Main function
########################################################################
if __name__ == '__main__':
tg = TeamGant() #Create a TeamGant class
js = tg.GetTodayTask() #Execute the method to get today's task and receive json
json_dict = json.loads(js) #Make the received json a dictionary type
Recommended Posts