API Recipes
Advanced TaskRouter Setup
This recipe was an interactive walkthrough in the previous portal. Each step below names the API call it makes; open it in the API Reference to try it.
Overview
Advanced TaskRouter Workforce Setup
This recipe improves upon basic workspace creation by chaining dependencies. It dynamically fetches the necessary Activity SID (which is required to create a worker) instead of hardcoding it, making the flow completely self-contained and robust.
🚀 Flow Overview
- Create Workspace: Initialize a new container for your task routing (e.g., 'Customer Support').
- Fetch Offline Activity: Retrieve the list of activities to find the 'Offline' Activity SID.
- Create Worker: Create a new worker (e.g., 'Alice') and assign them to the Offline activity.
🔗 API Endpoints Involved
- Create Workspace:
POST /v1/Workspaces - List Activities:
GET /v1/Workspaces/{WorkspaceSid}/Activities - Create Worker:
POST /v1/Workspaces/{WorkspaceSid}/Workers
⚠️ Prerequisites
- Twilio Account SID and Auth Token set in the environment.
Step 1: Create Workspace
Initialize a new container for your task routing (e.g., 'Customer Support').
API call: CreateWorkspace
Example arguments:
{
FriendlyName: `APIMatic Workspace ${Date.now()}`
}Step 2: Fetch Offline Activity
Retrieve the list of activities to find the 'Offline' Activity SID.
API call: ListActivity
Example arguments:
{
WorkspaceSid: workspaceSid,
FriendlyName: "Offline"
}Step 3: Create Worker
Create a new worker (e.g., 'Alice') and assign them to the Offline activity.
API call: CreateWorker
Example arguments:
{
WorkspaceSid: workspaceSid,
FriendlyName: `Alice ${Date.now()}`,
ActivitySid: activitySid,
Attributes: JSON.stringify({ roles: ["agent"], skills: ["support"] })
}