Inbound routing

Get a list of SMS inbound routes

If you want to retrieve information about multiple SMS inbound routes, use this GET request:

GET https://api.mailersend.com/v1/sms-inbounds

Request parameters

Query parameterTypeRequiredLimitationsDetails
sms_number_idstringno
enabledbooleanno
pageintno
limitintnoMin: 10, Max: 100Default: 25
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$smsRecipients = $mailersend->smsInbound->getAll($smsNumberId = 'sms_number_id', $enabled = true, $page = 3, $limit = 15);

More examplesopen in new window

import 'dotenv/config';
import { MailerSend } from "mailersend";

const mailerSend = new MailerSend({
  apiKey: process.env.API_KEY,
});

mailerSend.sms.inbound.list({
  enabled: 1,
  sms_number_id: "sms_number_id",
  limit: 10,
  page: 1,
})
  .then((response) => console.log(response.body))
  .catch((error) => console.log(error.body));

More examplesopen in new window

from mailersend import sms_inbounds

api_key = "API key here"

mailer = sms_inbounds.NewSmsInbounds(api_key)

#Request parameters
sms_number_id = "123456789"
enabled = True
page = 1
limit = 25

print(mailer.get_inbound_routes(sms_number_id, enabled, page, limit))

More examplesopen in new window

package main

import (
	"context"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

var APIKey = "Api Key Here"

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(APIKey)

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()

	listOptions := &mailersend.ListSmsInboundOptions{
		SmsNumberId: "sms-number-id",
	}
	
	_, _, err := ms.SmsInbound.List(ctx, listOptions)
	if err != nil {
		log.Fatal(err)
	}
}

More examplesopen in new window

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.sms.inboundroutes.SmsInboundRoute;
import com.mailersend.sdk.sms.inboundroutes.SmsInboundRouteList;

public void getSmsInboundRoutes() {
    
    MailerSend ms = new MailerSend();
    ms.setToken("mailersend token");
    
    try {
        
        SmsInboundRouteList routes = ms.sms().inboundRoutes().getSmsInboundRoutes();
        
        for (SmsInboundRoute route : routes.routes) {
            
            System.out.println(route.id);
        }
        
        
    } catch (MailerSendException e) {
        
        e.printStackTrace();
    }
}

More examplesopen in new window

require "mailersend-ruby"

# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new

ms_sms_inbounds.list

More examplesopen in new window

Responses

Valid

Response Code: 200 OK
Response Headers:
	Content-Type: application/json
{
  "data": [
    {
      "id": "7z3m5jgrogdpyo6n",
      "name": "Inbound",
      "filter": {
        "value": "START",
        "comparer": "equal"
      },
      "forward_url": "https://yourapp.com/hook",
      "enabled": true,
      "secret": "jYhafGtTiZgw0qWxlkUA7cbqTG3Zfh2j",
      "created_at": "2022-01-01T12:00:00.000000Z"
    }
  ]
}

Error

Response Code: 404 Not Found

Get a single SMS inbound route

If you want to retrieve a single SMS inbound route, use this GET request:

GET https://api.mailersend.com/v1/sms-inbounds/{sms_inbound_id}

Request parameters

URL parameterTypeRequiredLimitationsDetails
sms_inbound_idstringyes
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$smsRecipients = $mailersend->smsInbound->find('sms_inbound_id');

More examplesopen in new window

import 'dotenv/config';
import { MailerSend } from "mailersend";

const mailerSend = new MailerSend({
  apiKey: process.env.API_KEY,
});

mailerSend.sms.inbound.single("sms_inbound_id")
  .then((response) => console.log(response.body))
  .catch((error) => console.log(error.body));

More examplesopen in new window

from mailersend import sms_inbounds

api_key = "API key here"

mailer = sms_inbounds.NewSmsInbounds(api_key)

#Request parameters
sms_inbound_id = "123456789"

print(mailer.get_inbound_route(sms_inbound_id))

More examplesopen in new window

package main

import (
	"context"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

var APIKey = "Api Key Here"

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(APIKey)

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()

	_, _, err := ms.SmsInbound.Get(ctx, "sms-inbound-id")
	if err != nil {
		log.Fatal(err)
	}
	
}

More examplesopen in new window

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.sms.inboundroutes.SmsInboundRoute;

