Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Execution


An Execution represents a specific person's run through a Flow. An Execution is active while the user is in the Flow, and it is considered ended when they stop responding to messages or hang up their call.

The Execution resource can be used to retrieve information about existing Executions or to create new Executions for outbound use cases (e.g. surveys, appointment reminders).

Subscribe to Real-time Studio Events

You can now subscribe to Studio Events for Executions and Steps instead of polling via the REST API. Simplify your data ingestion with Event Streams for Studio.

Try Studio Events(link takes you to an external page)

Create an Execution to Trigger a Flow

create-an-execution-to-trigger-a-flow page anchor

To trigger a new Execution of your Flow via the REST API, make an HTTP POST request to:

https://studio.twilio.com/v2/Flows/{FlowSid}/Executions

(warning)

Warning

Studio Rate Limits
Be sure to review Studio's rate limits when building your application.

Required Parameters

ParameterDescription
ToThe Contact phone number (or other identifier) to start a Studio Flow Execution, available as variable {{contact.channel.address}}
FromThe Twilio phone number (or other identifier such as a SID of a Messaging Service) to send messages or initiate calls from during the Flow Execution, available as variable {{flow.channel.address}}

Important: If you are using a phone number as an identifier, make sure to format the To / From phone numbers as E.164 (e.g. +1xxxxxxxxxx) to ensure a Contact's session is tracked correctly. Only one Execution can be active at a time for the same To/From combination.

Optional Parameters

ParameterDescription
ParametersJSON data that will be added to your flow's context and can be accessed as variables inside your flow. For example, if you pass in Parameters={"name":"Zeke"}, then inside a widget you can reference the variable {{flow.data.name}}, which will return the string "Zeke". Note: At the HTTP layer, the JSON parameter must be explicitly passed as a URL encoded string. However, the Twilio Helper Libraries accept a native object and automatically serialize and encode the JSON string for you.

Quick Example

quick-example page anchor

Here is a quick example of creating an Execution via the REST API using the Twilio Node.js Helper Library(link takes you to an external page):


_11
const client = require('twilio')(accountSid, authToken);
_11
_11
client.studio.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
_11
.executions
_11
.create({
_11
to: '+15558675310',
_11
from: '+15017122661',
_11
parameters: {
_11
name: 'Zeke'
_11
}})
_11
.then(execution => console.log(execution.sid));

(warning)

Warning

Important: When triggering flows with the API, don't forget to also configure your phone number (or other identifier) with your Studio Flow! If you don't configure the phone number, users won't be able to reply to your messages or interact with your IVR.

See the following for examples:

Additionally, if a number is configured with a Messaging Service, be sure to use the Messaging Service identifier as the From identifier so that users can reply to your messages, and ensure that your Messaging Service inbound settings are configured to point to the webhook urlfrom your Twilio Studio Flow.


Property nameTypePIIDescription
sidSID<FN>
Not PII

The unique string that we created to identify the Execution resource.

Pattern: ^FN[0-9a-fA-F]{32}$Min length: 34Max length: 34

account_sidSID<AC>

The SID of the Account that created the Execution resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

flow_sidSID<FW>

The SID of the Flow.

Pattern: ^FW[0-9a-fA-F]{32}$Min length: 34Max length: 34

contact_channel_addressstring
PII MTL: 30 days

The phone number, SIP address or Client identifier that triggered the Execution. Phone numbers are in E.164 format (e.g. +16175551212). SIP addresses are formatted as name@company.com. Client identifiers are formatted client:name.


contextobject

The current state of the Flow's Execution. As a flow executes, we save its state in this context. We save data that your widgets can access as variables in configuration fields or in text areas as variable substitution.


statusenum<string>

The status of the Execution. Can be: active or ended.

Possible values:
activeended

date_createdstring<date-time>

The date and time in GMT when the resource was created specified in ISO 8601(link takes you to an external page) format.


date_updatedstring<date-time>

The date and time in GMT when the resource was last updated specified in ISO 8601(link takes you to an external page) format.


urlstring<uri>

The absolute URL of the resource.


linksobject<uri-map>

The URLs of nested resources.


POST https://studio.twilio.com/v2/Flows/{FlowSid}/Executions

