-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall.php
More file actions
51 lines (43 loc) · 1.46 KB
/
call.php
File metadata and controls
51 lines (43 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
// n8n Webhook Integration via PHP
// Specify your n8n webhook URL (update with your actual n8n instance URL and webhook path)
$n8nWebhookUrl = 'https://your-n8n-instance.com/webhook/myWebhook';
// Prepare the data payload that your n8n workflow expects.
// This could be an event, order details, or any other data you want to process in n8n.
$payload = array(
'event' => 'order_created',
'order' => array(
'id' => 12345,
'total' => 99.99,
'customer' => array(
'name' => 'Jane Doe',
'email' => 'jane@example.com'
)
),
'timestamp' => date('c') // ISO 8601 formatted timestamp
);
// Convert the PHP array to a JSON string
$jsonData = json_encode($payload);
// Initialize a cURL session to send the POST request to n8n
$ch = curl_init();
// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $n8nWebhookUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($jsonData)
));
// Execute the cURL request and capture the response
$response = curl_exec($ch);
// Check if any cURL error occurred
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
} else {
// Display the response from the n8n webhook
echo 'Response from n8n: ' . $response;
}
// Close the cURL session
curl_close($ch);
?>