public void getSmsInboundRoute() {
    
    MailerSend ms = new MailerSend();
    ms.setToken("mailersend token");
    
    try {
        
        SmsInboundRoute route = ms.sms().inboundRoutes().getSmsInboundRoute("route id");
        
        System.out.println(route.id);
        
        
    } catch (MailerSendException e) {
        
        e.printStackTrace();
    }
}

More examplesopen in new window

require "mailersend-ruby"

# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new

# Add parameters
ms_sms_inbounds.get_sms_inbound_route(sms_inbound_id: 'your-sms-inbound-id')

More examplesopen in new window

Responses

Valid

Response Code: 200 OK
Response Headers:
	Content-Type: application/json
{
  "data": {
    "id": "7z3m5jgrogdpyo6n",
    "name": "Inbound",
    "filter": {
      "value": "START",
      "comparer": "equal"
    },
    "forward_url": "https://yourapp.com/hook",
    "enabled": true,
    "secret": "jYhafGtTiZgw0qWxlkUA7cbqTG3Zfh2j",
    "created_at": "2022-01-13T12:00:00.000000Z",
    "sms_number": {
      "id": "7z3m5jgrogdpyo6n",
      "telephone_number": "+19199876543",
      "paused": false,
      "created_at": "2022-01-13T12:00:00.000000Z"
    }
  }
}

Error

Response Code: 404 Not Found

Add an SMS inbound route

If you want to add a new SMS inbound route to a domain, use this POST request:

POST https://api.mailersend.com/v1/sms-inbounds

Request body

{
    "sms_number_id": "7z3m5jgrogdpyo6n",
    "name": "Inbound",
    "forward_url": "https://yourapp.com/hook",
    "filter": {
      "comparer": "equal",
      "value": "START"
    },
    "enabled": true
  }
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsInbound;
use MailerSend\Helpers\Builder\SmsInboundFilter;

$mailersend = new MailerSend(['api_key' => 'key']);

$smsInboundParams = (new SmsInbound())
    ->setSmsNumberId('sms_number_id')
    ->setName('Name')
    ->setForwardUrl('https://mailersend.com/inbound_webhook')
    ->setFilter(new SmsInboundFilter($comparer = 'starts-with', $value = 'Stop'))
    ->setEnabled(true);

$smsRecipients = $mailersend->smsInbound->create($smsInboundParams);

More examplesopen in new window

import 'dotenv/config';
import { MailerSend, SmsInbound } from "mailersend";

const mailerSend = new MailerSend({
  apiKey: process.env.API_KEY,
});

const smsInbound = new SmsInbound()
  .setSmsNumberId("sms_number_id")
  .setEnabled(true)
  .setName("Inbound Name")
  .setForwardUrl("yourapp.com/hook")
  .setFilter({
    comparer: "equal",
    value: "START"
  });

mailerSend.sms.inbound.create(smsInbound)
  .then((response) => console.log(response.body))
  .catch((error) => console.log(error.body));

More examplesopen in new window

from mailersend import sms_inbounds

api_key = "API key here"

mailer = sms_inbounds.NewSmsInbounds(api_key)

#Request parameters
sms_number_id = "123456789"
name = "My route"
forward_url = "https://some.url"
filter = {
    "comparer": "equal",
    "value": "START"
}
enabled = True

print(mailer.create_inbound_route(sms_number_id, name, forward_url, filter, enabled))

More examplesopen in new window

require "mailersend-ruby"

# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new

# Add parameters
ms_sms_inbounds.settings =
  {
    'forward_url' => 'https://your-forward-url',
    'name' => 'name',
    'events' => ['sms.sent', 'sms.delivered'],
    'sms_number_id' => 'your-sms-number-id'
  }
puts ms_sms_inbounds.add_sms_inbound_route

More examplesopen in new window

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.sms.inboundroutes.SmsInboundRoute;

public void addSmsInboundRoute() {
    
    MailerSend ms = new MailerSend();
    ms.setToken("mailersend token");
    
    try {
        
        SmsInboundRoute route = ms.sms().inboundRoutes().builder()
                .smsNumberId("sms number id")
                .name("Test inbound route")
                .enabled(false)
                .forwardUrl("https://example.com")
                .filter("equal", "START")
                .addSmsInboundRoute();
        
        System.out.println(route.id);
        
        
    } catch (MailerSendException e) {
        
        e.printStackTrace();
    }
}

More examplesopen in new window

require "mailersend-ruby"

# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new

