### Simple output examples Source: https://www.twilio.com/docs/studio/user-guide/liquid-template-language Shows basic output statements: variable, hash access, and string literal. ```liquid Hello {{name}} Hello {{user.name}} Hello {{ 'tobi' }} ``` -------------------------------- ### Filter usage examples Source: https://www.twilio.com/docs/studio/user-guide/liquid-template-language Demonstrates filters: upcase, size, and date with parameters. Filters can be chained. ```liquid Hello {{ 'tobi' | upcase }} Hello tobi has {{ 'tobi' | size }} letters! Hello {{ '*tobi*'| upcase }} Hello {{ 'now' | date: "%Y %h" }} ``` -------------------------------- ### Create an execution using shortcut syntax (v1 after upgrade) Source: https://www.twilio.com/docs/studio/rest-api/v2 This example shows the shortcut syntax without a version indicator. After upgrading to the latest SDK, this code will automatically reference the v2 API, which may be unexpected. ```javascript client.studio.flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') .executions .create({to: '+15558675310', from: '+15017122661'}) .then(execution => console.log(execution.sid)); ``` -------------------------------- ### GET /v1/Flows/{FlowSid}/Executions Source: https://www.twilio.com/docs/studio/rest-api/execution This snippet documents the GET endpoint for listing Executions in a Twilio Studio Flow. It includes the endpoint URL, parameters, request example, and response structure. ```APIDOC ## GET /v1/Flows/{FlowSid}/Executions ### Description Retrieves a list of Executions for a specific Flow. Supports pagination via the `PageSize` query parameter and can be filtered by date. ### Method GET ### Endpoint `https://studio.twilio.com/v1/Flows/{FlowSid}/Executions` ### Parameters #### Path Parameters - **FlowSid** (string) - Required - The SID of the Flow to retrieve executions for. #### Query Parameters - **PageSize** (integer) - Optional - The number of records to return per page. Default is 50. - **Page** (integer) - Optional - The page index to retrieve. ### Request Example ``` curl -X GET "https://studio.twilio.com/v1/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Executions?PageSize=20" \ -u $TWILIO_API_KEY:$TWILIO_API_SECRET ``` ### Response #### Success Response (200) - **meta** (object) - Pagination metadata including `previous_page_url`, `next_page_url`, `url`, `page`, `first_page_url`, `page_size`, and `key`. - **executions** (array) - List of Execution objects. Each execution contains a `sid` field. #### Response Example ```json { "meta": { "previous_page_url": null, "next_page_url": null, "url": "https://studio.twilio.com/v1/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions?PageSize=50&Page=0", "page": 0, "first_page_url": "https://studio.twilio.com/v1/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions?PageSize=50&Page=0", "page_size": 50, "key": "executions" }, "executions": [] } ``` ``` -------------------------------- ### Liquid for loop with limit and offset Source: https://www.twilio.com/docs/studio/user-guide/liquid-template-language Use limit and offset arguments to restrict which items are iterated. This example starts at the third item (offset:2) and takes two items (limit:2), resulting in 3 and 4. ```liquid # array = [1,2,3,4,5,6] {% for item in array limit:2 offset:2 %} {{ item }} {% endfor %} # results in 3,4 ``` -------------------------------- ### Create Studio Flow Execution with Parameters (C#, Java, Go, PHP) Source: https://www.twilio.com/docs/studio/rest-api/v2/execution Create a Studio Flow execution with parameters using the Twilio helper libraries. Each example initializes the client with API key and secret from environment variables, then calls the create method with the flow SID, To, From, and a parameters map containing "foo": "bar". The resulting execution SID is printed. ```csharp // Install the C# / .NET helper library from twilio.com/docs/csharp/install using System; using Twilio; using Twilio.Rest.Studio.V2.Flow; using System.Threading.Tasks; using System.Collections.Generic; class Program { public static async Task Main(string[] args) { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token string apiKey = Environment.GetEnvironmentVariable("TWILIO_API_KEY"); string apiSecret = Environment.GetEnvironmentVariable("TWILIO_API_SECRET"); string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); TwilioClient.Init(apiKey, apiSecret, accountSid); var execution = await ExecutionResource.CreateAsync( parameters: new Dictionary() { { "foo", "bar" } }, to: new Twilio.Types.PhoneNumber("+14155552345"), from: new Twilio.Types.PhoneNumber("+14155552344"), pathFlowSid: "FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); Console.WriteLine(execution.Sid); } } ``` ```java // Install the Java helper library from twilio.com/docs/java/install import com.twilio.type.PhoneNumber; import java.util.HashMap; import com.twilio.Twilio; import com.twilio.rest.studio.v2.flow.Execution; public class Example { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token public static final String API_KEY = System.getenv("TWILIO_API_KEY"); public static final String API_SECRET = System.getenv("TWILIO_API_SECRET"); public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID"); public static void main(String[] args) { Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID); Execution execution = Execution .creator("FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", new com.twilio.type.PhoneNumber("+14155552345"), new com.twilio.type.PhoneNumber("+14155552344")) .setParameters(new HashMap() { { put("foo", "bar"); } }) .create(); System.out.println(execution.getSid()); } } ``` ```go // Download the helper library from https://www.twilio.com/docs/go/install package main import ( "fmt" "github.com/twilio/twilio-go" studio "github.com/twilio/twilio-go/rest/studio/v2" "os" ) func main() { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token accountSid := os.Getenv("TWILIO_ACCOUNT_SID") apiKey := os.Getenv("TWILIO_API_KEY") apiSecret := os.Getenv("TWILIO_API_SECRET") client := twilio.NewRestClientWithParams(twilio.ClientParams{ Username: apiKey, Password: apiSecret, AccountSid: accountSid, }) params := &studio.CreateExecutionParams{} params.SetParameters(map[string]interface{}{ "foo": "bar", }) params.SetTo("+14155552345") params.SetFrom("+14155552344") resp, err := client.StudioV2.CreateExecution("FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", params) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { if resp.Sid != nil { fmt.Println(*resp.Sid) } else { fmt.Println(resp.Sid) } } } ``` ```php studio->v2 ->flows("FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") ->executions->create( "+14155552345", // To "+14155552344", // From [ "parameters" => [ "foo" => "bar", ], ], ); print $execution->sid; ``` -------------------------------- ### List Execution Steps in Go Source: https://www.twilio.com/docs/studio/rest-api/step Uses the Twilio Go helper library to list up to 20 steps for a given flow and execution. Requires TWILIO_ACCOUNT_SID, TWILIO_API_KEY, and TWILIO_API_SECRET environment variables. Prints each step's SID or an error message. ```go // Download the helper library from https://www.twilio.com/docs/go/install package main import ( "fmt" "github.com/twilio/twilio-go" studio "github.com/twilio/twilio-go/rest/studio/v1" "os" ) func main() { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token accountSid := os.Getenv("TWILIO_ACCOUNT_SID") apiKey := os.Getenv("TWILIO_API_KEY") apiSecret := os.Getenv("TWILIO_API_SECRET") client := twilio.NewRestClientWithParams(twilio.ClientParams{ Username: apiKey, Password: apiSecret, AccountSid: accountSid, }) params := &studio.ListExecutionStepParams{} params.SetLimit(20) resp, err := client.StudioV1.ListExecutionStep("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", params) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { for record := range resp { if resp[record].Sid != nil { fmt.Println(*resp[record].Sid) } else { fmt.Println(resp[record].Sid) } } } } ``` -------------------------------- ### List Studio Flows with twilio-cli and curl Source: https://www.twilio.com/docs/studio/rest-api/flow List Studio Flows using the twilio-cli command `twilio api:studio:v1:flows:list` and a raw curl GET request to the Studio API endpoint. The curl example uses the TWILIO_API_KEY and TWILIO_API_SECRET environment variables for basic authentication. ```bash # Install the twilio-cli from https://twil.io/cli twilio api:studio:v1:flows:list ``` ```bash curl -X GET "https://studio.twilio.com/v1/Flows?PageSize=20" \ -u $TWILIO_API_KEY:$TWILIO_API_SECRET ``` -------------------------------- ### Unless statement Source: https://www.twilio.com/docs/studio/user-guide/liquid-template-language The unless tag is the reverse of an if statement. This example is equivalent to the previous if user.name != 'tobi' example. Do not use elsif or else with unless. ```liquid # Same as above {% unless user.name == 'tobi' %} Hello non-tobi {% endunless %} ``` -------------------------------- ### Twilio Studio Flow JSON Example Source: https://www.twilio.com/docs/studio/rest-api/v2/flow Example JSON response for a Twilio Studio Flow resource, showing the structure with definition, states, transitions, and properties. ```json { "sid": "FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "author_sid": "USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "definition": { "description": "A New Flow", "states": [ { "name": "Trigger", "type": "trigger", "transitions": [ { "event": "incomingMessage" }, { "next": "say_play_1", "event": "incomingCall" }, { "event": "incomingRequest" } ], "properties": { "offset": { "x": 0, "y": 0 } } }, { "name": "say_play_1", "type": "say-play", "transitions": [ { "event": "audioComplete" } ], "properties": { "offset": { "x": 173, "y": 212 }, "loop": 1, "say": "Hello world" } } ], "initial_state": "Trigger", "flags": { "allow_concurrent_calls": true } }, "friendly_name": "Test Flow", "status": "published", "revision": 1, "commit_message": "Prod release v2", "valid": true, "errors": [], "warnings": [], "webhook_url": "http://webhooks.twilio.com/v1/Accounts/ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "date_created": "2017-11-06T12:00:00Z", "date_updated": "2017-11-06T12:00:00Z", "url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "links": { "test_users": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/TestUsers", "revisions": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions", "executions": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions" } } ``` -------------------------------- ### Fetch Execution Step - JSON Response Source: https://www.twilio.com/docs/studio/rest-api/v2/step Example JSON response returned when fetching a Studio execution step. Contains step details such as sid, flow_sid, execution_sid, name, context, and links. ```json { "sid": "FTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "flow_sid": "FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "execution_sid": "FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "name": "incomingRequest", "context": {}, "parent_step_sid": "FTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "transitioned_from": "Trigger", "transitioned_to": "Ended", "type": "trigger", "date_created": "2017-11-06T12:00:00Z", "date_updated": null, "url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps/FTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "links": { "step_context": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions/FNaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Steps/FTaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Context" } } ``` -------------------------------- ### Request body example for Update TestUser Source: https://www.twilio.com/docs/studio/rest-api/v2/test-user Example request body for updating test users. The TestUsers array contains the list of test user identities to update. ```json { "TestUsers": [ "user1", "user2" ] } ``` -------------------------------- ### Create Studio Execution in Go Source: https://www.twilio.com/docs/studio/rest-api/execution Uses the Twilio Go helper library to create a Studio execution. Requires TWILIO_API_KEY, TWILIO_API_SECRET, and TWILIO_ACCOUNT_SID environment variables. Prints the execution SID or an error message. ```go // Download the helper library from https://www.twilio.com/docs/go/install package main import ( "fmt" "github.com/twilio/twilio-go" studio "github.com/twilio/twilio-go/rest/studio/v1" "os" ) func main() { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token accountSid := os.Getenv("TWILIO_ACCOUNT_SID") apiKey := os.Getenv("TWILIO_API_KEY") apiSecret := os.Getenv("TWILIO_API_SECRET") client := twilio.NewRestClientWithParams(twilio.ClientParams{ Username: apiKey, Password: apiSecret, AccountSid: accountSid, }) params := &studio.CreateExecutionParams{} params.SetTo("+15558675310") params.SetFrom("+15017122661") resp, err := client.StudioV1.CreateExecution("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", params) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { if resp.Sid != nil { fmt.Println(*resp.Sid) } else { fmt.Println(resp.Sid) } } } ``` -------------------------------- ### Create Execution in Go Source: https://www.twilio.com/docs/studio/rest-api/execution Uses the Twilio Go helper library to create a Studio execution. Requires TWILIO_API_KEY, TWILIO_API_SECRET, and TWILIO_ACCOUNT_SID environment variables. Sets the parameters, To, and From fields on the CreateExecutionParams, then calls CreateExecution with the flow SID. Prints the execution SID or an error message. ```go // Download the helper library from https://www.twilio.com/docs/go/install package main import ( "fmt" "github.com/twilio/twilio-go" studio "github.com/twilio/twilio-go/rest/studio/v1" "os" ) func main() { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token accountSid := os.Getenv("TWILIO_ACCOUNT_SID") apiKey := os.Getenv("TWILIO_API_KEY") apiSecret := os.Getenv("TWILIO_API_SECRET") client := twilio.NewRestClientWithParams(twilio.ClientParams{ Username: apiKey, Password: apiSecret, AccountSid: accountSid, }) params := &studio.CreateExecutionParams{} params.SetParameters(map[string]interface{}{ "foo": "bar", }) params.SetTo("+14155552345") params.SetFrom("+14155552344") resp, err := client.StudioV1.CreateExecution("FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", params) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { if resp.Sid != nil { fmt.Println(*resp.Sid) } else { fmt.Println(resp.Sid) } } } ``` -------------------------------- ### Studio Executions list response example Source: https://www.twilio.com/docs/studio/rest-api/v2/execution Example JSON response from the Studio Executions list endpoint. Shows the meta object with pagination details and an empty executions array. ```json { "meta": { "previous_page_url": null, "next_page_url": null, "url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions?PageSize=50&Page=0", "page": 0, "first_page_url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Executions?PageSize=50&Page=0", "page_size": 50, "key": "executions" }, "executions": [] } ``` -------------------------------- ### Liquid case statement example with template variable Source: https://www.twilio.com/docs/studio/user-guide/liquid-template-language Example of a case statement that checks the template variable and outputs different content based on its value. The else clause handles the default case. ```liquid {% case template %} {% when 'label' %} // {{ label.title }} {% when 'product' %} // {{ product.vendor }} / {{ product.title }} {% else %} // {{page_title}} {% endcase %} ``` -------------------------------- ### Fetch execution with C# / .NET helper library Source: https://www.twilio.com/docs/studio/rest-api/v2/execution C# / .NET helper library example to fetch a single Execution. Requires TWILIO_API_KEY, TWILIO_API_SECRET, and TWILIO_ACCOUNT_SID environment variables. Uses ExecutionResource.FetchAsync with placeholder SIDs. ```csharp // Install the C# / .NET helper library from twilio.com/docs/csharp/install using System; using Twilio; using Twilio.Rest.Studio.V2.Flow; using System.Threading.Tasks; class Program { public static async Task Main(string[] args) { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token string apiKey = Environment.GetEnvironmentVariable("TWILIO_API_KEY"); string apiSecret = Environment.GetEnvironmentVariable("TWILIO_API_SECRET"); string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); TwilioClient.Init(apiKey, apiSecret, accountSid); var execution = await ExecutionResource.FetchAsync( pathFlowSid: "FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", pathSid: "FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); Console.WriteLine(execution.Sid); } } ``` -------------------------------- ### Query parameters for GET /Flows/{Sid}/Revisions Source: https://www.twilio.com/docs/studio/rest-api/v2/flow-revision Defines the optional query parameters for the GET /Flows/{Sid}/Revisions endpoint. PageSize defaults to 50 and has a maximum of 1000; Page and PageToken control pagination. ```json [{"name":"PageSize","in":"query","description":"How many resources to return in each list page. The default is 50, and the maximum is 1000.","schema":{"type":"integer","format":"int64","minimum":1,"maximum":1000}},{"name":"Page","in":"query","description":"The page index. This value is simply for client state.","schema":{"type":"integer","minimum":0}},{"name":"PageToken","in":"query","description":"The page token. This is provided by the API.","schema":{"type":"string"}}] ``` -------------------------------- ### Fetch Flow with Go Source: https://www.twilio.com/docs/studio/rest-api/flow Go example using the Twilio helper library to fetch a Flow. Requires TWILIO_ACCOUNT_SID, TWILIO_API_KEY, and TWILIO_API_SECRET environment variables. Prints the flow SID or exits with error. ```go // Download the helper library from https://www.twilio.com/docs/go/install package main import ( "fmt" "github.com/twilio/twilio-go" "os" ) func main() { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token accountSid := os.Getenv("TWILIO_ACCOUNT_SID") apiKey := os.Getenv("TWILIO_API_KEY") apiSecret := os.Getenv("TWILIO_API_SECRET") client := twilio.NewRestClientWithParams(twilio.ClientParams{ Username: apiKey, Password: apiSecret, AccountSid: accountSid, }) resp, err := client.StudioV1.FetchFlow("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { if resp.Sid != nil { fmt.Println(*resp.Sid) } else { fmt.Println(resp.Sid) } } } ``` -------------------------------- ### Path parameters for GET /Flows/{Sid}/Revisions Source: https://www.twilio.com/docs/studio/rest-api/v2/flow-revision Defines the required path parameter for the GET /Flows/{Sid}/Revisions endpoint. The Sid must be a Flow SID matching the pattern ^FW[0-9a-fA-F]{32}$. ```json [{"name":"Sid","in":"path","description":"The SID of the Flow resource to fetch.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^FW[0-9a-fA-F]{32}$"},"required":true}] ``` -------------------------------- ### List Flow Revisions Response Example Source: https://www.twilio.com/docs/studio/rest-api/v2/flow-revision Example JSON response from the List Flow Revisions endpoint. Shows the meta pagination information and a single revision object with fields such as sid, account_sid, status, revision, and timestamps. ```json { "meta": { "previous_page_url": null, "next_page_url": null, "url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions?PageSize=50&Page=0", "page": 0, "first_page_url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions?PageSize=50&Page=0", "page_size": 50, "key": "revisions" }, "revisions": [ { "sid": "FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "author_sid": "USaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "friendly_name": "Test Flow", "status": "published", "revision": 1, "definition": null, "commit_message": null, "valid": null, "errors": null, "date_created": "2017-11-06T12:00:00Z", "date_updated": "2017-11-06T12:00:00Z", "url": "https://studio.twilio.com/v2/Flows/FWaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Revisions/1" } ] } ``` -------------------------------- ### List Studio Flows with Twilio helper libraries (Go, PHP, Ruby) Source: https://www.twilio.com/docs/studio/rest-api/flow List Studio Flows using the Twilio helper libraries for Go, PHP, and Ruby. Each example sets the limit to 20 and prints the SID of each flow. Requires TWILIO_ACCOUNT_SID, TWILIO_API_KEY, and TWILIO_API_SECRET environment variables. ```go // Download the helper library from https://www.twilio.com/docs/go/install package main import ( "fmt" "github.com/twilio/twilio-go" studio "github.com/twilio/twilio-go/rest/studio/v1" "os" ) func main() { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token accountSid := os.Getenv("TWILIO_ACCOUNT_SID") apiKey := os.Getenv("TWILIO_API_KEY") apiSecret := os.Getenv("TWILIO_API_SECRET") client := twilio.NewRestClientWithParams(twilio.ClientParams{ Username: apiKey, Password: apiSecret, AccountSid: accountSid, }) params := &studio.ListFlowParams{} params.SetLimit(20) resp, err := client.StudioV1.ListFlow(params) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { for record := range resp { if resp[record].Sid != nil { fmt.Println(*resp[record].Sid) } else { fmt.Println(resp[record].Sid) } } } } ``` ```php studio->v1->flows->read(20); foreach ($flows as $record) { print $record->sid; } ``` ```ruby # Download the helper library from https://www.twilio.com/docs/ruby/install require 'twilio-ruby' # Find your Account SID at twilio.com/console # Provision API Keys at twilio.com/console/runtime/api-keys # and set the environment variables. See http://twil.io/secure # For local testing, you can use your Account SID and Auth token api_key = ENV['TWILIO_API_KEY'] api_secret = ENV['TWILIO_API_SECRET'] account_sid = ENV['TWILIO_ACCOUNT_SID'] @client = Twilio::REST::Client.new(api_key, api_secret, account_sid) flows = @client .studio .v1 .flows .list(limit: 20) flows.each do |record| puts record.sid end ``` -------------------------------- ### List flows with C# Source: https://www.twilio.com/docs/studio/rest-api/flow C# / .NET helper library example that lists up to 20 Studio flows and prints each flow's SID. Requires TWILIO_API_KEY, TWILIO_API_SECRET, and TWILIO_ACCOUNT_SID environment variables. ```csharp // Install the C# / .NET helper library from twilio.com/docs/csharp/install using System; using Twilio; using Twilio.Rest.Studio.V1; using System.Threading.Tasks; class Program { public static async Task Main(string[] args) { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token string apiKey = Environment.GetEnvironmentVariable("TWILIO_API_KEY"); string apiSecret = Environment.GetEnvironmentVariable("TWILIO_API_SECRET"); string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); TwilioClient.Init(apiKey, apiSecret, accountSid); var flows = await FlowResource.ReadAsync(limit: 20); foreach (var record in flows) { Console.WriteLine(record.Sid); } } } ``` -------------------------------- ### Validate Flow - Request Body Example Source: https://www.twilio.com/docs/studio/rest-api/v2/flow-validate Example request body for the Flow Validate endpoint. It includes the required fields FriendlyName, Status, and Definition, with a sample Definition containing an initial state of "Trigger". ```json { "FriendlyName": "Test Flow", "Status": "published", "Definition": "{\"initial_state\": \"Trigger\"}" } ``` -------------------------------- ### Fetch execution context with Twilio Java Source: https://www.twilio.com/docs/studio/rest-api/execution-context Java example using the Twilio helper library to fetch an execution context. Requires TWILIO_API_KEY, TWILIO_API_SECRET, and TWILIO_ACCOUNT_SID environment variables. The example prints the AccountSid from the fetched context. ```java // Install the Java helper library from twilio.com/docs/java/install import com.twilio.Twilio; import com.twilio.rest.studio.v1.flow.execution.ExecutionContext; public class Example { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token public static final String API_KEY = System.getenv("TWILIO_API_KEY"); public static final String API_SECRET = System.getenv("TWILIO_API_SECRET"); public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID"); public static void main(String[] args) { Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID); ExecutionContext executionContext = ExecutionContext.fetcher("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") .fetch(); System.out.println(executionContext.getAccountSid()); } } ``` -------------------------------- ### List flows with Python Source: https://www.twilio.com/docs/studio/rest-api/flow Python helper library example that lists up to 20 Studio flows and prints each flow's SID. Requires TWILIO_API_KEY, TWILIO_API_SECRET, and TWILIO_ACCOUNT_SID environment variables. ```python # Download the helper library from https://www.twilio.com/docs/python/install import os from twilio.rest import Client # Find your Account SID at twilio.com/console # Provision API Keys at twilio.com/console/runtime/api-keys # and set the environment variables. See http://twil.io/secure # For local testing, you can use your Account SID and Auth token api_key = os.environ["TWILIO_API_KEY"] api_secret = os.environ["TWILIO_API_SECRET"] account_sid = os.environ["TWILIO_ACCOUNT_SID"] client = Client(api_key, api_secret, account_sid) flows = client.studio.v1.flows.list(limit=20) for record in flows: print(record.sid) ``` -------------------------------- ### Update Studio Flow Execution to Ended Status Source: https://www.twilio.com/docs/studio/rest-api/v2/execution Update a Studio Flow execution to the 'ended' status using the Twilio API. Each example uses the same Flow SID and Execution SID placeholders and requires Twilio API credentials via environment variables. The Java, Go, PHP, and Ruby examples use the respective Twilio helper libraries, while the CLI and curl examples show direct API calls. ```java // Install the Java helper library from twilio.com/docs/java/install import com.twilio.Twilio; import com.twilio.rest.studio.v2.flow.Execution; public class Example { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token public static final String API_KEY = System.getenv("TWILIO_API_KEY"); public static final String API_SECRET = System.getenv("TWILIO_API_SECRET"); public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID"); public static void main(String[] args) { Twilio.init(API_KEY, API_SECRET, ACCOUNT_SID); Execution execution = Execution .updater( "FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", Execution.Status.ENDED) .update(); System.out.println(execution.getSid()); } } ``` ```go // Download the helper library from https://www.twilio.com/docs/go/install package main import ( "fmt" "github.com/twilio/twilio-go" studio "github.com/twilio/twilio-go/rest/studio/v2" "os" ) func main() { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token accountSid := os.Getenv("TWILIO_ACCOUNT_SID") apiKey := os.Getenv("TWILIO_API_KEY") apiSecret := os.Getenv("TWILIO_API_SECRET") client := twilio.NewRestClientWithParams(twilio.ClientParams{ Username: apiKey, Password: apiSecret, AccountSid: accountSid, }) params := &studio.UpdateExecutionParams{} params.SetStatus("ended") resp, err := client.StudioV2.UpdateExecution("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", params) if err != nil { fmt.Println(err.Error()) os.Exit(1) } else { if resp.Sid != nil { fmt.Println(*resp.Sid) } else { fmt.Println(resp.Sid) } } } ``` ```php studio->v2 ->flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") ->executions("FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") ->update( "ended", // Status ); print $execution->sid; ``` ```ruby # Download the helper library from https://www.twilio.com/docs/ruby/install require 'twilio-ruby' # Find your Account SID at twilio.com/console # Provision API Keys at twilio.com/console/runtime/api-keys # and set the environment variables. See http://twil.io/secure # For local testing, you can use your Account SID and Auth token api_key = ENV['TWILIO_API_KEY'] api_secret = ENV['TWILIO_API_SECRET'] account_sid = ENV['TWILIO_ACCOUNT_SID'] @client = Twilio::REST::Client.new(api_key, api_secret, account_sid) execution = @client .studio .v2 .flows('FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') .executions('FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') .update(status: 'ended') puts execution.sid ``` ```bash # Install the twilio-cli from https://twil.io/cli twilio api:studio:v2:flows:executions:update \ --flow-sid FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \ --sid FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \ --status ended ``` ```bash curl -X POST "https://studio.twilio.com/v2/Flows/FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Executions/FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \ --data-urlencode "Status=ended" \ -u $TWILIO_API_KEY:$TWILIO_API_SECRET ``` -------------------------------- ### List Execution Steps in PHP Source: https://www.twilio.com/docs/studio/rest-api/step Uses the Twilio PHP helper library to list up to 20 steps for a given flow and execution. Requires TWILIO_API_KEY, TWILIO_API_SECRET, and TWILIO_ACCOUNT_SID environment variables. Prints each step's SID. ```php studio->v1 ->flows("FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") ->executions("FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") ->steps->read(20); foreach ($steps as $record) { print $record->sid; } ``` -------------------------------- ### Create Execution request body schema and example Source: https://www.twilio.com/docs/studio/rest-api/v2/execution Request body schema for the Create Execution endpoint. It requires To and From fields, and Parameters must be passed as a JSON string, not a hash object. The example shows a request with To, From, Parameters, and ExternalId. ```json {"schema":{"type":"object","title":"CreateExecutionRequest","required":["To","From"],"properties":{"To":{"type":"string","format":"phone-number","description":"The Contact phone number to start a Studio Flow Execution, available as variable `{{contact.channel.address}}`."},"From":{"type":"string","format":"phone-number","description":"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."},"Parameters":{"description":"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."}}},"examples":{"create":{"value":{"lang":"json","value":"{\n \"To\": \"+18001234567\",\n \"From\": \"+18007654321\",\n \"Parameters\": \"{\\\"first_name\\\":\\\"Foo\\\"}\",\n \"ExternalId\": \"random_external_id\"\n}","meta":"","code":"{\n \"To\": \"+18001234567\",\n \"From\": \"+18007654321\",\n \"Parameters\": \"{\\\"first_name\\\":\\\"Foo\\\"}\",\n \"ExternalId\": \"random_external_id\"\n}","tokens":[["{","#C9D1D9"],"\n ",["\"To\"","#7EE787"],[":","#C9D1D9"]," ",["\"+18001234567\"","#A5D6FF"],[",","#C9D1D9"],"\n ",["\"From\"","#7EE787"],[":","#C9D1D9"]," ",["\"+18007654321\"","#A5D6FF"],[",","#C9D1D9"],"\n ",["\"Parameters\"","#7EE787"],[":","#C9D1D9"]," ",["\"{","#A5D6FF"],["\\\"","#79C0FF"],["first_name","#A5D6FF"],["\\\"","#79C0FF"],[":","#A5D6FF"],["\\\"","#79C0FF"],["Foo","#A5D6FF"],["\\\"","#79C0FF"],["}\"","#A5D6FF"],[",","#C9D1D9"],"\n ",["\"ExternalId\"","#7EE787"],[":","#C9D1D9"]," ",["\"random_external_id\"","#A5D6FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117","colorScheme":"dark"}}},"encodingType":"application/x-www-form-urlencoded","conditionalParameterMap":{}} ``` -------------------------------- ### Fetch an Execution Step via Twilio CLI Source: https://www.twilio.com/docs/studio/rest-api/step Uses the Twilio CLI to fetch an execution step. Requires the Twilio CLI to be installed. ```bash # Install the twilio-cli from https://twil.io/cli twilio api:studio:v1:flows:executions:steps:fetch \ --flow-sid FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \ --execution-sid FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX \ --sid FTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ``` -------------------------------- ### Fetch execution context with Twilio C# / .NET Source: https://www.twilio.com/docs/studio/rest-api/execution-context C# / .NET example using the Twilio helper library to fetch an execution context. Requires TWILIO_API_KEY, TWILIO_API_SECRET, and TWILIO_ACCOUNT_SID environment variables. The example prints the AccountSid from the fetched context. ```csharp // Install the C# / .NET helper library from twilio.com/docs/csharp/install using System; using Twilio; using Twilio.Rest.Studio.V1.Flow.Execution; using System.Threading.Tasks; class Program { public static async Task Main(string[] args) { // Find your Account SID at twilio.com/console // Provision API Keys at twilio.com/console/runtime/api-keys // and set the environment variables. See http://twil.io/secure // For local testing, you can use your Account SID and Auth token string apiKey = Environment.GetEnvironmentVariable("TWILIO_API_KEY"); string apiSecret = Environment.GetEnvironmentVariable("TWILIO_API_SECRET"); string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); TwilioClient.Init(apiKey, apiSecret, accountSid); var executionContext = await ExecutionContextResource.FetchAsync( pathFlowSid: "FWXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", pathExecutionSid: "FNXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); Console.WriteLine(executionContext.AccountSid); } } ```