PATCH /tasks/{task_id} writes ticket changes back. A nightly job with GET /tasks catches anything either side missed.
Before you start
- Create a dedicated login for the integration, such as
integrations@yourcompany.com, on one team with the admin role. Create the API key from that login. See Authenticate. - Set up the webhook and store its secret on your server.
- Store
ANSWERING_AGENT_API_KEYandANSWERING_AGENT_WEBHOOK_SECRETas environment variables.
Create a ticket from each new task
Thetask.created webhook carries the task in data, the same object GET /tasks/{task_id} returns. It has the title, description, status, assignee, category, priority, customer, and source.
- Check the
X-Answering-Agent-Secretheader. See Check the secret. - Skip the event if you already processed its
id. - Respond with a
2xxstatus within 8 seconds. Do the rest after you respond. - Create the ticket from
data. Storedata.id, the API task ID, on the ticket.
createTicket stands for your ticket system’s own client. Store the task’s id, and store its status and assignee?.id as the last synced values.
Write ticket changes back
When someone changes a ticket’s status or assignee, send the change withPATCH /tasks/{task_id}. The values you read are the values you send. status is open, in_progress, on_hold, or done. assigned_to takes the same ID as a task’s assignee.id. Map these to your ticket system’s statuses and users in your own config. GET /account lists up to 50 members with their id and name.
Set expected_status to the status your sync last saw. If someone changed the task in the dashboard since then, the API returns 409 and changes nothing.
Always send assigned_to with a status change. Without it, in_progress, on_hold, and done can assign the task to the integration login, the same as a click in the dashboard.
POST /tasks/{task_id}/notes as content. Only your team sees the note. Each request adds a note, so send each comment once. Tasks from forms do not take notes.
Other errors to handle:
422(unprocessable) means the dashboard would refuse the same change. Theerrorsays why. If your team requires a note to mark a task done, add one withPOST /tasks/{task_id}/notesbefore you send"status": "done".404(not_found) on a task that belongs to a repeat conversation merged into an earlier one has anerrorthat names the task to update instead, such asThis conversation was merged into conversation-184519. Use that task.
Reconcile every night
A webhook event can be lost. For example, Answering Agent drops an event after its last retry fails, and it sends nothing while the webhook address is cleared. A nightly job fixes both. Page through every task that is not done. Create a ticket for any task you do not have. Search results leave outdescription, so read the full task first. Copy dashboard changes to tickets that differ.
findTicket, openTicketsNotIn, updateTicketFromTask, and saveTicket stand for your ticket system’s own client.
Each page of 50 tasks is one request, and each task you read again is one more. The API allows 120 requests per minute for each person. The helper above waits and retries on 429.