# Add parameters
ms_sms_inbounds.settings =
  {
    'forward_url' => 'https://your-forward-url',
    'name' => 'name',
    'events' => ['sms.sent', 'sms.delivered'],
    'sms_number_id' => 'your-sms-number-id'
  }
puts ms_sms_inbounds.add_sms_inbound_route

More examplesopen in new window

Request Parameters

JSON parameters are provided in dot notation

JSON ParameterTypeRequiredLimitationsDetails
sms_number_idstringYes
namestringYesMax 191 characters.
forward_urlstringYesMax 255 characters.
filterobjectNo
filter.comparerstringYes*Must be one of the comparers: equal, not-equal, contains, not-contains, starts-with, ends-with, not-starts-with, not-ends-with.
filter.valuestringYes*Max 255 characters.
enabledbooleanNo
* Required if filter is added.

Responses

Response KeyTypeDetails
dataobjectSMS Inbound object created.

Valid

Response Code: 201 CREATED
Response Headers:
	Content-Type: application/json
{
  "data": {
    "id": "7z3m5jgrogdpyo6n",
    "name": "Inbound",
    "filter": {
      "value": "START",
      "comparer": "equal"
    },
    "forward_url": "https://yourapp.com/hook",
    "enabled": true,
    "secret": "jYhafGtTiZgw0qWxlkUA7cbqTG3Zfh2j",
    "created_at": "2022-01-01T12:00:00.000000Z"
  }
}

Invalid

Response Code: 422 Unprocessable Entity

See - Validation errors

Update an inbound route

If you want to update the information of an existing inbound route, use this PUT request:

PUT https://api.mailersend.com/v1/sms-inbounds/{sms_inbound_id}

Request body

{
    "sms_number_id": "7z3m5jgrogdpyo6n",
    "name": "Inbound",
    "forward_url": "https://yourapp.com/hook",
    "filter": {
      "comparer": "equal",
      "value": "START"
    },
    "enabled": true
}
use MailerSend\MailerSend;
use MailerSend\Helpers\Builder\SmsInbound;
use MailerSend\Helpers\Builder\SmsInboundFilter;

$mailersend = new MailerSend(['api_key' => 'key']);

$smsInboundParams = (new SmsInbound())
    ->setSmsNumberId('sms_number_id')
    ->setName('Name')
    ->setForwardUrl('https://mailersend.com/inbound_webhook')
    ->setFilter(new SmsInboundFilter($comparer = 'starts-with', $value = 'Stop'))
    ->setEnabled(true);

$smsRecipients = $mailersend->smsInbound->update('sms_inbound_id', $smsInboundParams);

More examplesopen in new window

import 'dotenv/config';
import { MailerSend, SmsInbound } from "mailersend";

const mailerSend = new MailerSend({
  apiKey: process.env.API_KEY,
});

const smsInbound = new SmsInbound()
  .setSmsNumberId("sms_number_id")
  .setEnabled(true)
  .setName("Inbound Name Update")
  .setForwardUrl("yourapp.com/hook")
  .setFilter({
    comparer: "equal",
    value: "START"
  });

mailerSend.sms.inbound.update("sms_inbound_id", {...smsInbound})
  .then((response) => console.log(response.body))
  .catch((error) => console.log(error.body));

More examplesopen in new window

from mailersend import sms_inbounds

api_key = "API key here"

mailer = sms_inbounds.NewSmsInbounds(api_key)

#Request parameters
sms_number_id = "123456789"
name = "New name"
forward_url = "https://news.url"
filter = {
    "comparer": "contains",
    "value": "some-value"
}
enabled = True

print(mailer.update_inbound_route(sms_number_id, name, forward_url, filter, enabled))

More examplesopen in new window

require "mailersend-ruby"

# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new

# Add parameters
ms_sms_inbounds.settings =
  {
    'forward_url' => 'https://your-forward-url',
    'name' => 'name',
    'events' => ['sms.sent', 'sms.delivered'],
    'sms_number_id' => 'your-sms-number-id'
  }
puts ms_sms_inbounds.update_sms_inbound_route(sms_inbound_id: 'your-sms-inbound-id')

More examplesopen in new window

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.sms.inboundroutes.SmsInboundRoute;

