SUPPORT.TWILIO.COM END OF LIFE NOTICE: This site, support.twilio.com, is scheduled to go End of Life on February 27, 2024. All Twilio Support content has been migrated to help.twilio.com, where you can continue to find helpful Support articles, API docs, and Twilio blog content, and escalate your issues to our Support team. We encourage you to update your bookmarks and begin using the new site today for all your Twilio Support needs.

How to Create an Outbound Voice Flex Task Using the REST API

Objective

This article will guide you on how to create an outbound voice Flex tasks using the TaskRouter API.

Warning: When using TaskRouter standalone (without Flex), this API request will not automatically create a Voice Conference.

 

Product

Twilio Flex

 

Procedure 

Prerequisites

  • A Flex-enabled Twilio account.

  • A Workspace (WS…), Workflow (WW…), Task Queue (WQ…), and Voice TaskChannel in TaskRouter (Flex creates these by default).

  • A ready/available Worker (WK…) signed into Flex, or a TaskQueue SID (WQ...).

  • An owned/verified Twilio caller ID (the from number).

The cURL request

curl --location 'https://taskrouter.twilio.com/v1/Workspaces/WSXXXXX/Tasks' \
  -u ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:your_auth_token \
  --data-urlencode 'RoutingTarget=WKXXXXXX' \
  --data-urlencode 'Attributes={"outbound_to":"+1XXXXXXXX", "direction":"outbound", "from":"+1XXXXXXXX"}' \
  --data-urlencode 'TaskQueueSid=WQXXXX' \
  --data-urlencode 'WorkflowSid=WWXXXX' \
  --data-urlencode 'TaskChannel=voice' 

 

What each field does:

  • RoutingTarget=WK…
    Directs the Task to a specific Worker or Task Queue.

  • Attributes (JSON)

    • direction:"outbound" – lets Flex know this is an outbound call.

    • outbound_to:"+1…" – the destination phone number.

    • from:"+1…" – the caller ID / Twilio number to dial from.

  • TaskQueueSid=WQ…
    Queue used for the task (can be a general outbound queue).

  • WorkflowSid=WW…
    Workflow that will create a Reservation for the targeted Worker.

  • TaskChannel=voice
    Ensures the Task is created for the Voice channel.

 

Minimal REST example (Node.js)

const client = require('twilio')(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);

(async () => {
  const task = await client.taskrouter.v1
    .workspaces('WSXXXXX')
    .tasks
    .create({
      routingTarget: 'WKXXXXXX',
      attributes: JSON.stringify({
        outbound_to: '+1XXXXXXXX',
        direction: 'outbound',
        from: '+1XXXXXXXX'
      }),
      taskQueueSid: 'WQXXXX',
      workflowSid: 'WWXXXX',
      taskChannel: 'voice'
    });

  console.log('Created Task:', task.sid);
})();

 

Additional Information

Have more questions? Submit a request
Powered by Zendesk