Join us in San Francisco on the 29/30th of October for two days of developer workshops and technical talks

Send an MMS

In this code snippet you will see how to send an MMS using the Messages API.

IMPORTANT: Only US Short codes are currently supported for sending MMS.

Example

Ensure the following variables are set to your required values using any convenient method:

Key Description
FROM_NUMBER The phone number you are sending the MMS from. (US Short Code only)
TO_NUMBER The phone number you are sending the message to.
IMAGE_URL The URL of the media you want to send.

NOTE: Don't use a leading + or 00 when entering a phone number, start with the country code, for example 14155550105.

Prerequisites

Create an application
If you do not have an application you can create one. Make sure you also configure your webhooks.

Write the code

Add the following to send-mms.sh:

Copy to Clipboard
curl -X POST https://api.nexmo.com/v0.1/messages \
  -H 'Authorization: Bearer '$JWT\
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json' \
  -d $'{ 
   "from":{
        "type": "mms",    
        "number": "'$FROM_NUMBER'"
   },
   "to":{
        "type": "mms",
        "number": "'$TO_NUMBER'"
   },
   "message":{ 
      "content":{
          "type": "image",
          "image": {
              "url": "'$IMAGE_URL'"
          }
      }
   }
}'

View full source

Run your code

Save this file to your machine and run it:

bash send-mms.sh

Prerequisites

Create an application
If you do not have an application you can create one. Make sure you also configure your webhooks.
Install dependencies

npm install nexmo@beta

Write the code

Add the following to send-mms.js:

Copy to Clipboard
nexmo.channel.send(
  { "type": "mms", "number": "TO_NUMBER" },
  { "type": "mms", "number": "FROM_NUMBER" },
  {
    "content": {
      "type": "image",
       "image": { "url": "IMG_URL" }
    }
  },
  (err, data) => { console.log(data.message_uuid); }
);

View full source

Run your code

Save this file to your machine and run it:

node send-mms.js

Try it out

When you run the code an MMS message is sent to the destination number.