# Notify: SMS Notifications Quickstart

> \[!CAUTION]
>
> Twilio deprecated Notify in October 2022 and no longer supports it. Learn more about [transitioning off Notify](https://support.twilio.com/hc/en-us/articles/11746930233115-Transitioning-off-Notify).
>
> If you're starting a new project, use [Programmable Messaging](/docs/messaging) for SMS notifications. For push notifications, integrate directly with platform-specific services such as APNs for iOS or FCM for Android. If you've already built on Notify, visit the [transition guide](https://support.twilio.com/hc/en-us/articles/11746930233115-Transitioning-off-Notify) to learn about your options.

With this Quickstart, you will be able to send an SMS Notification from scratch (no previous code writing experience needed).

What we will do:

* [Purchase a Twilio Phone Number](#purchase-a-twilio-phone-number)
* [Create Messaging Service](#create-a-messaging-service)
* [Set up Notify Service Instance](#set-up-notify-service-instance)
* [Gather Twilio account information](#gather-account-information)
* [Create a Binding for SMS](#optional-create-a-binding-for-sms)
* [Send an SMS Notification](#send-an-sms-notification)

Before we get started, please, read the following note:

> \[!WARNING]
>
> It is best practice, and also potentially required by law in certain jurisdictions, for you to have consent from your end users before sending messages to them, and you should respect your end users' choice to not receive messages from you. It is also important to make sure your database is up to date. This is particularly important for number-based communications like SMS because over time phone numbers may be reassigned to different individuals. If your database is out of date, you could inadvertently send a message to someone who did not consent but was reassigned a phone number that was previously subscribed to your service by another person. Check out the [Twilio Marketplace for Add-ons](/docs/marketplace) from our partners that can help you keep your database up to date.
>
> Twilio recommends that you consult with your legal counsel to make sure that you are complying with all applicable laws in connection with communications you transmit using Twilio.

## Purchase a Twilio Phone Number

***

The first thing you need in order to send an SMS notification is a Twilio-powered phone number. [You can grab one to use in the console here](/console/phone-numbers/search) by going to the Numbers tab to add a phone number. Make sure that it has SMS enabled!

![Twilio dashboard showing active phone numbers with SMS Quickstart messaging service.](https://docs-resources.prod.twilio.com/bae18d67c1a2eba6273f4f7392ed234ea3d81c2f4b86a355e06dd5ee0e9e5f9e.png)

Now for Notify to use this Phone number, we need to add it to Messaging Service and associate it with Notify Service Instance.

## Create a Messaging Service

***

Go to console [Programmable SMS -> Messaging Service](/console/sms/services)

Create a new Messaging Service.

![Step 1 of Messaging Service Setup, naming service 'SMS Quickstart' for user notifications.](https://docs-resources.prod.twilio.com/5824c1eeaf9b550652164cdd99f1f2d22ec01c51a5e0e5adb1eff7a3c401078a.png)

Messaging Services allow you to organize your messages and enable specific features for groups of messages. It has a lot of cool features and you can read about them [in the docs](/docs/messaging/tutorials/send-messages-with-messaging-services), but now we just need it to send SMS from your new Twilio Phone Number.

To do that, add your new Twilio Phone Number to the Messaging Service

![Add phone number to Twilio messaging service with selected number and add button highlighted.](https://docs-resources.prod.twilio.com/fafc2c505af3f878b4d2c18d3597e69ac592e9ce4dfd1fc802063461856ec1e3.png)

Now that we have a Phone Number and a Messaging Service, we must create a Notify Service Instance that we'll use the new Twilio Phone Number to send SMS Notifications.

## Set up Notify Service Instance

***

[In the console, create a Notify Service](/console/notify/services). Make note of the SID! You will use this later when you start writing code further down.

![Services table with SMS Quickstart entry and add service button highlighted.](https://docs-resources.prod.twilio.com/263bbf4aedc5859de174217be60b73a9c231d8e811d21cd00aa2d68d0a54d56f.png)

Now choose your new Messaging Service for this Notify Service Instance

![Configure SMS Quickstart with Messaging Service SID highlighted.](https://docs-resources.prod.twilio.com/f0ccb55745b5d2fefa1051724570bc493214831d621eb9754870137c464477db.png)

Next, we will gather account information and start writing a bit of code.

## Gather account information

***

| Config Value         | Description                                                                                                                                                                            |
| :------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Account SID          | Used to authenticate REST API requests - [find it in the console here](/user/account/settings).                                                                                        |
| Auth Token           | Used to authenticate REST API requests - [like the Account SID, find it in the console here](/user/account/settings).                                                                  |
| Service Instance SID | A [Notify Service](/docs/notify/api/service-resource) instance where all the data for our application is stored and scoped. We created it in Twilio console in the previous paragraph. |

Now we're ready to write some code!

## (Optional) Create a binding for SMS

***

This step is optional. If you do not want to store the phone numbers of your users in Notify to manage all contact information in one place, you can just skip ahead to [Send an SMS Notification](#send-an-sms-notification).

A [Binding](/docs/notify/api/binding-resource) is a combination of a user and a device that can receive a notification. You can find out more about bindings and how to create, list, retrieve or delete them, under [REST API - > Bindings menu](/docs/notify/api/binding-resource).

In this example, we will create a binding with type 'sms'.

You will need:

* Your account information (gathered [above](#gather-account-information))
* User Identity - this is a unique identifier of the user. In this example it's `00000001`, but it's up to you, how you identify your users. The only requirement - it has to be unique and not Personally Identifiable Information.
* User's phone number (parameter 'Address') - for testing purposes, let's create a binding with your mobile phone number so you can actually receive it. In the example, it's `+1651000000000`

Here, we use the REST API to create a Binding

Create a Binding for SMS

```js
// Download the Node helper library from www.twilio.com/docs/libraries/node#installation
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
// To set up environmental variables, see http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);

const bindingOpts = {
  identity: '00000001', // We recommend using a GUID or other anonymized identifier for Identity.
  bindingType: 'sms',
  address: '+1651000000000',
};

client.notify
  .services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
  .bindings.create(bindingOpts)
  .then(binding => console.log(binding.sid))
  .catch(error => console.log(error))
  .done();
```

```py
#!/usr/bin/env python
# Install the Python helper library from twilio.com/docs/python/install
import os

from twilio.rest import Client

# To set up environmental 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)
binding = client.notify.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
    .bindings.create(
        # We recommend using a GUID or other anonymized identifier for Identity
        identity='00000001',
        binding_type='sms',
        address='+1651000000000')
print(binding.sid)
```

```cs
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using System.Collections.Generic;
using Twilio;
using Twilio.Rest.Notify.Service;

public class Example
{
    public static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
        const string serviceSid = Environment.GetEnvironmentVariable("TWILIO_SERVICE_SID");

        TwilioClient.Init(accountSid, authToken);

        var binding = BindingResource.Create(
                        serviceSid,
                        "00000001", // We recommend using a GUID or other anonymized identifier for Identity.
                        BindingResource.BindingTypeEnum.Sms,
                        "+1651000000000");

        Console.WriteLine(binding.Sid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.notify.service.Binding;

public class Example {
  // Get your Account SID and Auth Token from https://twilio.com/console
  // To set up 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 final String SERVICE_SID = System.getenv("TWILIO_SERVICE_SID");

  public static void main(String[] args) {
    // Initialize the client
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Binding binding = Binding.creator
    (
      SERVICE_SID,
      "00000001", // We recommend using a GUID or other anonymized identifier for Identity.
      Binding.BindingType.SMS,
      "+1651000000000"
    ).create();

    System.out.println(binding.getSid());
  }
}
```

```php
<?php
// NOTE: This example uses the next generation Twilio helper library - for more
// information on how to download and install this version, visit
// https://www.twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php';

use Twilio\Rest\Client;

// Your Account SID and Auth Token from https://www.twilio.com/console
// To set up environmental variables, see http://twil.io/secure
$accountSid = getenv('TWILIO_ACCOUNT_SID');
$authToken = getenv('TWILIO_AUTH_TOKEN');

$serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Initialize the client
$client = new Client($accountSid, $authToken);

// Create a binding
$binding = $client
    ->notify->services($serviceSid)
    ->bindings->create(
        '00000001', // We recommend using a GUID or other anonymized identifier for Identity.
        'sms',
        '+1651000000000'
    );

echo $binding->sid;
```

```rb
# Download the Ruby helper library from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account Sid and Auth Token from https://www.twilio.com/console
# To set up environmental 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)

service = client.notify.v1.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')

binding = service.bindings.create(
  identity: '00000001',
  binding_type: 'sms',
  address: 'Address=+1651000000000'
)

puts binding.sid
```

```bash
curl -X POST 'https://notify.twilio.com/v1/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Bindings' \
--data-urlencode 'Identity=00000001'  \
--data-urlencode 'BindingType=sms'  \
--data-urlencode 'Address=+1651000000000'  \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
```

> \[!CAUTION]
>
> Notify uses `Identity` as a unique identifier of a user. You should not use directly identifying information (aka personally identifiable information or PII) like a *person's name, home address, email or phone number,* as Identity because the systems that will process this attribute assume it is not directly identifying information.

Now that we have a binding, all we need to do is send an SMS notification!

## Send an SMS Notification

***

In this step, we will send an SMS. If you created a Binding in the previous step we are going to use that if not you can just provide the phone number(s) you want to message directly in the request.

You will need:

* Your account information (gathered [above](#gather-account-information))
* User's Identity or phone number, to whom you want to send the SMS (Note, if you are using Identity then a binding between the Identity and the phone number has to be created first. See an example at [Create a Binding for SMS](#optional-create-a-binding-for-sms).)
* Body - text of the message to be sent.

Here, we use the REST API to send an SMS Notification using Identity

Send SMS Notification Using Identity

```js
// Download the Node helper library from www.twilio.com/docs/libraries/node#installation
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
// To set up environmental variables, see http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);

const notificationOpts = {
  identity: '00000001', // We recommend using a GUID or other anonymized identifier for Identity.
  body: 'Knok-Knok! This is your first Notify SMS',
};

client.notify
  .services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
  .notifications.create(notificationOpts)
  .then(notification => console.log(notification.sid))
  .catch(error => console.log(error));
```

```py
#!/usr/bin/env python
# Install the Python helper library from twilio.com/docs/python/install
import os

from twilio.rest import Client

# To set up environmental 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)
notification = client.notify.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
    .notifications.create(
        # We recommend using a GUID or other anonymized identifier for Identity
        identity='00000001',
        body='Knok-Knok! This is your first Notify SMS')
print(notification.sid)
```

```cs
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using System.Collections.Generic;
using Twilio;
using Twilio.Rest.Notify.Service;

public class Example
{
    public static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
        const string serviceSid = Environment.GetEnvironmentVariable("TWILIO_SERVICE_SID");

        TwilioClient.Init(accountSid, authToken);

        var notification = NotificationResource.Create(
            serviceSid,
            identity: new List<string> { "00000001" },
            body: "Knok-Knok! This is your first Notify SMS");

        Console.WriteLine(notification.Sid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.notify.v1.service.Notification;

public class Example {
  // Get your Account SID and Auth Token from https://twilio.com/console
  // To set up 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 final String SERVICE_SID = System.getenv("TWILIO_SERVICE_SID");

  public static void main(String[] args) {
    // Initialize the client
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Notification notification = Notification
        .creator(SERVICE_SID)
        .setBody("Knok-Knok! This is your first Notify SMS")
        .setIdentity("00000001")
        .create();

    System.out.println(notification.getSid());
  }
}
```

```php
<?php
// NOTE: This example uses the next generation Twilio helper library - for more
// information on how to download and install this version, visit
// https://www.twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php';

use Twilio\Rest\Client;

// Your Account SID and Auth Token from https://www.twilio.com/console
// To set up environmental variables, see http://twil.io/secure
$accountSid = getenv('TWILIO_ACCOUNT_SID');
$authToken = getenv('TWILIO_AUTH_TOKEN');

$serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Initialize the client
$client = new Client($accountSid, $authToken);

// Create a notification
$notification = $client
    ->notify->services($serviceSid)
    ->notifications->create([
        'identity' => '00000001', # We recommend using a GUID or other anonymized identifier for Identity.
        'body' => 'Knok-Knok! This is your first Notify SMS'
    ]);

echo $notification->body; // => Knok-Knok! This is your first Notify SMS
```

```rb
# Download the Ruby helper library from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account Sid and Auth Token from https://www.twilio.com/console
# To set up environmental 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)

service = client.notify.v1.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')

notification = service.notifications.create(
  identity: '00000001',
  body: 'Knok-Knok! This is your first Notify SMS'
)

puts notification.sid
```

```bash
curl -X POST 'https://notify.twilio.com/v1/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Notifications' \
--data-urlencode 'Identity=00000001'  \
--data-urlencode 'Body=Knok-Knok! This is your first Notify SMS'  \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
```

Alternatively, you can just provide the phone number directly. If you want to send an SMS to multiple phone numbers, just add more ToBinding parameters.

Send SMS Notification To a Number

```js
// Download the Node helper library from www.twilio.com/docs/libraries/node#installation
// These identifiers are your accountSid and authToken from
// https://www.twilio.com/console
// To set up environmental variables, see http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);

const notificationOpts = {
  toBinding: JSON.stringify({
    binding_type: 'sms',
    address: '+1651000000000',
  }),
  body: 'Knock-Knock! This is your first Notify SMS',
};

client.notify
  .services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
  .notifications.create(notificationOpts)
  .then(notification => console.log(notification.sid))
  .catch(error => console.log(error));
```

```py
#!/usr/bin/env python
# Install the Python helper library from twilio.com/docs/python/install
import os

from twilio.rest import Client

# To set up environmental 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)
notification = client.notify.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX') \
    .notifications.create(
        to_binding='{"binding_type":"sms", "address":"+1651000000000"}',
        body='Knok-Knok! This is your first Notify SMS')
print(notification.sid)
```

```cs
// Download the twilio-csharp library from twilio.com/docs/libraries/csharp
using System;
using System.Collections.Generic;
using Twilio;
using Twilio.Rest.Notify.Service;

public class Example
{
    public static void Main(string[] args)
    {
        // Find your Account SID and Auth Token at twilio.com/console
        // To set up environmental variables, see http://twil.io/secure
        const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        const string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");
        const string serviceSid = Environment.GetEnvironmentVariable("TWILIO_SERVICE_SID");

        TwilioClient.Init(accountSid, authToken);

        var notification = NotificationResource.Create(
            serviceSid,
            toBinding: new List<string> { "{\"binding_type\":\"sms\",\"address\":\"+1651000000000\"}"}
            body: "Knok-Knok! This is your first Notify SMS");

        Console.WriteLine(notification.Sid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install
import com.twilio.Twilio;
import com.twilio.rest.notify.v1.service.Notification;

public class Example {
  // Get your Account SID and Auth Token from https://twilio.com/console
  // To set up 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 final String SERVICE_SID = System.getenv("TWILIO_SERVICE_SID");

  public static void main(String[] args) {
    // Initialize the client
    Twilio.init(ACCOUNT_SID, AUTH_TOKEN);

    Notification notification = Notification
        .creator(SERVICE_SID)
        .setBody("Knok-Knok! This is your first Notify SMS")
        .setToBinding("{\"binding_type\":\"sms\",\"address\":\"+1651000000000\"}")
        .create();

    System.out.println(notification.getSid());
  }
}
```

```php
<?php
// NOTE: This example uses the next generation Twilio helper library - for more
// information on how to download and install this version, visit
// https://www.twilio.com/docs/libraries/php
require_once '/path/to/vendor/autoload.php';

use Twilio\Rest\Client;

// Your Account SID and Auth Token from https://www.twilio.com/console
// To set up environmental variables, see http://twil.io/secure
$accountSid = getenv('TWILIO_ACCOUNT_SID');
$authToken = getenv('TWILIO_AUTH_TOKEN');

$serviceSid = "ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

// Initialize the client
$client = new Client($accountSid, $authToken);

// Create a notification
$notification = $client
    ->notify->services($serviceSid)
    ->notifications->create([
        "toBinding" => '{"binding_type":"sms", "address":"+1651000000000"}'
        'body' => 'Knok-Knok! This is your first Notify SMS'
    ]);

echo $notification->body; // => Knok-Knok! This is your first Notify SMS
```

```rb
# Download the Ruby helper library from twilio.com/docs/libraries/ruby
require 'twilio-ruby'

# Get your Account Sid and Auth Token from https://www.twilio.com/console
# To set up environmental 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)

service = client.notify.v1.services('ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')

notification = service.notifications.create(
  to_binding: '{"binding_type":"sms", "address":"+1651000000000"}',
  body: 'Knok-Knok! This is your first Notify SMS'
)

puts notification.sid
```

```bash
curl -X POST 'https://notify.twilio.com/v1/Services/ISXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Notifications' \
--data-urlencode 'ToBinding={"binding_type":"sms", "address":"+1651000000000"}'  \
--data-urlencode 'Body=Knok-Knok! This is your first Notify SMS'  \
-u 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token'
```

## What's next?

***

There's much more you can do with Notify. Try our other Quickstarts to send:

* [iOS Push Notification](/docs/notify/quickstart/ios)
* [Android Push Notifications](/docs/notify/quickstart/android)

Or learn how to [send Notifications to a group of users.](/docs/notify/send-notifications#sending-notifications)
