1
+ import sys
2
+ import os
3
+ import json
4
+
5
+ sys .path .append (os .path .dirname (os .path .dirname (__file__ )))
6
+
7
+ import asana
8
+ from six import print_
9
+
10
+ # Instructions
11
+ #
12
+ # 1. Set your ASANA_ACCESS_TOKEN environment variable to a Personal Access Token obtained in your Asana Account Settings
13
+ #
14
+ # This simple script asks the user to choose from their available Workspaces and then the first page (if more than a
15
+ # single page exists) of available projects in order to create a task in that project.
16
+ #
17
+
18
+ def user_select_option (message , options ):
19
+ option_lst = list (options )
20
+ print_ (message )
21
+ for i , val in enumerate (option_lst ):
22
+ print_ (i , ': ' + val ['name' ])
23
+ index = int (input ("Enter choice (default 0): " ) or 0 )
24
+ return option_lst [index ]
25
+
26
+
27
+ if 'ASANA_ACCESS_TOKEN' in os .environ :
28
+ # create a client with a Personal Access Token
29
+ client = asana .Client .access_token (os .environ ['ASANA_ACCESS_TOKEN' ])
30
+ workspaces = client .workspaces .find_all ()
31
+
32
+ workspace = user_select_option ("Please choose a workspace" , workspaces )
33
+
34
+ projects = client .projects .find_all ({'workspace' : workspace ['id' ]})
35
+
36
+ project = user_select_option ("Please choose a project" , projects )
37
+
38
+ result = client .tasks .create_in_workspace (workspace ['id' ],
39
+ {'name' : 'Learn to use Nunchucks' ,
40
+ 'notes' : 'Note: This is a test task created with the python-asana client.' ,
41
+ 'projects' : [project ['id' ]]})
42
+
43
+ print_ (json .dumps (result , indent = 4 ))
0 commit comments