Skip to content

Commit 07db9ff

Browse files
committed
add create_task example
1 parent 3f718d4 commit 07db9ff

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

examples/example-create-task.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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))

examples/example-script.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
import json
66
from six import print_
77

8-
# API Key Instructions:
9-
#
10-
# 1. set your ASANA_API_KEY environment variable to the API key found in Asana Account Settings
11-
#
128
# OAuth Instructions:
139
#
1410
# 1. create a new application in your Asana Account Settings ("App" panel)
1511
# 2. set the redirect URL to "urn:ietf:wg:oauth:2.0:oob"
1612
# 3. set your ASANA_CLIENT_ID and ASANA_CLIENT_SECRET environment variables
13+
#
14+
# Personal Access Token Instructions:
15+
#
16+
# 1. set your ASANA_ACCESS_TOKEN environment variable to a Personal Access Token obtained in your Asana Account Settings
17+
#
1718

1819
if 'ASANA_CLIENT_ID' in os.environ:
1920
# create a client with the OAuth credentials:

0 commit comments

Comments
 (0)