Objective
Adding a new line or carriage return in SMS using the Vonage REST API.
Applies To
- REST API
- SMS
Procedure
A newline character (\n or LF) should be represented in your HTTP request with 1 character in UTF8: %0A
CRLF (Carriage Return Line Feed) should be represented with 2 characters in UTF8: %0D%0A
The following code snippets demonstrate how to add newline characters to SMS messages.
PHP
<?php
$url = 'https://rest.nexmo.com/sms/json?' . http_build_query(
[
'api_key' => 'KEY',
'api_secret' => 'SECRET',
'to' => 'TO_NUMBER',
'from' => 'FROM_NUMBER',
'text' => "Here is a newline\nWow!"
]
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
echo $response;
Python
import urllib
import urllib2
params = {
'api_key': 'KEY',
'api_secret': 'SECRET',
'to': 'TO_NUMBER',
'from': 'FROM_NUMBER',
'text': 'Here is a newline:\nWow!'
}
url = 'https://rest.nexmo.com/sms/json?' + urllib.urlencode(params)
request = urllib2.Request(url)
request.add_header('Accept', 'application/json')
response = urllib2.urlopen(request)
print response.read()
Articles in this section
- Adding a New Line in SMS Using Vonage REST API
- What is the minimum/maximum of a Sender ID length?
- What are some best practices for sending social invites through SMS?
- How to Avoid Outbound SMS Rejection
- Message Delivery Failed Error 10 Invalid Message
- Error 8 Network Error
- Vonage SMS Delivery Error Codes and Descriptions
- DLR Error Code 99 General Error
- DLR Error Code 9 Illegal Number
- DLR Error Code 3 Absent Subscriber Permanent