# ConnectionPolicyTarget Resource

The `ConnectionPolicyTarget` resource describes the individual URI entries that make up the BYOC Origination ConnectionPolicies list.

## Target Properties

```json
{"type":"object","refName":"voice.v1.connection_policy.connection_policy_target","modelName":"voice_v1_connection_policy_connection_policy_target","properties":{"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","nullable":true,"description":"The SID of the [Account](/docs/iam/api/account) that created the Target resource."},"connection_policy_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NY[0-9a-fA-F]{32}$","nullable":true,"description":"The SID of the Connection Policy that owns the Target."},"sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NE[0-9a-fA-F]{32}$","nullable":true,"description":"The unique string that we created to identify the Target resource."},"friendly_name":{"type":"string","nullable":true,"description":"The string that you assigned to describe the resource."},"target":{"type":"string","format":"uri","nullable":true,"description":"The SIP address you want Twilio to route your calls to. This must be a `sip:` schema. `sips` is NOT supported.","x-twilio":{"pii":{"handling":"standard","deleteSla":30}}},"priority":{"type":"integer","default":0,"description":"The relative importance of the target. Can be an integer from 0 to 65535, inclusive, and the default is 10. The lowest number represents the most important target."},"weight":{"type":"integer","default":0,"description":"The value that determines the relative share of the load the Target should receive compared to other Targets with the same priority. Can be an integer from 1 to 65535, inclusive, and the default is 10. Targets with higher values receive more load than those with lower ones with the same priority."},"enabled":{"type":"boolean","nullable":true,"description":"Whether the target is enabled. The default is `true`."},"date_created":{"type":"string","format":"date-time","nullable":true,"description":"The date and time in GMT when the resource was created specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format."},"date_updated":{"type":"string","format":"date-time","nullable":true,"description":"The date and time in GMT when the resource was last updated specified in [RFC 2822](https://www.ietf.org/rfc/rfc2822.txt) format."},"url":{"type":"string","format":"uri","nullable":true,"description":"The absolute URL of the resource."}}}
```

## Create a ConnectionPolicyTarget resource

`POST https://voice.twilio.com/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets`

### Path parameters

```json
[{"name":"ConnectionPolicySid","in":"path","description":"The SID of the Connection Policy that owns the Target.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NY[0-9a-fA-F]{32}$"},"required":true}]
```

### Request body parameters

```json
{"schema":{"type":"object","title":"CreateConnectionPolicyTargetRequest","required":["Target"],"properties":{"Target":{"type":"string","format":"uri","description":"The SIP address you want Twilio to route your calls to. This must be a `sip:` schema. `sips` is NOT supported.","x-twilio":{"pii":{"handling":"standard","deleteSla":30}}},"FriendlyName":{"type":"string","description":"A descriptive string that you create to describe the resource. It is not unique and can be up to 255 characters long."},"Priority":{"type":"integer","description":"The relative importance of the target. Can be an integer from 0 to 65535, inclusive, and the default is 10. The lowest number represents the most important target."},"Weight":{"type":"integer","description":"The value that determines the relative share of the load the Target should receive compared to other Targets with the same priority. Can be an integer from 1 to 65535, inclusive, and the default is 10. Targets with higher values receive more load than those with lower ones with the same priority."},"Enabled":{"type":"boolean","description":"Whether the Target is enabled. The default is `true`."}}},"examples":{"create":{"value":{"lang":"json","value":"{\n  \"FriendlyName\": \"friendly_name\",\n  \"Target\": \"sip:sip-box.com:1234\",\n  \"Priority\": 1,\n  \"Weight\": 20,\n  \"Enabled\": true\n}","meta":"","code":"{\n  \"FriendlyName\": \"friendly_name\",\n  \"Target\": \"sip:sip-box.com:1234\",\n  \"Priority\": 1,\n  \"Weight\": 20,\n  \"Enabled\": true\n}","tokens":[["{","#C9D1D9"],"\n  ",["\"FriendlyName\"","#7EE787"],[":","#C9D1D9"]," ",["\"friendly_name\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Target\"","#7EE787"],[":","#C9D1D9"]," ",["\"sip:sip-box.com:1234\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Priority\"","#7EE787"],[":","#C9D1D9"]," ",["1","#79C0FF"],[",","#C9D1D9"],"\n  ",["\"Weight\"","#7EE787"],[":","#C9D1D9"]," ",["20","#79C0FF"],[",","#C9D1D9"],"\n  ",["\"Enabled\"","#7EE787"],[":","#C9D1D9"]," ",["true","#79C0FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}}},"encodingType":"application/x-www-form-urlencoded","conditionalParameterMap":{}}
```

