2

I want to send MMS using Twilio REST API. The message was sent successfully However, I am not able to get the unique MessageSid of the sent message.

I have already tried with $result->sid and $result->messageSid.

Current Code

$result= $client->account->messages->create(
    $to, array('from' => $from,
               'body' => $message,
               'mediaUrl' => $mediaurl
              ));               

if (isset($result->messageSid))
    return $result->messageSid;
else
    return "";

Is there anything i am doing wrong ?

Punit Gajjar
  • 4,937
  • 7
  • 35
  • 70
arun kumar
  • 703
  • 2
  • 13
  • 33

1 Answers1

1

Twilio developer evangelist here.

If you check the output for the first code sample on the documentation page for sending messages with Twilio then you will see that the returned JSON should have a sid property. Like this:

{
  "sid": "MMc781610ec0b3400c9e0cab8e757da937",
  "date_created": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_updated": "Mon, 19 Oct 2015 07:07:03 +0000",
  "date_sent": null,
  "account_sid": "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "to": "+15558675309",
  "from": "+15017250604",
  "body": "This is the ship that made the Kessel Run in fourteen parsecs?",
  "status": "queued",
  "num_segments": "1",
  "num_media": "1",
  "direction": "outbound-api",
  "api_version": "2010-04-01",
  "price": null,
  "price_unit": "USD",
  "error_code": null,
  "error_message": null,
  "uri": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937.json",
  "subresource_uris": {
    "media": "/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages/MMc781610ec0b3400c9e0cab8e757da937/Media.json"
  }
}

I just used similar code to you (I didn't send a media URL) and could echo $result->sid.

$result = $client->account->messages->create(
    'MY_NUMBER',
    array(
        'from' => 'MY_TWILIO_NUMBER',
        'body' => "Hey Jenny! Good luck on the bar exam!"
    )
);

echo $result->sid;

Let me know if that helps.

philnash
  • 70,667
  • 10
  • 60
  • 88