# Flow Validate

The **Flow Validate** endpoint will validate a Flow definition without creating a new Flow. It accepts the same parameters as the [Create Flow method](/docs/studio/rest-api/v2/flow) and returns `{"valid":true}` in the response payload if no errors were found; otherwise, if the definition fails validation, the endpoint returns an error response.

## Validate Properties

```json
{"type":"object","refName":"studio.v2.flow_validate","modelName":"studio_v2_flow_validate","properties":{"valid":{"type":"boolean","nullable":true,"description":"Boolean if the flow definition is valid."}}}
```

## Validate Flow

`POST https://studio.twilio.com/v2/Flows/Validate`

### Request body parameters

```json
{"schema":{"type":"object","title":"UpdateFlowValidateRequest","required":["FriendlyName","Status","Definition"],"properties":{"FriendlyName":{"type":"string","description":"The string that you assigned to describe the Flow."},"Status":{"type":"string","enum":["draft","published"],"description":"The status of the Flow. Can be: `draft` or `published`.","refName":"flow_validate_enum_status","modelName":"flow_validate_enum_status"},"Definition":{"description":"JSON representation of flow definition."},"CommitMessage":{"type":"string","description":"Description of change made in the revision."}}},"examples":{"update":{"value":{"lang":"json","value":"{\n  \"FriendlyName\": \"Test Flow\",\n  \"Status\": \"published\",\n  \"Definition\": \"{\\\"initial_state\\\": \\\"Trigger\\\"}\"\n}","meta":"","code":"{\n  \"FriendlyName\": \"Test Flow\",\n  \"Status\": \"published\",\n  \"Definition\": \"{\\\"initial_state\\\": \\\"Trigger\\\"}\"\n}","tokens":[["{","#C9D1D9"],"\n  ",["\"FriendlyName\"","#7EE787"],[":","#C9D1D9"]," ",["\"Test Flow\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Status\"","#7EE787"],[":","#C9D1D9"]," ",["\"published\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Definition\"","#7EE787"],[":","#C9D1D9"]," ",["\"{","#A5D6FF"],["\\\"","#79C0FF"],["initial_state","#A5D6FF"],["\\\"","#79C0FF"],[":","#A5D6FF"]," ",["\\\"","#79C0FF"],["Trigger","#A5D6FF"],["\\\"","#79C0FF"],["}\"","#A5D6FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}}},"encodingType":"application/x-www-form-urlencoded","conditionalParameterMap":{}}
```

Validate Flow

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function updateFlowValidate() {
  const flowValidate = await client.studio.v2.flowValidate.update({
    definition: {
      description: "A New Flow",
      flags: {
        allow_concurrent_calls: true,
      },
      initial_state: "Trigger",
      states: [
        {
          name: "Trigger",
          properties: {
            offset: {
              x: 0,
              y: 0,
            },
          },
          transitions: [],
          type: "trigger",
        },
      ],
    },
    friendlyName: "Test Flow",
    status: "published",
  });

  console.log(flowValidate.valid);
}

updateFlowValidate();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

flow_validate = client.studio.v2.flow_validate.update(
    friendly_name="Test Flow",
    status="published",
    definition={
        "description": "A New Flow",
        "flags": {"allow_concurrent_calls": True},
        "initial_state": "Trigger",
        "states": [
            {
                "name": "Trigger",
                "properties": {"offset": {"x": 0, "y": 0}},
                "transitions": [],
                "type": "trigger",
            }
        ],
    },
)

