I want to access the ‘messageid
‘ and ‘errorcode
‘ from the object response returned from Postmark email API. How do I access these two nested data points. I tried $request->_container['errorcode']
and returns NULL
object(PostmarkModelsDynamicResponseModel)#329 (2) {
["_container":"PostmarkModelsCaseInsensitiveArray":private]=> array(5) {
["errorcode"]=> int(0)
["message"]=> string(2) "OK"
["messageid"]=> string(36) "23c5b9a4-3da7-45f1-acbe-c935390e7911"
["submittedat"]=> string(28) "2024-04-09T13:36:41.0585492Z"
["to"]=> string(25) "[email protected]"
}
["_pointer":"PostmarkModelsCaseInsensitiveArray":private]=> int(0)
}
3
Answers
Try
$request['_container']['errorcode']
According to this source code you should be able to do
$request->messageid
or$request['messageid']
While I know nothing about these, I searched for https://kagi.com/search?q=DynamicResponseModel the second result is https://github.com/ActiveCampaign/postmark-php/blob/main/src/Postmark/Models/DynamicResponseModel.php which says
class DynamicResponseModel extends CaseInsensitiveArray
clicking CaseInsensitiveArray leads to https://github.com/ActiveCampaign/postmark-php/blob/main/src/Postmark/Models/CaseInsensitiveArray.php#L17
where
offsetGet
doesreturn $this->_container[$offset] ?? null;
and so
$response['errorcode']
is what you need.
Also the original class
__get
wraps this so$response->errorcode
should also work.