Creating a new Execution will attempt to trigger a new Studio flow between two contacts.

(warning)

Handling Conflicting Executions: New Behavior in v2

If you attempt to create an Execution using v2 of this API and we find there is an active Execution for the same To/From combination, the API will return an error with the 409 Conflict HTTP status. This error response will provide a reference to the existing Execution SID so you can end it, if appropriate, and try your Create request again.

Example error response:


_10
{
_10
"code": 20409,
_10
"details": {
_10
"conflicting_execution_sid": "FNf11d38169ef8920ae5e2b10acbb0374d"
_10
},
_10
"message": "Execution FNf11d38169ef8920ae5e2b10acbb0374d is already active for this contact. End the active Execution before creating a new one",
_10
"more_info": "https://www.twilio.com/docs/errors/20409",
_10
"status": 409
_10
}

If we are able to create a new Execution with your To/From information, the API will return the 201 Created HTTP status.

If you're still using v1 of this API, creating an Execution where one is already active will not create a new Execution or return an error, and will instead always return a 200 OK code with the existing active Execution.

Property nameTypeRequiredPIIDescription
FlowSidSID<FW>required

The SID of the Excecution's Flow.

Pattern: ^FW[0-9a-fA-F]{32}$Min length: 34Max length: 34
Property nameTypeRequiredPIIDescription
Tostring<phone-number>required

The Contact phone number to start a Studio Flow Execution, available as variable {{contact.channel.address}}.


Fromstring<phone-number>required

The Twilio phone number to send messages or initiate calls from during the Flow's Execution. Available as variable {{flow.channel.address}}. For SMS, this can also be a Messaging Service SID.


ParametersobjectOptional

JSON data that will be added to the Flow's context and that can be accessed as variables inside your Flow. For example, if you pass in Parameters={"name":"Zeke"}, a widget in your Flow can reference the variable {{flow.data.name}}, which returns "Zeke". Note: the JSON value must explicitly be passed as a string, not as a hash object. Depending on your particular HTTP library, you may need to add quotes or URL encode the JSON string.

Create Execution

create-execution page anchor
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_21
// Download the helper library from https://www.twilio.com/docs/node/install
_21
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_21
_21
// Find your Account SID and Auth Token at twilio.com/console
_21
// and set the environment variables. See http://twil.io/secure
_21
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_21
const authToken = process.env.TWILIO_AUTH_TOKEN;
_21
const client = twilio(accountSid, authToken);
_21
_21
async function createExecution() {
_21
const execution = await client.studio.v2
_21
.flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_21
.executions.create({
_21
from: "+15017122661",
_21
to: "+15558675310",
_21
});
_21
_21
console.log(execution.sid);
_21
}
_21
_21
createExecution();

Output

_15
{
_15
"url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"sid": "FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"flow_sid": "FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_15
"context": {},
_15
"contact_channel_address": "+18001234567",
_15
"status": "active",
_15
"date_created": "2015-07-30T20:00:00Z",
_15
"date_updated": "2015-07-30T20:00:00Z",
_15
"links": {
_15
"steps": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps",
_15
"execution_context": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Context"
_15
}
_15
}

Create an Execution with custom parameters

create-an-execution-with-custom-parameters page anchor

