Skip to contentSkip to navigationSkip to topbar
On this page

Studio Flows API Quickstart


The quickest way to get started with the Studio Flows API is to create a Flow using the Studio Canvas in Console(link takes you to an external page) and then use the Flows API to fetch and update the Flow's JSON Definition.

Note: The examples in this quickstart use cURL, but complete code samples for the Twilio Helper Libraries and the Twilio CLI are available in the Studio REST API v2 docs.


Create a new Flow from a template

create-a-new-flow-from-a-template page anchor

Start by creating a new Flow in Console(link takes you to an external page). Select the Start from scratch template and click Next, which will automatically create and load a new blank Flow in the Studio Canvas.

Studio Template Picker.

Fetch the newly created Flow via the API

fetch-the-newly-created-flow-via-the-api page anchor

Use the Flow SID from the newly created Flow's URL to fetch the definition from the API.

Example using cURL:

curl https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX -u ACCOUNT_SID:TOKEN

Results:

1
{
2
"status" : "published",
3
"friendly_name" : "My first flow",
4
"sid" : "FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
5
"revision" : 1,
6
"date_updated" : null,
7
"account_sid" : "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
8
"errors" : [],
9
"url" : "https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
10
"date_created" : "2020-01-15T18:17:38Z",
11
"links" : {
12
"revisions" : "https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Revisions"
13
},
14
"commit_message" : null,
15
"definition" : {
16
"flags" : {
17
"allow_concurrent_calls" : true
18
},
19
"initial_state" : "Trigger",
20
"description" : "A New Flow",
21
"states" : [
22
{
23
"properties" : {
24
"offset" : {
25
"y" : 0,
26
"x" : 0
27
}
28
},
29
"transitions" : [],
30
"name" : "Trigger",
31
"type" : "trigger"
32
}
33
]
34
},
35
"valid" : true
36
}
37

Modify the Flow via the REST API

modify-the-flow-via-the-rest-api page anchor

Add a Say/Play Widget to the definition and run a Flow update command.

To connect the Say/Play Widget, add its JSON as a new item in the states array, and set the Widget's friendly name to the next property of the Trigger's incomingCall transition:

1
...
2
{
3
"next" : "say_play_1",
4
"event" : "incomingCall"
5
}
6
...

Complete code example:

1
DEFINITION=$(cat << EOF
2
{
3
"flags" : {
4
"allow_concurrent_calls" : true
5
},
6
"description" : "A New Flow",
7
"states" : [
8
{
9
"properties" : {
10
"offset" : {
11
"x" : 0,
12
"y" : 0
13
}
14
},
15
"name" : "Trigger",
16
"type" : "trigger",
17
"transitions" : [
18
{
19
"event" : "incomingMessage"
20
},
21
{
22
"next" : "say_play_1",
23
"event" : "incomingCall"
24
},
25
{
26
"event" : "incomingRequest"
27
}
28
]
29
},
30
{
31
"transitions" : [
32
{
33
"event" : "audioComplete"
34
}
35
],
36
"type" : "say-play",
37
"properties" : {
38
"loop" : 1,
39
"say" : "Hello World",
40
"offset" : {
41
"x" : 100,
42
"y" : 200
43
}
44
},
45
"name" : "say_play_1"
46
}
47
],
48
"initial_state" : "Trigger"
49
}
50
EOF
51
)
52
53
curl -X POST https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
54
--data-urlencode "CommitMessage=First update" \
55
--data-urlencode "Definition=$DEFINITION" \
56
--data-urlencode "Status=published" \
57
-u ACCOUNT_SID:TOKEN
58
(information)

Info

To import the Flow into another account or subaccount, just change the credentials to use the receiving account's Account SID and Token.


Reload the Flow in Console to view the changes

reload-the-flow-in-console-to-view-the-changes page anchor

Now that the Flow has been updated via the API, reload the Flow in the Studio Canvas to see the updated layout with the new Widget in place.

Simple Studio Flow.

Now you're ready to try some real world examples for your use case. Be sure to download the latest version of our server-side helper library for your language — or update your Twilio CLI — and explore the rest of the API.

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.