Getting results from an API

Can you post the output you’re getting from the var_dump when you run the script please?

This is the output, it should be showing two separate messages although it’s showing one message twice but I’m not worried about that at the moment

[quote]
object(MessageBird\Objects\BaseList)#24 (5) { [“offset”]=> int(0) [“count”]=> int(2) [“totalCount”]=> int(2) [“links”]=> object(stdClass)#15 (4) { [“first”]=> string(47) “https://rest.messagebird.com/messages/?offset=0” [“previous”]=> NULL [“next”]=> NULL [“last”]=> string(47) “https://rest.messagebird.com/messages/?offset=0” } [“items”]=> array(2) { [0]=> object(MessageBird\Objects\Message)#7 (15) { [“id”:protected]=> string(32) “49f518203543802e8b46023a68836835” [“href”:protected]=> string(70) “https://rest.messagebird.com/messages/49f518203543802e8b46023a68836835” [“direction”]=> string(2) “mt” [“type”]=> string(3) “sms” [“originator”]=> string(9) “Sender” [“body”]=> string(65) “Sign up now to get £10 off of your first order” [“reference”]=> NULL [“validity”]=> NULL [“gateway”]=> int(10) [“typeDetails”]=> object(stdClass)#21 (0) { } [“datacoding”]=> string(5) “plain” [“mclass”]=> int(1) [“scheduledDatetime”]=> NULL [“createdDatetime”:protected]=> string(25) “2014-10-10T16:01:44+00:00” [“recipients”]=> object(stdClass)#22 (5) { [“totalCount”]=> int(1) [“totalSentCount”]=> int(1) [“totalDeliveredCount”]=> int(0) [“totalDeliveryFailedCount”]=> int(1) [“items”]=> array(1) { [0]=> object(MessageBird\Objects\Recipient)#19 (3) { [“recipient”]=> int(447551159632) [“status”]=> string(15) “delivery_failed” [“statusDatetime”]=> string(25) “2014-10-10T16:01:45+00:00” } } } } [1]=> object(MessageBird\Objects\Message)#7 (15) { [“id”:protected]=> string(32) “49f518203543802e8b46023a68836835” [“href”:protected]=> string(70) “https://rest.messagebird.com/messages/49f518203543802e8b46023a68836835” [“direction”]=> string(2) “mt” [“type”]=> string(3) “sms” [“originator”]=> string(9) “Sender” [“body”]=> string(65) “Sign up now to get £10 off of your first order” [“reference”]=> NULL [“validity”]=> NULL [“gateway”]=> int(10) [“typeDetails”]=> object(stdClass)#21 (0) { } [“datacoding”]=> string(5) “plain” [“mclass”]=> int(1) [“scheduledDatetime”]=> NULL [“createdDatetime”:protected]=> string(25) “2014-10-10T16:01:44+00:00” [“recipients”]=> object(stdClass)#22 (5) { [“totalCount”]=> int(1) [“totalSentCount”]=> int(1) [“totalDeliveredCount”]=> int(0) [“totalDeliveryFailedCount”]=> int(1) [“items”]=> array(1) { [0]=> object(MessageBird\Objects\Recipient)#19 (3) { [“recipient”]=> int(447551159632) [“status”]=> string(15) “delivery_failed” [“statusDatetime”]=> string(25) “2014-10-10T16:01:45+00:00” } } } } } }[/quote]
Thank you for helping me with this.

Oops, looks like it’s a typo on my part. Within the foreach loop it should be:

echo $message->body;

with a lowercase m.

Thank you so much that works perfectly now. I’ve also added to it so now I’ve got:

<?php if ($MessageList->count > 0) { foreach ($MessageList->items as $message) { $date = new DateTime($message->recipients->items[0]->statusDatetime); echo "<b>Date sent:</b> ".$date->format( 'd/m/Y @ g:ia' )."&nbsp;&nbsp;"; echo "<b>Sent:</b> ".$message->recipients->totalSentCount."&nbsp;&nbsp;"; echo "<b>Delivered:</b> ".$message->recipients->totalDeliveredCount."&nbsp;&nbsp;"; echo "<b>Undelivered:</b> ".$message->recipients->totalDeliveryFailedCount."<br>"; } } ?>
to get everything I need. Thank you so much for helping me with this.