# Messaging API Overview

With the Programmable Messaging REST API, you can add messaging capabilities to your application.

## Base URLs

To ensure data privacy, Twilio serves its APIs over HTTPS.

Messaging-related APIs use three base URLs:

### Twilio API base URL

The following API resources that process SMS messages point to the Base URL of `https://api.twilio.com/2010-04-01`:

- [Messages resource](https://www.twilio.com/docs/messaging/api/message-resource "Messages resource")
  - [Feedback subresource](https://www.twilio.com/docs/messaging/api/message-feedback-resource "Feedback subresource")
  - [Media subresource](https://www.twilio.com/docs/messaging/api/media-resource "Media subresource")

The following API resources that manage [Messaging Services](https://www.twilio.com/docs/messaging/services "Messaging Services") point to `https://messaging.twilio.com/v1`:

- [Services resource](https://www.twilio.com/docs/messaging/api/service-resource "Services resource")
  - [PhoneNumbers subresource](https://www.twilio.com/docs/messaging/api/phonenumber-resource "PhoneNumbers subresource")
  - [Shortcodes subresource](https://www.twilio.com/docs/messaging/api/services-shortcode-resource "Shortcodes subresource")
  - [AlphaSenders subresource](https://www.twilio.com/docs/messaging/api/alphasender-resource "AlphaSenders subresource")
  - [DestinationAlphaSenders subresource](https://www.twilio.com/docs/messaging/api/destination-alphasender-resource "DestinationAlphaSenders subresource")
  - [ChannelSenders subresource](https://www.twilio.com/docs/messaging/api/messaging-service-channelsender-resource "ChannelSenders subresource")

The following API resources that report on deactivated phone numbers and process toll-free verification requests also point to `https://messaging.twilio.com/v1`:

- [Deactivations resource](https://www.twilio.com/docs/messaging/api/deactivations-resource "Deactivations resource")
- [Verifications resource](https://www.twilio.com/docs/messaging/api/tollfree-verification-resource "Verifications resource")

The API resource that reports on [per-country SMS pricing](https://www.twilio.com/docs/messaging/api/pricing "per-country SMS pricing") points to the `https://pricing.twilio.com/v1` base URL.

## Authentication

To authenticate requests to the Twilio APIs, Twilio supports [HTTP Basic authentication](https://en.wikipedia.org/wiki/Basic_access_authentication "HTTP Basic authentication"). Use your _API key_ as the username and your _API key secret_ as the password. You can create an API key either [in the Twilio Console](https://www.twilio.com/docs/iam/api-keys/keys-in-console "in the Twilio Console") or [using the API](https://www.twilio.com/docs/iam/api-keys/key-resource-v1 "using the API").

**Note**: Twilio recommends using API keys for authentication in production apps. For local testing, you can use your Account SID as the username and your Auth token as the password. You can find your Account SID and Auth Token in the [Twilio Console](https://www.twilio.com/console "Twilio Console").

Learn more about [Twilio API authentication](https://www.twilio.com/docs/usage/requests-to-twilio "Twilio API authentication").

Here's an example of authenticating with the API:

```bash
curl -G https://api.twilio.com/2010-04-01/Accounts \
     -u $TWILIO_API_KEY:$TWILIO_API_KEY_SECRET
```

## Use the Programmable Messaging API

Twilio monitors messages to prevent content violating the [Acceptable Use Policy](https://www.twilio.com/en-us/legal/aup "Acceptable Use Policy"). This helps to ensure that Twilio Messaging is seen as a trustworthy, high engagement channel and will not slow down the delivery of messages.

If a message you send has violated the AUP, it will be returned and you will receive an error code which identifies the necessary changes you need to make before sending it again.

### Send messages

To send an outbound message, send a `POST` request to the [Messages resource](https://www.twilio.com/docs/messaging/api/message-resource "Messages resource").

- To [send media messages](https://www.twilio.com/docs/messaging/tutorials/how-to-send-sms-messages "send media messages"), use the `MediaUrl` parameter in the request.
- To [schedule an outbound Message](https://www.twilio.com/docs/messaging/features/message-scheduling "schedule an outbound Message") to be sent in the future, use the `ScheduleType` and `SendAt` parameters in the request.
- To [send messages with shortened links](https://www.twilio.com/docs/messaging/features/link-shortening "send messages with shortened links"), use the `ShortenUrls` parameter in the request.
  - **Note**: This feature is available only if you use a [Messaging Service](https://www.twilio.com/docs/messaging/services "Messaging Service").

To learn more about how to receive and reply to messages, see [Receive and Reply to Messages Guide](https://www.twilio.com/docs/messaging/tutorials/how-to-receive-and-reply "Receive and Reply to Messages Guide").

### Fetch, list, update, and delete messages

Use the [Messages resources](https://www.twilio.com/docs/messaging/api/message-resource "Messages resources") to fetch, list, and delete Messages associated with your account.

Redact messages by updating a Message resource.

### Fetch, list, and delete media

Twilio creates a [Media subresource](https://www.twilio.com/docs/messaging/api/media-resource "Media subresource") when an incoming or outgoing Message resource contains media.

You can fetch, list, and delete Media subresources.

### Manage your short codes

Fetch, list, and update your Account's short codes with the [ShortCodes subresource](https://www.twilio.com/docs/messaging/api/short-code-resource "ShortCodes subresource").

### Track message feedback

Track user-reported outcomes of Messages with the [Feedback subresource](https://www.twilio.com/docs/messaging/api/message-feedback-resource "Feedback subresource").

### Manage your Messaging Services

Create, fetch, read, update, and delete Messaging Services with the [Services resource](https://www.twilio.com/docs/messaging/api/service-resource "Services resource").
Manage your Messaging Services' senders with the following subresources:

- [ShortCodes subresource](https://www.twilio.com/docs/messaging/api/services-shortcode-resource "ShortCodes subresource")
- [AlphaSenders subresource](https://www.twilio.com/docs/messaging/api/alphasender-resource "AlphaSenders subresource")
- [DestinationAlphaSenders subresource](https://www.twilio.com/docs/messaging/api/destination-alphasender-resource "DestinationAlphaSenders subresource")
- [PhoneNumbers subresource](https://www.twilio.com/docs/messaging/api/phonenumber-resource "PhoneNumbers subresource")
- [ChannelSenders subresource](https://www.twilio.com/docs/messaging/api/messaging-service-channelsender-resource "ChannelSenders subresource")

### Check SMS pricing by country

Check inbound and outbound SMS message pricing with the [Messaging Countries subresources](https://www.twilio.com/docs/messaging/api/pricing "Messaging Countries subresources") of the Pricing API.

### Retrieve a list of deactivated US phone numbers

Fetch a list of all US phone numbers that were deactivated on a given day with the [Deactivations resource](https://www.twilio.com/docs/messaging/api/deactivations-resource "Deactivations resource").

### Verify that your toll-free number complies with regulations

Demonstrate that your toll-free number complies with US and Canadian SMS regulations. Submit, update, or delete toll-free verification (TFV) requests with the [Verifications resource](https://www.twilio.com/docs/messaging/api/tollfree-verification-resource "Verifications resource").

## Additional resources

- [SMS developer quickstart](https://www.twilio.com/docs/messaging/quickstart "SMS developer quickstart")
- For inspiration, read the [Twilio Blog](https://www.twilio.com/blog/search-results?search=sms "Twilio Blog") on building messaging applications with various languages and tools.
- Get started with [toll-free verification](https://www.twilio.com/docs/messaging/compliance/toll-free/api-onboarding "toll-free verification").
- For help troubleshooting your Programmable Messaging application, check out the docs on [Debugging Common Issues](https://www.twilio.com/docs/messaging/guides/debugging-common-issues "Debugging Common Issues") and [Debugging Tools](https://www.twilio.com/docs/messaging/guides/debugging-tools "Debugging Tools").
- [Learn more about Twilio's Global Infrastructure](https://www.twilio.com/docs/global-infrastructure "Learn more about Twilio's Global Infrastructure"), which allows you to control where your application's Twilio-related data is routed, processed, and stored.
