Sending an SMS with Unicode

Nexmo's SMS API is easy to use and supports Unicode characters too. Sign up for an account and replace the following variables in the example below:

Key Description
TO_NUMBER The number you are sending the SMS to, for example 447700900000.
NEXMO_API_KEY You can find this in your Nexmo Dashboard.
NEXMO_API_SECRET You can find this in your Nexmo Dashboard.

Prerequisites

Initialize your dependencies

Create a file named send-an-sms-with-unicode.sh and add the following code:

Copy to Clipboard
source "../../config.sh"

View full source 

Write the code

Add the following to send-an-sms-with-unicode.sh:

Copy to Clipboard
curl -X "POST" "https://rest.nexmo.com/sms/json" \
  -d "from=AcmeInc" \
  -d "to=$TO_NUMBER" \
  -d "text=こんにちは世界" \
  -d "type=unicode" \
  -d "api_key=$NEXMO_API_KEY" \
  -d "api_secret=$NEXMO_API_SECRET"

View full source 

Run your code

Save this file to your machine and run it:

$ ./send-an-sms-with-unicode.sh

Prerequisites

Install dependencies

$ npm install nexmo
Initialize your dependencies

Create a file named send-unicode-sms.js and add the following code:

Copy to Clipboard
const nexmo = new Nexmo({
  apiKey: NEXMO_API_KEY,
  apiSecret: NEXMO_API_SECRET
})

View full source 

Write the code

Add the following to send-unicode-sms.js:

Copy to Clipboard
const from = 'Acme Inc'
const to = TO_NUMBER
const text = 'こんにちは世界'
const opts = {
  "type": "unicode"
}

nexmo.message.sendSms(from, to, text, opts, function(){})

View full source 

Run your code

Save this file to your machine and run it:

$ node send-unicode-sms.js

Prerequisites

Install dependencies

$ composer require nexmo
Initialize your dependencies

Create a file named send-unicode-sms.php and add the following code:

Copy to Clipboard
$basic  = new \Nexmo\Client\Credentials\Basic(NEXMO_API_KEY, NEXMO_API_SECRET);
$client = new \Nexmo\Client($basic);

View full source 

Write the code

Add the following to send-unicode-sms.php:

Copy to Clipboard
$message = $client->message()->send([
    'to' => TO_NUMBER,
    'from' => 'Acme Inc',
    'text' => 'こんにちは世界',
    'type' => 'unicode'
]);

View full source 

Run your code

Save this file to your machine and run it:

$ php -f send-unicode-sms.php

Prerequisites

Install dependencies

$ pip install nexmo
Initialize your dependencies

Create a file named send-an-sms-with-unicode.py and add the following code:

Copy to Clipboard
import nexmo

client = nexmo.Client(key=NEXMO_API_KEY, secret=NEXMO_API_SECRET)

View full source 

Write the code

Add the following to send-an-sms-with-unicode.py:

Copy to Clipboard
client.send_message({
    'from': 'Acme Inc',
    'to': TO_NUMBER,
    'text': 'こんにちは世界',
    'type': 'unicode',
})

View full source 

Run your code

Save this file to your machine and run it:

$ python3 send-an-sms-with-unicode.py

Prerequisites

Install dependencies

$ gem install nexmo
Initialize your dependencies

Create a file named send-unicode-sms.rb and add the following code:

Copy to Clipboard
require 'nexmo'

client = Nexmo::Client.new(
  api_key: NEXMO_API_KEY,
  api_secret: NEXMO_API_SECRET
)

View full source 

Write the code

Add the following to send-unicode-sms.rb:

Copy to Clipboard
client.sms.send(
  from: 'Acme Inc',
  to: TO_NUMBER,
  text: 'こんにちは世界',
  type: "unicode"
)

View full source 

Run your code

Save this file to your machine and run it:

$ ruby send-unicode-sms.rb

Try it out

When you run the example above, the text message will be sent to the mobile number specified with the unicode characters intact.

Note that Unicode messages can only contain 70 characters, rather than the usual 160. There's more information about this on the help page 

Further reading