メニュー

Expand
ページを評価:

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 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.

Let's Get Started!

Create a new Flow from a template

Start by creating a new Flow in Console. 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 Flow via the API

Fetch the newly created Flow via the API

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:

{
   "status" : "published",
   "friendly_name" : "My first flow",
   "sid" : "FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
   "revision" : 1,
   "date_updated" : null,
   "account_sid" : "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
   "errors" : [],
   "url" : "https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
   "date_created" : "2020-01-15T18:17:38Z",
   "links" : {
      "revisions" : "https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Revisions"
   },
   "commit_message" : null,
   "definition" : {
      "flags" : {
         "allow_concurrent_calls" : true
      },
      "initial_state" : "Trigger",
      "description" : "A New Flow",
      "states" : [
         {
            "properties" : {
               "offset" : {
                  "y" : 0,
                  "x" : 0
               }
            },
            "transitions" : [],
            "name" : "Trigger",
            "type" : "trigger"
         }
      ]
   },
   "valid" : true
}
Update the Flow via the REST API

Modify the Flow via the REST API

Add a simple 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:

...
{
  "next" : "say_play_1",
  "event" : "incomingCall"
}
...

Complete code example:

DEFINITION=$(cat << EOF
{
      "flags" : {
         "allow_concurrent_calls" : true
      },
      "description" : "A New Flow",
      "states" : [
         {
            "properties" : {
               "offset" : {
                  "x" : 0,
                  "y" : 0
               }
            },
            "name" : "Trigger",
            "type" : "trigger",
            "transitions" : [
               {
                  "event" : "incomingMessage"
               },
               {
                  "next" : "say_play_1",
                  "event" : "incomingCall"
               },
               {
                  "event" : "incomingRequest"
               }
            ]
         },
         {
            "transitions" : [
               {
                  "event" : "audioComplete"
               }
            ],
            "type" : "say-play",
            "properties" : {
               "loop" : 1,
               "say" : "Hello World",
               "offset" : {
                  "x" : 100,
                  "y" : 200
               }
            },
            "name" : "say_play_1"
         }
      ],
      "initial_state" : "Trigger"
   }
EOF
)

curl -X POST https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \
--data-urlencode "CommitMessage=First update" \
--data-urlencode "Definition=$DEFINITION" \
--data-urlencode "Status=published" \
-u ACCOUNT_SID:TOKEN

Pro Tip

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

View the Changes in Studio Canvas

Reload the Flow in Console to view the changes

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

That's It!

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.

ページを評価:

ヘルプが必要ですか?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Community Forums or browsing the Twilio tag on Stack Overflow.

        
        
        

        フィードバックくださりありがとうございます!

        We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        Refer us and get $10 in 3 simple steps!

        ステップ1

        Get link

        Get a free personal referral link here

        ステップ2:

        Give $10

        Your user signs up and upgrade using link

        ステップ3

        Get $10

        1,250 free SMSes
        OR 1,000 free voice mins
        OR 12,000 chats
        OR more