Create a Target

```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 createConnectionPolicyTarget() {
  const target = await client.voice.v1
    .connectionPolicies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .targets.create({ target: "https://www.example.com" });

  console.log(target.accountSid);
}

createConnectionPolicyTarget();
```

```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)

target = client.voice.v1.connection_policies(
    "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
).targets.create(target="https://www.example.com")

print(target.account_sid)
```

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

using System;
using Twilio;
using Twilio.Rest.Voice.V1.ConnectionPolicy;
using System.Threading.Tasks;

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 connectionPolicyTarget = await ConnectionPolicyTargetResource.CreateAsync(
            target: new Uri("https://www.example.com"),
            pathConnectionPolicySid: "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(connectionPolicyTarget.AccountSid);
    }
}
```

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

import java.net.URI;
import com.twilio.Twilio;
import com.twilio.rest.voice.v1.connectionpolicy.ConnectionPolicyTarget;

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);
        ConnectionPolicyTarget connectionPolicyTarget =
            ConnectionPolicyTarget.creator("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", URI.create("https://www.example.com"))
                .create();

        System.out.println(connectionPolicyTarget.getAccountSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	voice "github.com/twilio/twilio-go/rest/voice/v1"
	"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 := &voice.CreateConnectionPolicyTargetParams{}
	params.SetTarget("https://www.example.com")

	resp, err := client.VoiceV1.CreateConnectionPolicyTarget("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.AccountSid != nil {
			fmt.Println(*resp.AccountSid)
		} else {
			fmt.Println(resp.AccountSid)
		}
	}
}
```

```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);

$target = $twilio->voice->v1
    ->connectionPolicies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->targets->create(
        "https://www.example.com" // Target
    );

print $target->accountSid;
```

```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)

target = @client
         .voice
         .v1
         .connection_policies('NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
         .targets
         .create(target: 'https://www.example.com')

puts target.account_sid
```

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

twilio api:voice:v1:connection-policies:targets:create \
   --connection-policy-sid NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --target https://www.example.com
```

```bash
curl -X POST "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets" \
--data-urlencode "Target=https://www.example.com" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "connection_policy_sid": "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "sid": "NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "friendly_name": "friendly_name",
  "target": "https://www.example.com",
  "priority": 1,
  "weight": 20,
  "enabled": true,
  "date_created": "2020-03-18T23:31:36Z",
  "date_updated": "2020-03-18T23:31:36Z",
  "url": "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets/NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
```

## Fetch a ConnectionPolicyTarget resource

`GET https://voice.twilio.com/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets/{Sid}`

### Path parameters

```json
[{"name":"ConnectionPolicySid","in":"path","description":"The SID of the Connection Policy that owns the Target.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NY[0-9a-fA-F]{32}$"},"required":true},{"name":"Sid","in":"path","description":"The unique string that we created to identify the Target resource to fetch.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NE[0-9a-fA-F]{32}$"},"required":true}]
```

Fetch a Target

```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 fetchConnectionPolicyTarget() {
  const target = await client.voice.v1
    .connectionPolicies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .targets("NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .fetch();

  console.log(target.accountSid);
}

fetchConnectionPolicyTarget();
```

```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)

target = (
    client.voice.v1.connection_policies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .targets("NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .fetch()
)

print(target.account_sid)
```

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