print(flow_validate.valid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Studio.V2;
using System.Threading.Tasks;
using System.Collections.Generic;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var flowValidate = await FlowValidateResource.UpdateAsync(
            friendlyName: "Test Flow",
            status: FlowValidateResource.StatusEnum.Published,
            definition: new Dictionary<string, Object>() {
                { "description", "A New Flow" },
                { "flags",
                  new Dictionary<string, Object>() { { "allow_concurrent_calls", true } } },
                { "initial_state", "Trigger" },
                { "states",
                  new List<Object> { new Dictionary<string, Object>() {
                      { "name", "Trigger" },
                      { "properties",
                        new Dictionary<string, Object>() {
                            { "offset",
                              new Dictionary<string, Object>() { { "x", 0 }, { "y", 0 } } }
                        } },
                      { "transitions",
                        new List<Object> {

                        } },
                      { "type", "trigger" }
                  } } }
            });

        Console.WriteLine(flowValidate.Valid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import java.util.Arrays;
import java.util.HashMap;
import com.twilio.Twilio;
import com.twilio.rest.studio.v2.FlowValidate;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        FlowValidate flowValidate = FlowValidate
                                        .updater("Test Flow",
                                            FlowValidate.Status.PUBLISHED,
                                            new HashMap<String, Object>() {
                                                {
                                                    put("description", "A New Flow");
                                                    put("flags", new HashMap<String, Object>() {
                                                        {
                                                            put("allow_concurrent_calls", true);
                                                        }
                                                    });
                                                    put("initial_state", "Trigger");
                                                    put("states", Arrays.asList(new HashMap<String, Object>() {
                                                        {
                                                            put("name", "Trigger");
                                                            put("properties", new HashMap<String, Object>() {
                                                                {
                                                                    put("offset", new HashMap<String, Object>() {
                                                                        {
                                                                            put("x", 0);
                                                                            put("y", 0);
                                                                        }
                                                                    });
                                                                }
                                                            });
                                                            put("transitions",
                                                                Arrays.asList(

                                                                    ));
                                                            put("type", "trigger");
                                                        }
                                                    }));
                                                }
                                            }

                                            )
                                        .update();

        System.out.println(flowValidate.getValid());
    }
}
```

```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 and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &studio.UpdateFlowValidateParams{}
	params.SetFriendlyName("Test Flow")
	params.SetStatus("published")
	params.SetDefinition(map[string]interface{}{
		"description": "A New Flow",
		"flags": map[string]interface{}{
			"allow_concurrent_calls": true,
		},
		"initial_state": "Trigger",
		"states": []interface{}{
			map[string]interface{}{
				"name": "Trigger",
				"properties": map[string]interface{}{
					"offset": map[string]interface{}{
						"x": 0,
						"y": 0,
					},
				},
				"transitions": []interface{}{},
				"type":        "trigger",
			},
		},
	})

	resp, err := client.StudioV2.UpdateFlowValidate(params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.Valid != nil {
			fmt.Println(*resp.Valid)
		} else {
			fmt.Println(resp.Valid)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$flow_validate = $twilio->studio->v2->flowValidate->update(
    "Test Flow", // FriendlyName
    "published", // Status
    [
        "description" => "A New Flow",
        "flags" => [
            "allow_concurrent_calls" => true,
        ],
        "initial_state" => "Trigger",
        "states" => [
            [
                "name" => "Trigger",
                "properties" => [
                    "offset" => [
                        "x" => 0,
                        "y" => 0,
                    ],
                ],
                "transitions" => [],
                "type" => "trigger",
            ],
        ],
    ] // Definition
);

print $flow_validate->valid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

flow_validate = @client
                .studio
                .v2
                .flow_validate
                .update(
                  friendly_name: 'Test Flow',
                  status: 'published',
                  definition: {
                    'description' => 'A New Flow',
                    'flags' => {
                      'allow_concurrent_calls' => true
                    },
                    'initial_state' => 'Trigger',
                    'states' => [
                      {
                        'name' => 'Trigger',
                        'properties' => {
                          'offset' => {
                            'x' => 0,
                            'y' => 0
                          }
                        },
                        'transitions' => [

                        ],
                        'type' => 'trigger'
                      }
                    ]
                  }
                )

puts flow_validate.valid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:studio:v2:flows:validate:create \
   --friendly-name "Test Flow" \
   --status published \
   --definition "{\"description\":\"A New Flow\",\"flags\":{\"allow_concurrent_calls\":true},\"initial_state\":\"Trigger\",\"states\":[{\"name\":\"Trigger\",\"properties\":{\"offset\":{\"x\":0,\"y\":0}},\"transitions\":[],\"type\":\"trigger\"}]}"
```

```bash
DEFINITION_OBJ=$(cat << EOF
{
  "description": "A New Flow",
  "flags": {
    "allow_concurrent_calls": true
  },
  "initial_state": "Trigger",
  "states": [
    {
      "name": "Trigger",
      "properties": {
        "offset": {
          "x": 0,
          "y": 0
        }
      },
      "transitions": [],
      "type": "trigger"
    }
  ]
}
EOF
)
curl -X POST "https://studio.twilio.com/v2/Flows/Validate" \
--data-urlencode "FriendlyName=Test Flow" \
--data-urlencode "Status=published" \
--data-urlencode "Definition=$DEFINITION_OBJ" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "valid": true
}
```

## Troubleshoot using error details

An error response will be returned if the given Flow definition fails validation. Use the `details` object in the error response to find all errors present within the definition. Each error contains a message along with the path of where the issue took place.

For example, the `initial_state` parameter for this Flow definition has been changed to an invalid value:

```javascript
client.studio.v2.flowValidate
                .update({
                   friendlyName: 'Test Flow',
                   status: 'published',
                   definition: {
                     description: 'A New Flow',
                     flags: {
                       allow_concurrent_calls: true
                     },
                     initial_state: 'test', // changed from Trigger -> test for demonstration
                     states: [
                       {
                         name: 'Trigger',
                         properties: {
                           offset: {
                             x: 0,
                             y: 0
                           }
                         },
                         transitions: [
                         ],
                         type: 'trigger'
                       }
                     ]
                   }
                 })
                .then(flow_validate => console.log(flow_validate))
                .catch(e => console.log(e.details));
```

If an error response is delivered, the details will be logged to console. After the API request is made, the console logs this information:

```json
{
  errors: [
    {
      message: 'must match a widget name',
      property_path: '#/initial_state'
    }
  ],
  warnings: []
}
```

The message indicates that the name must be a valid Widget name. This property is located at `#/initial_state`, which was where the invalid value was inputted for this example.
