skip to Main Content

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


  1. Try $request['_container']['errorcode']

    Login or Signup to reply.
  2. According to this source code you should be able to do $request->messageid or $request['messageid']

    Login or Signup to reply.
  3. 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 does return $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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search