using System;
using Twilio;
using Twilio.Rest.Voice.V1.ConnectionPolicy;
using System.Threading.Tasks;

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 connectionPolicyTarget = await ConnectionPolicyTargetResource.FetchAsync(
            pathConnectionPolicySid: "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            pathSid: "NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(connectionPolicyTarget.AccountSid);
    }
}
```

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

import com.twilio.Twilio;
import com.twilio.rest.voice.v1.connectionpolicy.ConnectionPolicyTarget;

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);
        ConnectionPolicyTarget connectionPolicyTarget =
            ConnectionPolicyTarget.fetcher("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
                .fetch();

        System.out.println(connectionPolicyTarget.getAccountSid());
    }
}
```

```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 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()

	resp, err := client.VoiceV1.FetchConnectionPolicyTarget("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		"NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.AccountSid != nil {
			fmt.Println(*resp.AccountSid)
		} else {
			fmt.Println(resp.AccountSid)
		}
	}
}
```

```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);

$target = $twilio->voice->v1
    ->connectionPolicies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->targets("NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->fetch();

print $target->accountSid;
```

```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)

target = @client
         .voice
         .v1
         .connection_policies('NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
         .targets('NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
         .fetch

puts target.account_sid
```

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

twilio api:voice:v1:connection-policies:targets:fetch \
   --connection-policy-sid NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --sid NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
```

```bash
curl -X GET "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets/NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "connection_policy_sid": "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "sid": "NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "friendly_name": "friendly_name",
  "target": "sip:sip-box.com:1234",
  "priority": 1,
  "weight": 20,
  "enabled": true,
  "date_created": "2020-03-18T23:31:36Z",
  "date_updated": "2020-03-18T23:31:37Z",
  "url": "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets/NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
```

## Read multiple ConnectionPolicyTarget resources

`GET https://voice.twilio.com/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets`

### Path parameters

```json
[{"name":"ConnectionPolicySid","in":"path","description":"The SID of the Connection Policy from which to read the Targets.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NY[0-9a-fA-F]{32}$"},"required":true}]
```

### Query parameters

```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"}}]
```

List multiple Targets

```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 listConnectionPolicyTarget() {
  const targets = await client.voice.v1
    .connectionPolicies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .targets.list({ limit: 20 });

  targets.forEach((t) => console.log(t.accountSid));
}

listConnectionPolicyTarget();
```

```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)

targets = client.voice.v1.connection_policies(
    "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
).targets.list(limit=20)

for record in targets:
    print(record.account_sid)
```

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

using System;
using Twilio;
using Twilio.Rest.Voice.V1.ConnectionPolicy;
using System.Threading.Tasks;

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 connectionPolicyTargets = await ConnectionPolicyTargetResource.ReadAsync(
            pathConnectionPolicySid: "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", limit: 20);

        foreach (var record in connectionPolicyTargets) {
            Console.WriteLine(record.AccountSid);
        }
    }
}
```

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

import com.twilio.Twilio;
import com.twilio.rest.voice.v1.connectionpolicy.ConnectionPolicyTarget;
import com.twilio.base.ResourceSet;

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);
        ResourceSet<ConnectionPolicyTarget> connectionPolicyTargets =
            ConnectionPolicyTarget.reader("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").limit(20).read();

        for (ConnectionPolicyTarget record : connectionPolicyTargets) {
            System.out.println(record.getAccountSid());
        }
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	voice "github.com/twilio/twilio-go/rest/voice/v1"
	"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 := &voice.ListConnectionPolicyTargetParams{}
	params.SetLimit(20)

	resp, err := client.VoiceV1.ListConnectionPolicyTarget("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		for record := range resp {
			if resp[record].AccountSid != nil {
				fmt.Println(*resp[record].AccountSid)
			} else {
				fmt.Println(resp[record].AccountSid)
			}
		}
	}
}
```

```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);

$targets = $twilio->voice->v1
    ->connectionPolicies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->targets->read(20);

foreach ($targets as $record) {
    print $record->accountSid;
}
```

```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)

targets = @client
          .voice
          .v1
          .connection_policies('NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
          .targets
          .list(limit: 20)

targets.each do |record|
   puts record.account_sid
end
```

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

twilio api:voice:v1:connection-policies:targets:list \
   --connection-policy-sid NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
```

```bash
curl -X GET "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets?PageSize=20" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "meta": {
    "page": 0,
    "page_size": 50,
    "first_page_url": "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets?PageSize=50&Page=0",
    "previous_page_url": null,
    "url": "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets?PageSize=50&Page=0",
    "next_page_url": null,
    "key": "targets"
  },
  "targets": [
    {
      "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "connection_policy_sid": "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "sid": "NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "friendly_name": "friendly_name",
      "target": "sip:sip-box.com:1234",
      "priority": 1,
      "weight": 20,
      "enabled": true,
      "date_created": "2020-03-18T23:31:36Z",
      "date_updated": "2020-03-18T23:31:37Z",
      "url": "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets/NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    }
  ]
}
```

## Update a ConnectionPolicyTarget resource

`POST https://voice.twilio.com/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets/{Sid}`

### Path parameters

```json
[{"name":"ConnectionPolicySid","in":"path","description":"The SID of the Connection Policy that owns the Target.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NY[0-9a-fA-F]{32}$"},"required":true},{"name":"Sid","in":"path","description":"The unique string that we created to identify the Target resource to update.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NE[0-9a-fA-F]{32}$"},"required":true}]
```

### Request body parameters

```json
{"schema":{"type":"object","title":"UpdateConnectionPolicyTargetRequest","properties":{"FriendlyName":{"type":"string","description":"A descriptive string that you create to describe the resource. It is not unique and can be up to 255 characters long."},"Target":{"type":"string","format":"uri","description":"The SIP address you want Twilio to route your calls to. This must be a `sip:` schema. `sips` is NOT supported.","x-twilio":{"pii":{"handling":"standard","deleteSla":30}}},"Priority":{"type":"integer","description":"The relative importance of the target. Can be an integer from 0 to 65535, inclusive. The lowest number represents the most important target."},"Weight":{"type":"integer","description":"The value that determines the relative share of the load the Target should receive compared to other Targets with the same priority. Can be an integer from 1 to 65535, inclusive. Targets with higher values receive more load than those with lower ones with the same priority."},"Enabled":{"type":"boolean","description":"Whether the Target is enabled."}}},"examples":{"update":{"value":{"lang":"json","value":"{\n  \"FriendlyName\": \"updated_name\",\n  \"Target\": \"sip:sip-updated.com:4321\",\n  \"Priority\": 2,\n  \"Weight\": 10,\n  \"Enabled\": false\n}","meta":"","code":"{\n  \"FriendlyName\": \"updated_name\",\n  \"Target\": \"sip:sip-updated.com:4321\",\n  \"Priority\": 2,\n  \"Weight\": 10,\n  \"Enabled\": false\n}","tokens":[["{","#C9D1D9"],"\n  ",["\"FriendlyName\"","#7EE787"],[":","#C9D1D9"]," ",["\"updated_name\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Target\"","#7EE787"],[":","#C9D1D9"]," ",["\"sip:sip-updated.com:4321\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"Priority\"","#7EE787"],[":","#C9D1D9"]," ",["2","#79C0FF"],[",","#C9D1D9"],"\n  ",["\"Weight\"","#7EE787"],[":","#C9D1D9"]," ",["10","#79C0FF"],[",","#C9D1D9"],"\n  ",["\"Enabled\"","#7EE787"],[":","#C9D1D9"]," ",["false","#79C0FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}}},"encodingType":"application/x-www-form-urlencoded","conditionalParameterMap":{}}
```

Update a Target

```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 updateConnectionPolicyTarget() {
  const target = await client.voice.v1
    .connectionPolicies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .targets("NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .update({ friendlyName: "FriendlyName" });

  console.log(target.accountSid);
}

updateConnectionPolicyTarget();
```

```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)

connection_policy_target = (
    client.voice.v1.connection_policies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .targets("NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .update(friendly_name="FriendlyName")
)

print(connection_policy_target.account_sid)
```

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

