I have a form that when submitting it will create a task in a project in Asana.
I want this to be able to create the task under the section “billing” in the project called “work”.
How do I get this task to be created in that project, but under a specific section ?
I have different options in my form that should make this be put under the correct section in the project.
hi @Frederic_Malenfant I’m having trouble creating a task below a section in a single posting, I was searching the forum and came across your post, I tried using your suggestion but it didn’t work!
I created a script in python as below
import requests
import json
# replace with your actual Asana token
asana_token = 'insert token'
headers = {
'Authorization': f'Bearer {asana_token}',
'Content-Type': 'application/json'
}
# Define the data payload
data = {
"assignee": "132064102866", # replace with the actual assignee ID
"completed": False,
"followers": [
"209184463753" # replace with actual follower IDs
],
"name": "Teste API Section",
"notes": "teste api",
# Adding project to projects array as well
"projects": ["705582290015520"],
"memberships": [
{
"project": "705582290015520", # replace with the actual project ID
"section": "1138893254883204" # replace with the actual section ID
}
],
"resource_subtype": "default_task",
"start_on": "2023-08-06",
"workspace": "132064102865" # replace with the actual workspace ID
}
# Make the POST request
response = requests.post(
'https://app.asana.com/api/1.0/tasks', headers=headers, json=data)
# Check if the request was successful
if response.status_code == 201:
print(
f"Task created successfully. Task ID: {response.json()['data']['gid']}")
else:
print(f"Failed to create task. Response: {response.text}")
def createTask(name, workspaceID, projectID, sectionID, assignee=None, followers=None, due_on=None):
memberships = [{‘project’: projectID, ‘section’: sectionID}]
data = {
‘data’: {
‘name’: name,
‘workspace’: workspaceID,
‘memberships’: memberships,
‘assignee’: assignee,
# If followers is None, pass an empty list
‘followers’: followers if followers else ,
‘due_on’: due_on
}
}
r = requests.post(base_url + ‘tasks’, headers=headers, json=data)
if r.status_code != 201:
s = ‘Creation of task with name ’ + name + ’ failed:’
raise ValueError(s, r.json())
else:
print(f"Task created successfully. Task ID: {r.json()[‘data’][‘gid’]}")
Call the function with your parameters
createTask(
name=“Teste API Section”,
workspaceID=“132064102865”,
projectID=“705582290015520”,
sectionID=“1138893254883204”,
assignee=“132064102866”,
followers=[“209184463753”], # This can be a list of followers
due_on=“2023-08-06”
)