Send an MMS with Basic Authentication

In this building block you will see how to send an MMS using the Messages API.

IMPORTANT: Only US Short codes are currently supported.

Example

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

Key Description
US_SHORT_CODE The US Short Code you are sending the message from.
TO_NUMBER The phone number you are sending the message to.
IMG_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 447700900000.

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-basic-auth.sh:

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

View full source

Run your code

Save this file to your machine and run it:

$ bash send-mms-basic-auth.sh

Try it out

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