public void updateSmsInboundRoute() {
    
    MailerSend ms = new MailerSend();
    ms.setToken("mailersend token");
    
    try {
        
        SmsInboundRoute route = ms.sms().inboundRoutes().builder()
                .smsNumberId("sms number id")
                .name("Test inbound route updated")
                .enabled(false)
                .forwardUrl("https://example.com")
                .filter("equal", "START")
                .updateSmsInboundRoute("route id");
        
        System.out.println(route.name);
        
    } catch (MailerSendException e) {
        
        e.printStackTrace();
    }
}

More examplesopen in new window

require "mailersend-ruby"

# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new

# Add parameters
ms_sms_inbounds.settings =
  {
    'forward_url' => 'https://your-forward-url',
    'name' => 'name',
    'events' => ['sms.sent', 'sms.delivered'],
    'sms_number_id' => 'your-sms-number-id'
  }
puts ms_sms_inbounds.update_sms_inbound_route(sms_inbound_id: 'your-sms-inbound-id')

More examplesopen in new window

Request Parameters

URL parameterTypeRequiredLimitationsDetails
sms_inbound_idstringyes

JSON parameters are provided in dot notation

JSON ParameterTypeRequiredLimitationsDetails
sms_number_idstringNo
namestringNoMax 191 characters.
forward_urlstringNoMax 255 characters.
filterobjectNo
filter.comparerstringYes*Must be one of the comparers: equal, not-equal, contains, not-contains, starts-with, ends-with, not-starts-with, not-ends-with.
filter.valuestringYes*Max 255 characters.
enabledbooleanNo
* Required if inbound is not enabled.

Responses

Response KeyTypeDetails
dataobjectSMS Inbound object created.

Valid

Response Code: 200 OK
Response Headers:
	Content-Type: application/json
{
  "data": {
    "id": "7z3m5jgrogdpyo6n",
    "name": "Inbound",
    "filter": {
      "value": "START",
      "comparer": "equal"
    },
    "forward_url": "https://yourapp.com/hook",
    "enabled": true,
    "secret": "jYhafGtTiZgw0qWxlkUA7cbqTG3Zfh2j",
    "created_at": "2022-01-01T12:00:00.000000Z"
  }
}

Invalid

Response Code: 422 Unprocessable Entity

See - Validation errors

Delete an SMS inbound route

If you want to delete an SMS inbound route, use this DELETE request:

DELETE https://api.mailersend.com/v1/sms-inbounds/{sms_inbound_id}

Request parameters

URL parameterTypeRequiredLimitationsDetails
sms_inbound_idstringyes
use MailerSend\MailerSend;

$mailersend = new MailerSend(['api_key' => 'key']);

$smsRecipients = $mailersend->smsInbound->delete('sms_inbound_id');

More examplesopen in new window

import 'dotenv/config';
import { MailerSend } from "mailersend";

const mailerSend = new MailerSend({
  apiKey: process.env.API_KEY,
});

mailerSend.sms.inbound.delete("sms_inbound_id")
  .then((response) => console.log(response.body))
  .catch((error) => console.log(error.body));

More examplesopen in new window

from mailersend import sms_inbounds

api_key = "API key here"

mailer = sms_inbounds.NewSmsInbounds(api_key)

#Request parameters
sms_inbound_id = "123456789"

print(mailer.delete_inbound_route()(sms_inbound_id))

More examplesopen in new window

package main

import (
	"context"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

var APIKey = "Api Key Here"

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(APIKey)

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()

	_, err := ms.SmsInbound.Delete(ctx, "sms-inbound-id")
	if err != nil {
		log.Fatal(err)
	}
}

More examplesopen in new window

import com.mailersend.sdk.MailerSend;
import com.mailersend.sdk.exceptions.MailerSendException;
import com.mailersend.sdk.sms.inboundroutes.SmsInboundRoute;

public void deleteSmsInboundRoute() {
    
    MailerSend ms = new MailerSend();
    ms.setToken("mailersend token");
    
    try {
        
        boolean result = ms.sms().inboundRoutes().deleteSmsInboundRoute("route id");
        
        System.out.println(result);
        
    } catch (MailerSendException e) {
        
        e.printStackTrace();
    }
}

More examplesopen in new window

require "mailersend-ruby"

# Intialize the SMS Inbounds class
ms_sms_inbounds = Mailersend::SMSInbounds.new

# Add parameters
ms_sms_inbounds.delete_sms_inbound_route(sms_inbound_id: 'your-sms-inbound-id')

More examplesopen in new window

Responses

Valid

Response Code: 200 OK

Error

Response Code: 404 Not Found
Last Updated: