# Sessions Resource

## Session Properties

<OperationTable type="properties" data={{"type":"object","refName":"assistants.v1.service.session","modelName":"assistants_v1_service_session","properties":{"id":{"type":"string","description":"The Session ID."},"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","description":"The SID of the [Account](/docs/iam/api/account) that created the Session resource."},"assistant_id":{"type":"string","pattern":"^aia_asst_.+$","description":"The Assistant ID."},"verified":{"description":"True if the session is verified.","type":"boolean"},"identity":{"description":"The unique identity of user for the session.","type":"string"},"date_created":{"description":"The date and time in GMT when the Session was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.","format":"date-time","type":"string"},"date_updated":{"description":"The date and time in GMT when the Session was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format.","format":"date-time","type":"string"}}}} />

## Get a Session

`GET https://assistants.twilio.com/v1/Sessions/{id}`

### Path parameters

```json
[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}]
```

Get a Session

```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 fetchSession() {
  const session = await client.assistants.v1
    .sessions("your-session-id")
    .fetch();

  console.log(session.id);
}

fetchSession();
```

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

session = client.assistants.v1.sessions("your-session-id").fetch()

print(session.id)
```

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

using System;
using Twilio;
using Twilio.Rest.Assistants.V1;
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 session = await SessionResource.FetchAsync(pathId: "your-session-id");

        Console.WriteLine(session.Id);
    }
}
```

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

import com.twilio.Twilio;
import com.twilio.rest.assistants.v1.Session;

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);
        Session session = Session.fetcher("your-session-id").fetch();

        System.out.println(session.getId());
    }
}
```

```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.AssistantsV1.FetchSession("your-session-id")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		fmt.Println(resp.Id)
	}
}
```

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

$session = $twilio->assistants->v1->sessions("your-session-id")->fetch();

print $session->id;
```

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

session = @client
          .assistants
          .v1
          .sessions('your-session-id')
          .fetch

puts session.id
```

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

twilio api:assistants:v1:sessions:list \
   --id your-session-id
```

```bash
curl -X GET "https://assistants.twilio.com/v1/Sessions/your-session-id" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "assistant_id": "aia_asst_#",
  "date_created": "2009-07-06T20:30:00Z",
  "date_updated": "2009-07-06T20:30:00Z",
  "id": "your-session-id",
  "identity": "identity",
  "verified": false
}
```

## List Sessions

`GET https://assistants.twilio.com/v1/Sessions`

### Query parameters

```json
[{"name":"Page","in":"query","description":"The page index. This value is simply for client state.","schema":{"type":"integer","minimum":0}},{"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","minimum":1,"maximum":1000}},{"name":"PageToken","in":"query","description":"The page token. This is provided by the API.","schema":{"type":"string"}}]
```

List Sessions

```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 listSessions() {
  const sessions = await client.assistants.v1.sessions.list({ limit: 20 });

  sessions.forEach((s) => console.log(s.id));
}

listSessions();
```

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

sessions = client.assistants.v1.sessions.list(limit=20)

for record in sessions:
    print(record.id)
```

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

using System;
using Twilio;
using Twilio.Rest.Assistants.V1;
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 sessions = await SessionResource.ReadAsync(limit: 20);

        foreach (var record in sessions) {
            Console.WriteLine(record.Id);
        }
    }
}
```

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

import com.twilio.Twilio;
import com.twilio.rest.assistants.v1.Session;
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<Session> sessions = Session.reader().limit(20).read();

        for (Session record : sessions) {
            System.out.println(record.getId());
        }
    }
}
```

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

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

	resp, err := client.AssistantsV1.ListSessions(params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		for record := range resp {
			fmt.Println(resp[record].Id)
		}
	}
}
```

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

$sessions = $twilio->assistants->v1->sessions->read(20);

foreach ($sessions as $record) {
    print $record->id;
}
```

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

sessions = @client
           .assistants
           .v1
           .sessions
           .list(limit: 20)

sessions.each do |record|
   puts record.id
end
```

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

twilio api:assistants:v1:sessions:list
```

```bash
curl -X GET "https://assistants.twilio.com/v1/Sessions?PageSize=20" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "meta": {
    "first_page_url": "https://www.example.com",
    "key": "key",
    "next_page_url": "https://www.example.com",
    "page": 42,
    "page_size": 42,
    "previous_page_url": "https://www.example.com",
    "url": "https://www.example.com"
  },
  "sessions": [
    {
      "id": "id",
      "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "assistant_id": "aia_asst_#",
      "verified": false,
      "identity": "identity",
      "date_created": "2009-07-06T20:30:00Z",
      "date_updated": "2009-07-06T20:30:00Z"
    }
  ]
}
```
