Skip to contentSkip to navigationSkip to topbar
On this page

Interactions API



Base URL

base-url page anchor
https://flex-api.twilio.com/v1

The Flex API uses the same HTTP Basic Authentication as other Twilio APIs. Use your Twilio account SID as your username and your Auth Token as your password.



Example Request and Response

example-request-and-response page anchor

The following is an example of an agent-initiated interaction.

Request

request page anchor
Agent-initiated outbound SMSLink to code sample: Agent-initiated outbound SMS
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createInteraction() {
11
const interaction = await client.flexApi.v1.interaction.create({
12
channel: {
13
type: "sms",
14
initiated_by: "agent",
15
participants: [
16
{
17
address: "+13115552368",
18
proxy_address: "+192555512345",
19
},
20
],
21
},
22
routing: {
23
properties: {
24
workspace_sid: "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
25
workflow_sid: "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
26
queue_sid: "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
27
worker_sid: "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
28
task_channel_unique_name: "sms",
29
attributes: {
30
customerName: "silly name",
31
customerAddress: "+13115552368",
32
},
33
},
34
},
35
});
36
37
console.log(interaction.sid);
38
}
39
40
createInteraction();

Output

1
{
2
"sid": "KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"channel": {
4
"type": "sms",
5
"sid": "UOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
6
},
7
"routing": {
8
"reservation": null,
9
"properties": {
10
"date_updated": 1634845217,
11
"task_queue_entered_date": 1634845217,
12
"workflow_name": "Default Fifo Workflow",
13
"age_in_queue": 0,
14
"task_channel_unique_name": "default",
15
"assignment_status": "pending",
16
"queue_name": "Sample Queue",
17
"assignmentCounter": 0,
18
"priority": 0,
19
"sid": "WTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
20
"workflow_sid": "WWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
21
"routing_target": "WKaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
22
"reason": "",
23
"attributes": "{\"customerAddress\":\"customer phone address\",\"flexChannelInviteSid\":\"KGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"conversationSid\":\"CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"channelType\":\"sms\",\"customers\":{\"phone\":\"customer phone address\",\"name\":\"customer name\"},\"conversations\":{\"initiated_by\":\"customer\",\"conversation_id\":\"KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"media\":[{\"type\":\"ChatTranscript\",\"sid\":\"CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"}]},\"customerName\":\"customer name\",\"flexInteractionChannelSid\":\"UOaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"initiatedBy\":\"customer\",\"flexInteractionSid\":\"KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"direction\":\"inbound\"}",
24
"task_channel_sid": "TCaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
25
"age": 0,
26
"workspace_sid": "WSaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
27
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
28
"timeout": 86400,
29
"date_created": 1634845217,
30
"addons": "{}",
31
"queue_sid": "WQaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
32
}
33
},
34
"interaction_context_sid": null,
35
"url": "https://flex-api.twilio.com/v1/Interactions/KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
36
"links": {
37
"channels": "https://flex-api.twilio.com/v1/Interactions/KDaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels"
38
}
39
}
1
{
2
"url": "https://https://flex-api.twilio.com//v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"routing": {
4
"reservation": null,
5
"properties": {
6
"date_updated": 1637013849,
7
"task_queue_entered_date": 1637013849,
8
"workflow_name": "Assign to Anyone",
9
"age_in_queue": 0,
10
"task_channel_unique_name": "sms",
11
"assignment_status": "pending",
12
"queue_name": "Everyone",
13
"assignmentCounter": 0,
14
"priority": 0,
15
"sid": "WTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
16
"workflow_sid": "WWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
17
"routing_target": "WKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
18
"reason": null,
19
"attributes": "{\"customerAddress\":\"+1311-555-2368\",\"flexChannelInviteSid\":\"KGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"conversationSid\":\"CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"channelType\":\"sms\",\"conversations\":{\"initiated_by\":\"Agent\",\"communication_channel\":\"Sms\",\"media\":[{\"conversation_sid\":\"CHXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\"}],\"direction\":\"Outbound\"},\"customerName\":\"silly name\",\"flexInteractionChannelSid\":\"UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\"initiatedBy\":\"agent\",\"direction\":\"outbound\"}",
20
"task_channel_sid": "TCXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
21
"age": 0,
22
"workspace_sid": "WSXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
23
"account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
24
"timeout": 86400,
25
"date_created": 1637013849,
26
"addons": "{}",
27
"queue_sid": "WQXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
28
}
29
},
30
"channel": {
31
"type": "sms",
32
"sid": "UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
33
},
34
"sid": "KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
35
"links": {
36
"channels": "https://https://flex-api.twilio.com/v1/Interactions/KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Channels"
37
}
38
}

