Avatar of tjyoung
tjyoung

asked on 

Trying to retrieve values from webhook using Nylas API and Laravel

Hi, I'm using Nylas for mail syncing and have a webhook setup in Nylas and receiving it in my Laravel application.

From Nylas docs:
"The body of the POST request is encoded as a UTF-8 JSON object with the following attributes:
Attribute        Type          Description
deltas            array          An array consisting of a single delta object."

So it seems to be a json object that contains an array??

The incoming webhook looks like this:
{
"deltas": [{
"date": 1577127539,
 "object": "message", 
"type": "message.created", 
"object_data": {
"namespace_id": "93d6z2qmxm050zh2znnpxxxxx", 
"account_id": "93d6z2qmxm050zh2znnpxxxxx",
 "object": "message", 
"attributes": {
"thread_id": "6ejmdhd2p0iyhscfac21yyyyy", 
"received_date": 1577127517
}, 
"id": "ioe47mlrjm592gbrc01bbbbb", 
"metadata": null
}
}]
}

Open in new window


So my question is: how do I receive that in Laravel and get at the values?

Tried below but fails unsurprisingly (I think its because I'm receiving an object that contains an array?)

$results                   = $request->all();
$json                         = json_decode($results);
   
$Type                        = $json['deltas'][0]['type'];
$Thread                  = $json['deltas'][0]['object_data']['thread_id'];
$AccountId                  = $json['deltas'][0]['object_data']['account_id'];
$MessageDate            = $json['deltas'][0]['date'];
$MessageId                  = $json['deltas'][0]['object_data']['id'];

Thanks for any help in advance.
LaravelPHPJSON

Avatar of undefined
Last Comment
tjyoung

8/22/2022 - Mon