-
Notifications
You must be signed in to change notification settings - Fork 11
Public API: Complete a Task
Isaiah Fisher edited this page Dec 17, 2024
·
1 revision
You complete a task via API by sending a POST request to this endpoint:
https://api.pneumatic.app/<workflow-id>/task-complete
Only the currently active task in a workflow can be completed. To do so you need to pass in the task-id, the performer id, along with data for the output fields you want filled out before the task is completed.
These are passed in as a json that looks like this:
{
'task_id':task_id,
'user_id':user_id,
'output': {
'output-field-1':'value',
'output-field-2:['selection-id-1', 'selection-id-2' ...],
'output-field-3: 'selection-id',
}
}
Thus, to complete a task, you need to know:
- the id of the workflow the task belongs to – you can look this up in Pneumatic
- the id of the task to complete – you can query the workflow for the id of the current task
- the API names of the output fields you want to fill out, along with the selection ids of the checkbox and radio button fields you'll be filling out – you can look these up on the API tab in the integrations section of your template
This is what it looks like in Python:
import requests
api_key = 'your_api_key'
headers = {
'Authorization': f'Bearer {api_key}',
}
workflow_id ='the id of the workflow you want to complete the curren task in'
workflow = requests.get(f"https://api.pneumatic.app/workflows/{workflow_id}", headers=headers).json()
task_id =workflow['current_task']['id']
user_id='the id of the user who will be completing the task(optiona)'
headers = {
'Authorization': f'Bearer {api_key}',
'Content-Type':'application/json'
}
data_and_outputs ={
'task_id':task_id,
'user_id':user_id,
'output': {
'output-field-1':'value',
'output-field-2:['selection-id-1', 'selection-id-2' ...],
'output-field-3: 'selection-id',
}
}
json_data = json.dumps(data_and_outputs)
r = requests.post(
f'https://api.pneumatic.app/workflows/{workflow_id}/task-complete',
headers=headers,
data = json_data
)
If the task's been successfully completed you just get a 200 code in response, otherwise you get a json describing what went wrong(or at least trying to describe what went wrong).