# Schema resource

Schemas define how information is organized within an event's `data` attribute. You can use the schema to explore the fields in an event type before subscribing to it. You can use also it in production to validate that the events you receive match their published schemas.

There are two ways to find the schema `id` of an Event-Type.

1. You can fetch any event type resource through the [Event Type API](/docs/events/event-streams/event-type-resource#fetch-an-eventtype-resource) and find the `schema_id` in its properties.
2. If you are already receiving events in your sink, the metadata of the event will contain the url of its schema in a field called `dataschema`. The schema `id` is part of the url. For example, if the url is [https://events-schemas.twilio.com/VoiceInsights.CallSummary/1](https://events-schemas.twilio.com/VoiceInsights.CallSummary/1), the schema `id` is `VoiceInsights.CallSummary.`

## Schema Properties

```json
{"type":"object","refName":"events.v1.schema","modelName":"events_v1_schema","properties":{"id":{"type":"string","nullable":true,"description":"The unique identifier of the schema. Each schema can have multiple versions, that share the same id."},"url":{"type":"string","format":"uri","nullable":true,"description":"The URL of this resource."},"links":{"type":"object","format":"uri-map","nullable":true,"description":"Contains a dictionary of URL links to nested resources of this schema."},"latest_version_date_created":{"type":"string","format":"date-time","nullable":true,"description":"The date that the latest schema version was created, given in ISO 8601 format."},"latest_version":{"type":"integer","default":0,"description":"The latest version published of this schema."}}}
```

## Fetch a Schema resource

`GET https://events.twilio.com/v1/Schemas/{Id}`

### Path parameters

```json
[{"name":"Id","in":"path","description":"The unique identifier of the schema. Each schema can have multiple versions, that share the same id.","schema":{"type":"string"},"required":true}]
```

Fetch schema

```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 fetchSchema() {
  const schema = await client.events.v1
    .schemas("Messaging.MessageStatus")
    .fetch();

  console.log(schema.id);
}

fetchSchema();
```

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

schema = client.events.v1.schemas("Messaging.MessageStatus").fetch()

print(schema.id)
```

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

using System;
using Twilio;
using Twilio.Rest.Events.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 schema = await SchemaResource.FetchAsync(pathId: "Messaging.MessageStatus");

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

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

import com.twilio.Twilio;
import com.twilio.rest.events.v1.Schema;

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);
        Schema schema = Schema.fetcher("Messaging.MessageStatus").fetch();

        System.out.println(schema.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.EventsV1.FetchSchema("Messaging.MessageStatus")
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.Id != nil {
			fmt.Println(*resp.Id)
		} 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);

$schema = $twilio->events->v1->schemas("Messaging.MessageStatus")->fetch();

print $schema->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)

schema = @client
         .events
         .v1
         .schemas('Messaging.MessageStatus')
         .fetch

puts schema.id
```

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

twilio api:events:v1:schemas:fetch \
   --id Messaging.MessageStatus
```

```bash
curl -X GET "https://events.twilio.com/v1/Schemas/Messaging.MessageStatus" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "id": "Messaging.MessageStatus",
  "url": "https://events.twilio.com/v1/Schemas/Messaging.MessageStatus",
  "latest_version_date_created": "2020-07-30T20:00:00Z",
  "latest_version": 1,
  "links": {
    "versions": "https://events.twilio.com/v1/Schemas/Messaging.MessageStatus/Versions"
  }
}
```
