John Davidson

php - how to get the data from a webhook?

0 comments
Message:


I am using a webhook from Laposta, it will be activated when a user unsubscribed from a newsletter.


$sJsonData = @file_get_contents('php://input');

mail('[email protected]', 'webhook json',$sJsonData); // Email to myself to see what's within the webhook

// Decode JSON data to PHP associative array
$arr = json_decode($sJsonData, true);

// Access values from the associative array
$event1 = $arr["event"];
$event2 = $arr["data"]["event"];
$event3 = $arr["data"]["data"]["event"];

mail('[email protected]', 'webhook', 'event1 = ' . $event1 . ' and event2 = ' . $event2 . ' and event3 = ' . $event3); // Email to myself to see what's the value of the variable $event1(2,3)

I get in the first email this:


{
"data": [
{
"type": "member",
"event": "deactivated",
"data": {
"member_id": "***",
"list_id": "***",
"email": "[email protected]",
"state": "unsubscribed",
"signup_date": "2020-11-18 15:50:34",
"modified": "2020-11-23 16:56:25",
"confirm_date": null,
"ip": "***",
"source_url": "",
"custom_fields": {
"spelersnaam": "***"
}
},
"info": {
"source": "external",
"action": "unsubscribed",
"date_event": "2020-11-23 17:05:15"
}
}
],
"date_requested": "2020-11-23 17:05:20"
}

But in my second mail, all the 3 variables are empty.


What am I doing wrong?


I want the data email, state and date_event in 3 variables so I can make a MySQL request to change this record in my database.


Kind regards,


Arie



My Answer:
@example.com', 'Unsubscribe Notification', $sJsonData);

Rate this post

3 of 5 based on 5124 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us