The following table lists a set of "well known" attributes that are consumed by the Flex UI and/or Flex Insights.

AttributeDescriptionExample
customerNameFor Insights, it is used to populate conversations.customers.name.

In the Flex UI, it is rendered as the main customer's name for an email task.
Al Fresco
customerAddressFor Insights, it is used to populate conversations.customers.email or conversations.customers.phone.

In the Flex UI, it is rendered as the main customer's email address for an email task.
+192522212345 or

alfresco@aol.com
fromThis is the Flex UI's preferred attribute for identifying the customer on non-email tasks. For email tasks, it uses customerName.Al Fresco, +19251235555
subjectIn the Flex UI, it is rendered as the initial subject of an email thread task.Issue with shoes
flexInteractionChannelSidUsed in the Flex UI to identify whether a task is interaction-based or not and therefore whether there is a need for Flex UI orchestration or not.UOXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
flexInteractionSidThe interaction SIDKDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
flexChannelInviteSidThe invite SIDKGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
followed_byUsed for external warm transfers
outcomeUsed for external warm transfers
customersThis object is automatically added if customerAddress and customerName are provided.

This object contains the name, phone, and email of a single customer.

name [required]: The display name of the customer. If name is not available, it must be set to null

phone [required]: The phone number or WhatsApp number of the customer. If number is not available, it should be set to null

email [required]: The email address of the customer. If no email address is available, it should be set to null
"customers": {

"name": "Al Fresco",

"Phone": "+19252148887",

"email": null

}

The following attributes are added when the channel is created (asynchronously):

AttributeDescriptionExample
conversations.external_contact

(This is the Conversation projected address)
For Insights, this is the contact address the customer used to reach you or the contact address from which you have reached them. This may be an inbound support phone number, your support email, or a phone number that appears on the customer's phone when you call them.

The contact information (email, phone) that the customer uses or sees when communicating with the contact center can be used for traffic segmentation.
help@example.com

Task Attributes mapped from Channel Attributes

task-attributes-mapped-from-channel-attributes page anchor

Some interaction request channel attributes are also used to create other task attributes. The following table lists those task attributes that are created from the given channel attributes:

Interaction Channel AttributeTask Attribute(s)Values
typeconversations.media.type (Insights)

For all conversation media types
ChatTranscript
conversations.communication_channel (Insights)Email, SMS, Whatsapp, Web, Chat
channelType (FlexUI)

The Flex UI uses this to identify tasks that have the same "uniqueTaskChannelName" as chat, but have to be treated differently, e.g. whatsapp, sms.
email, sms, whatsapp, web, chat, messenger, gbm
initiated_bydirection (Flex UI)

When initiated_by is set to "agent", this value is outbound, otherwise it's inbound.
customer | api | agent
properties.media_channel_sidconversations.conversation_id (Insights)KDXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
conversations.media.sid (Insights)
conversationSid (Flex UI)

The following table captures the reason for requiring these attributes:

Flex Insights attributesHow/why is it used
conversations.media.typeExample of the entire media object with attached chat transcript
conversations.initiated_byFlex Insights: Used to identify how the conversation was initiated. This helps to identify funnels leading towards a conversation.
conversations.external_contactFlex Insights: The contact address the customer used to reach you or the contact address from which you have reached them. This may be an inbound support phone number, your support email, or a phone number that appears on the customer's phone when you call them.

Useful for segmenting traffic by contact information (email, phone)
conversations.conversation_id

conversations.media.sid
The ID of the conversation used for Historical insights. The Media SID is used to get access to the transcripts.

Some common errors you may encounter include Error 20003 and Error 11200. See the Twilio Error and Warning Dictionary for a list of potential errors.

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.