How do I add a new line to a message in the API?

You can include new lines in SMS messages sent via the API. The Mobile Message API supports newline characters, and they will display correctly on the recipient’s phone.

In most cases, you’ll be building your message in a programming language and then sending it to the API as JSON. For example, in PHP you can include a new line using \n when creating your message text. When that message is encoded as JSON, the JSON encoder automatically escapes the newline for you. In the actual JSON sent to the API, this will appear as \\n, and it will be handled correctly.

If you are sending raw JSON directly to the API, you need to escape the newline yourself. In raw JSON, a new line must be written as \\n, not \n. Using an unescaped newline in raw JSON can cause the request to fail or the message to be formatted incorrectly.

In summary, use \n when building the message in code and let your JSON library do the work. Use \\n only when you are manually writing the JSON payload. In both cases, the SMS will be delivered with the line breaks displayed as expected.