using System;
using Twilio;
using Twilio.Rest.Voice.V1.ConnectionPolicy;
using System.Threading.Tasks;

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 connectionPolicyTarget = await ConnectionPolicyTargetResource.UpdateAsync(
            friendlyName: "FriendlyName",
            pathConnectionPolicySid: "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            pathSid: "NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

        Console.WriteLine(connectionPolicyTarget.AccountSid);
    }
}
```

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

import com.twilio.Twilio;
import com.twilio.rest.voice.v1.connectionpolicy.ConnectionPolicyTarget;

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);
        ConnectionPolicyTarget connectionPolicyTarget =
            ConnectionPolicyTarget.updater("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
                .setFriendlyName("FriendlyName")
                .update();

        System.out.println(connectionPolicyTarget.getAccountSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	voice "github.com/twilio/twilio-go/rest/voice/v1"
	"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 := &voice.UpdateConnectionPolicyTargetParams{}
	params.SetFriendlyName("FriendlyName")

	resp, err := client.VoiceV1.UpdateConnectionPolicyTarget("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		"NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.AccountSid != nil {
			fmt.Println(*resp.AccountSid)
		} else {
			fmt.Println(resp.AccountSid)
		}
	}
}
```

```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);

$connection_policy_target = $twilio->voice->v1
    ->connectionPolicies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->targets("NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->update(["friendlyName" => "FriendlyName"]);

print $connection_policy_target->accountSid;
```

```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)

target = @client
         .voice
         .v1
         .connection_policies('NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
         .targets('NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
         .update(friendly_name: 'FriendlyName')

puts target.account_sid
```

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

twilio api:voice:v1:connection-policies:targets:update \
   --connection-policy-sid NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --sid NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --friendly-name FriendlyName
```

```bash
curl -X POST "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets/NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
--data-urlencode "FriendlyName=FriendlyName" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "connection_policy_sid": "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "sid": "NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "friendly_name": "FriendlyName",
  "target": "sip:sip-updated.com:4321",
  "priority": 2,
  "weight": 10,
  "enabled": false,
  "date_created": "2020-03-18T23:31:36Z",
  "date_updated": "2020-03-18T23:31:37Z",
  "url": "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets/NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
```

## Delete a ConnectionPolicyTarget resource

`DELETE https://voice.twilio.com/v1/ConnectionPolicies/{ConnectionPolicySid}/Targets/{Sid}`

### Path parameters

```json
[{"name":"ConnectionPolicySid","in":"path","description":"The SID of the Connection Policy that owns the Target.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NY[0-9a-fA-F]{32}$"},"required":true},{"name":"Sid","in":"path","description":"The unique string that we created to identify the Target resource to delete.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^NE[0-9a-fA-F]{32}$"},"required":true}]
```

Delete a Target

```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 deleteConnectionPolicyTarget() {
  await client.voice.v1
    .connectionPolicies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .targets("NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    .remove();
}

deleteConnectionPolicyTarget();
```

```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)

client.voice.v1.connection_policies(
    "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
).targets("NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").delete()
```

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

using System;
using Twilio;
using Twilio.Rest.Voice.V1.ConnectionPolicy;
using System.Threading.Tasks;

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);

        await ConnectionPolicyTargetResource.DeleteAsync(
            pathConnectionPolicySid: "NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            pathSid: "NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    }
}
```

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

import com.twilio.Twilio;
import com.twilio.rest.voice.v1.connectionpolicy.ConnectionPolicyTarget;

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);
        ConnectionPolicyTarget.deleter("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
            .delete();
    }
}
```

```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 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()

	err := client.VoiceV1.DeleteConnectionPolicyTarget("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		"NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	}
}
```

```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);

$twilio->voice->v1
    ->connectionPolicies("NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->targets("NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
    ->delete();
```

```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)

@client
  .voice
  .v1
  .connection_policies('NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
  .targets('NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
  .delete
```

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

twilio api:voice:v1:connection-policies:targets:remove \
   --connection-policy-sid NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --sid NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
```

```bash
curl -X DELETE "https://voice.twilio.com/v1/ConnectionPolicies/NYaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Targets/NEaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```