Create a new Execution with JSON data to be added to your flow's context. You will be able to access these parameters as variables inside your Studio flow.

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_24
// Download the helper library from https://www.twilio.com/docs/node/install
_24
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_24
_24
// Find your Account SID and Auth Token at twilio.com/console
_24
// and set the environment variables. See http://twil.io/secure
_24
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_24
const authToken = process.env.TWILIO_AUTH_TOKEN;
_24
const client = twilio(accountSid, authToken);
_24
_24
async function createExecution() {
_24
const execution = await client.studio.v2
_24
.flows("FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_24
.executions.create({
_24
from: "+14155552344",
_24
parameters: {
_24
foo: "bar",
_24
},
_24
to: "+14155552345",
_24
});
_24
_24
console.log(execution.sid);
_24
}
_24
_24
createExecution();

Output

_15
{
_15
"url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"sid": "FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"flow_sid": "FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"context": {},
_15
"contact_channel_address": "+18001234567",
_15
"status": "active",
_15
"date_created": "2015-07-30T20:00:00Z",
_15
"date_updated": "2015-07-30T20:00:00Z",
_15
"links": {
_15
"steps": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps",
_15
"execution_context": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Context"
_15
}
_15
}


Fetch a single execution

fetch-a-single-execution page anchor
GET https://studio.twilio.com/v2/Flows/{FlowSid}/Executions/{Sid}

Property nameTypeRequiredPIIDescription
FlowSidSID<FW>required

The SID of the Flow with the Execution resource to fetch

Pattern: ^FW[0-9a-fA-F]{32}$Min length: 34Max length: 34

SidSID<FN>required

The SID of the Execution resource to fetch.

Pattern: ^FN[0-9a-fA-F]{32}$Min length: 34Max length: 34
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_19
// Download the helper library from https://www.twilio.com/docs/node/install
_19
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19
_19
// Find your Account SID and Auth Token at twilio.com/console
_19
// and set the environment variables. See http://twil.io/secure
_19
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19
const authToken = process.env.TWILIO_AUTH_TOKEN;
_19
const client = twilio(accountSid, authToken);
_19
_19
async function fetchExecution() {
_19
const execution = await client.studio.v2
_19
.flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_19
.executions("FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_19
.fetch();
_19
_19
console.log(execution.sid);
_19
}
_19
_19
fetchExecution();

Output

_15
{
_15
"sid": "FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_15
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"flow_sid": "FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_15
"contact_channel_address": "+14155555555",
_15
"status": "ended",
_15
"context": {},
_15
"date_created": "2017-11-06T12:00:00Z",
_15
"date_updated": null,
_15
"url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"links": {
_15
"steps": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps",
_15
"execution_context": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Context"
_15
}
_15
}


Read a list of executions

read-a-list-of-executions page anchor
GET https://studio.twilio.com/v2/Flows/{FlowSid}/Executions

Execution resources are listed in reverse chronological order (most recent is first).

Property nameTypeRequiredPIIDescription
FlowSidSID<FW>required

The SID of the Flow with the Execution resources to read.

Pattern: ^FW[0-9a-fA-F]{32}$Min length: 34Max length: 34
Property nameTypeRequiredPIIDescription
DateCreatedFromstring<date-time>Optional

Only show Execution resources starting on or after this ISO 8601(link takes you to an external page) date-time, given as YYYY-MM-DDThh:mm:ss-hh:mm.


DateCreatedTostring<date-time>Optional

Only show Execution resources starting before this ISO 8601(link takes you to an external page) date-time, given as YYYY-MM-DDThh:mm:ss-hh:mm.


PageSizeintegerOptional

How many resources to return in each list page. The default is 50, and the maximum is 1000.

Minimum: 1Maximum: 1000

PageintegerOptional

The page index. This value is simply for client state.

Minimum: 0

PageTokenstringOptional

The page token. This is provided by the API.

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_18
// Download the helper library from https://www.twilio.com/docs/node/install
_18
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_18
_18
// Find your Account SID and Auth Token at twilio.com/console
_18
// and set the environment variables. See http://twil.io/secure
_18
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_18
const authToken = process.env.TWILIO_AUTH_TOKEN;
_18
const client = twilio(accountSid, authToken);
_18
_18
async function listExecution() {
_18
const executions = await client.studio.v2
_18
.flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_18
.executions.list({ limit: 20 });
_18
_18
executions.forEach((e) => console.log(e.sid));
_18
}
_18
_18
listExecution();

Output

_12
{
_12
"meta": {
_12
"previous_page_url": null,
_12
"next_page_url": null,
_12
"url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions?PageSize=50&Page=0",
_12
"page": 0,
_12
"first_page_url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions?PageSize=50&Page=0",
_12
"page_size": 50,
_12
"key": "executions"
_12
},
_12
"executions": []
_12
}

Read Executions Filtered by Date

read-executions-filtered-by-date page anchor

Executions can be filtered by the date they were created (30-day max range).

Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_22
// Download the helper library from https://www.twilio.com/docs/node/install
_22
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_22
_22
// Find your Account SID and Auth Token at twilio.com/console
_22
// and set the environment variables. See http://twil.io/secure
_22
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_22
const authToken = process.env.TWILIO_AUTH_TOKEN;
_22
const client = twilio(accountSid, authToken);
_22
_22
async function listExecution() {
_22
const executions = await client.studio.v2
_22
.flows("FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
_22
.executions.list({
_22
dateCreatedFrom: new Date("2019-02-17 00:00:00"),
_22
dateCreatedTo: new Date("2019-02-18 00:00:00"),
_22
limit: 20,
_22
});
_22
_22
executions.forEach((e) => console.log(e.sid));
_22
}
_22
_22
listExecution();

Output

_12
{
_12
"meta": {
_12
"previous_page_url": null,
_12
"next_page_url": null,
_12
"url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions?PageSize=50&Page=0",
_12
"page": 0,
_12
"first_page_url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions?PageSize=50&Page=0",
_12
"page_size": 50,
_12
"key": "executions"
_12
},
_12
"executions": []
_12
}


POST https://studio.twilio.com/v2/Flows/{FlowSid}/Executions/{Sid}

An active Execution can be updated to ended using the REST API. Once ended, subsequent widgets in the Flow are not processed, and any new events that Studio receives for that Execution are rejected.

(information)

Info

Attempting to end an Execution that is already in the ended state will fail with a 409 Conflict.

Property nameTypeRequiredPIIDescription
FlowSidSID<FW>required

The SID of the Flow with the Execution resources to update.

Pattern: ^FW[0-9a-fA-F]{32}$Min length: 34Max length: 34

SidSID<FN>required

The SID of the Execution resource to update.

Pattern: ^FN[0-9a-fA-F]{32}$Min length: 34Max length: 34
Property nameTypeRequiredPIIDescription
Statusenum<string>required

The status of the Execution. Can only be ended.

Possible values:
activeended
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_19
// Download the helper library from https://www.twilio.com/docs/node/install
_19
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_19
_19
// Find your Account SID and Auth Token at twilio.com/console
_19
// and set the environment variables. See http://twil.io/secure
_19
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_19
const authToken = process.env.TWILIO_AUTH_TOKEN;
_19
const client = twilio(accountSid, authToken);
_19
_19
async function updateExecution() {
_19
const execution = await client.studio.v2
_19
.flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_19
.executions("FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_19
.update({ status: "ended" });
_19
_19
console.log(execution.sid);
_19
}
_19
_19
updateExecution();

Output

_15
{
_15
"url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"sid": "FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_15
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
_15
"flow_sid": "FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
_15
"context": {},
_15
"contact_channel_address": "+14155555555",
_15
"status": "ended",
_15
"date_created": "2017-11-06T12:00:00Z",
_15
"date_updated": "2017-11-06T12:00:00Z",
_15
"links": {
_15
"steps": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps",
_15
"execution_context": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Context"
_15
}
_15
}


DELETE https://studio.twilio.com/v2/Flows/{FlowSid}/Executions/{Sid}

Property nameTypeRequiredPIIDescription
FlowSidSID<FW>required

The SID of the Flow with the Execution resources to delete.

Pattern: ^FW[0-9a-fA-F]{32}$Min length: 34Max length: 34

SidSID<FN>required

The SID of the Execution resource to delete.

Pattern: ^FN[0-9a-fA-F]{32}$Min length: 34Max length: 34
Node.js
Python
C#
Java
Go
PHP
Ruby
twilio-cli
curl

_17
// Download the helper library from https://www.twilio.com/docs/node/install
_17
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
_17
_17
// Find your Account SID and Auth Token at twilio.com/console
_17
// and set the environment variables. See http://twil.io/secure
_17
const accountSid = process.env.TWILIO_ACCOUNT_SID;
_17
const authToken = process.env.TWILIO_AUTH_TOKEN;
_17
const client = twilio(accountSid, authToken);
_17
_17
async function deleteExecution() {
_17
await client.studio.v2
_17
.flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_17
.executions("FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
_17
.remove();
_17
}
_17
_17
deleteExecution();


Rate this page: