# SMS Routing

## Routes <a href="#routes" id="routes"></a>

Routes are the functions that are executed each time that an inbound SMS message is received by an Accent DID. Currently, there are three (3) types of routes:

* `EMAIL` Routes: These routes will send inbound SMS messages to an e-mail address, which also allows for users to respond to the SMS message with a simple reply to the e-mail.
* `HTTP-POST` Routes: This route is also known as an "incoming webhook" and allows for users to receive inbound SMS messages at an HTTP endpoint of their choosing.
* `HTTP-GET` Routes: Similar to `HTTP-POST` routes, this type of route allows for users to receive inbound SMS messages at an HTTP endpoint of their choosing.

## Get All Routes

Retrieve all routes for a given DID.

```
curl "https://sms.accentvoice.com/api/v2/<DID Number>/routes?key=<API Key>"
```

> This request returns a JSON payload of this structure:

```
[
    {
        "id": 34,
        "did_id": 1,
        "type": "EMAIL",
        "payload": "david@xyz.com",
        "priority": 2,
        "active": 1,
        "updated_at": "2019-03-18 14:38:04",
        "created_at": "2019-03-18 14:38:04"
    },
    {
        "id": "44",
        "did_id": 1,
        "type": "EMAIL",
        "payload": "david@abc.com",
        "priority": 1,
        "active": 1,
        "updated_at": "2019-03-12 12:16:44",
        "created_at": "2019-03-12 12:16:44"
    }
]
```

This endpoint retrieves all routes for a given DID.

#### HTTP Request <a href="#http-request-2" id="http-request-2"></a>

`GET https://sms.accentvoice.com/api/v2/<DID Number>/routes?key=<API Key>`

#### Query Parameters <a href="#query-parameters-2" id="query-parameters-2"></a>

None

Remember: For API `GET` requests, your API Key must be provided as a URL parameter!

## Get a Specific Route

```
curl "https://sms.accentvoice.com/api/v2/<DID Number>/routes/44/?key=<API Key>"
```

> This request returns a JSON payload of this structure:

```
{
    "id": "44",
    "did_id": 1,
    "type": "EMAIL",
    "payload": "david@xyz.com",
    "priority": 1,
    "active": 1,
    "updated_at": "2019-03-12 12:16:44",
    "created_at": "2019-03-12 12:16:44"
}
```

This endpoint retrieves a specific route for a given DID.

#### HTTP Request <a href="#http-request-3" id="http-request-3"></a>

`GET https://sms.accentvoice.com/api/v2/<DID Number>/routes/<Route ID>/?key=<API Key>`

#### URL Parameters <a href="#url-parameters" id="url-parameters"></a>

None

## Delete a Specific Route

```
curl "https://sms.accentvoice.com/api/v2/<DID Number>/routes/44/"
  -X DELETE
```

> This request returns a JSON payload of this structure:

```

{
   "error": false,
   "success": true,´
   "message": "Route with ID 44 was successfully deleted."
 }

```

This request deletes a route, and has this response:

#### HTTP Request <a href="#http-request-4" id="http-request-4"></a>

`DELETE https://sms.accentvoice.com/api/v2/<DID Number>/routes/44/`

#### URL Parameters <a href="#url-parameters-2" id="url-parameters-2"></a>

| Parameter | Description                   | Required |
| --------- | ----------------------------- | -------- |
| ID        | The ID of the route to delete | Yes      |

## Create a New Route

> `EMAIL` Route

```
curl "https://sms.accentvoice.com/api/v2/<DID Number>/routes/"
  -X POST
{
    "key": "<API Key>",
    "type": "EMAIL",
    "payload": "your-email@address.us"
}
```

> This request creates a new `EMAIL` route, and has this response:

```
{
  "error": false,
  "success": true,
  "route": {
      "did_id": 1,
      "type": "EMAIL",
      "payload": "david@xyz.com",
      "priority": 64,
      "active": 1,
      "updated_at": "2019-03-18 14:38:04",
      "created_at": "2019-03-18 14:38:04",
      "id": 34
  }
}
```

> `HTTP-POST` Route

```
curl "https://sms.accentvoice.com/api/v2/<DID Number>/routes/"
  -X POST
{
    "key": "<API Key>",
    "type": "HTTP-POST",
    "payload": {
        "url": "https://test-website.braves.com/endpoint",
        "headers": { // Headers are always optional.
            "header1": "value1",
            "header2": "value2"
        }
    }
}
```

> This request creates a new `HTTP-POST` route, and has this response:

```
{
  "error": false,
  "success": true,
  "route": {
      "did_id": 1,
      "type": "HTTP-POST",
      "payload": {
          "url": "https://test-website.braves.com/endpoint",
          "headers": { // Headers are always optional.
              "header1": "value1",
              "header2": "value2"
          }
      },
      "priority": 64,
      "active": 1,
      "updated_at": "2019-03-18 14:38:04",
      "created_at": "2019-03-18 14:38:04",
      "id": 34
  }
}
```

> `HTTP-GET` Route

```
curl "https://sms.accentvoice.com/api/v2/<DID Number>/routes/"
  -X POST
{
    "key": "<API Key>",
    "type": "HTTP-GET",
    "payload": {
        "url": "https://test-website.braves.com/endpoint",
        "headers": { // Headers are always optional.
            "header1": "value1",
            "header2": "value2"
        }
    }
}
```

> This request creates a new `HTTP-GET` route, and has this response:

```
{
  "error": false,
  "success": true,
  "route": {
      "did_id": 1,
      "type": "HTTP-GET",
      "payload": {
          "url": "https://test-website.braves.com/endpoint",
          "headers": { // Headers are always optional.
              "header1": "value1",
              "header2": "value2"
          }
      },
      "priority": 64,
      "active": 1,
      "updated_at": "2019-03-18 14:38:04",
      "created_at": "2019-03-18 14:38:04",
      "id": 34
  }
}
```

This endpoint creates a new route for a DID. You *must* choose a route type before creating a route.

#### HTTP Request <a href="#http-request-5" id="http-request-5"></a>

`POST https://sms.accentvoice.com/api/v2/<DID Number>/routes/`

#### Request Body Parameters <a href="#request-body-parameters" id="request-body-parameters"></a>

| Parameter | Description                         | Required |
| --------- | ----------------------------------- | -------- |
| type      | `EMAIL`, `HTTP-POST`, or `HTTP-GET` | Yes      |
| payload   | Route-specific payload              | Yes      |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guides.accentvoice.com/sms-api/routing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
