RIAengine
1 year ago

Mailgun webhook data object trying to convert to array

Posted 1 year ago by RIAengine

Not sure where to put this so chose the first topic ...

I have a webhook where mailgun sends successful deliveries, I can send it into the log successfully. However I need to dig into the object and retrieve some fields so I can send to the database. Having a lot of trouble figuring out how to work with this object ... Mailgun docs not helpful on this. Here is the code I'm using, unless you know of a better way, I'm planning to use the RecursiveIteratorIterator and the array iterator. Anyway, it needs an array to work with. Not sure how else I can get this as an array, while it already appears to be an array from the 'is_array' being TRUE. Very odd. Anyway, it's failing on "new RecursiveArrayIterator(json_encode($content, TRUE)),". BTW I also tried, at the top of the file, "$content = request()->__get('event-data');" which also sure looks like an array, but still could not figure out how to get anything out of it. Sorry this might be a little scatterbrained.

public function getdeliveries(Request $request)
{

    $content = (array)$request;

    if (is_array($content))
    {
        $jsonIterator = new RecursiveIteratorIterator(
            new RecursiveArrayIterator(json_encode($content, TRUE)),
            RecursiveIteratorIterator::SELF_FIRST);

        Log::debug($jsonIterator);
    }

    return response()->json(['status' => 'ok']);

}

Please sign in or create an account to participate in this conversation.