{
"field": "messages",
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "16505551111",
"phone_number_id": "123456123"
},
"contacts": [
{
"profile": {
"name": "test user name"
},
"wa_id": "16315551181"
}
],
"messages": [
{
"from": "16315551181",
"id": "ABGGFlA5Fpa",
"timestamp": "1504902988",
"type": "text",
"text": {
"body": "this is a text message"
}
}
]
}
}
Asked
Active
Viewed 209 times
0

Donkarnash
- 12,433
- 5
- 26
- 37
-
Are you asking how to parse json? `$obj = json_decode($json);` `$obj->value->metadata->phone_number_id` – Michael Mano Jun 07 '22 at 01:27
1 Answers
1
The easiest way is to save the response to a variable and get the data from the array as follows
$message = $responce['value']['message'];
$phone_number = $responce['value']['metadata']['phone_number_id'];
$contact = $responce['value']['contacts'];
You can also decode the response first and then you can easily do the following
$res = json_decode($responce);
$message = $res->value->message;
$phone_number= $res->value->metadata->phone_number_id;
$contact = $res->value->contacts;
But if you want to convert the JSON you have to a Laravel object I recommend checking out the following answer.

dz0nika
- 882
- 1
- 5
- 16