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
- SMS Best Practices During COVID-19 for Users Sending Traffic to North America
- Troubleshooting SMS Delivery
- Global Sender ID Portal - FAQs
- Global Sender ID Registration Guide
- Recommended Sender ID option for A2P Alert and Transactional Messages to US Virtual Numbers
- Partner Quota Violation Error
- SMS Delivery Failure Error 95 - Unknown
- DLR Statuses
- Is USSD supported via SMS for the SMS API?
- What countries require STOP management for recipient opt-out?