Hi @correa.
We don’t have a precise example for that, but the idea is that you capture the webhook data, build an array with the information needed, then send the request to Sendcloud’s API.
If you’re using basic PHP, it would be something like this:
<?php
$data = json_decode(file_get_contents('php://input'), true);
$name = ($data["content"]["billingAddressName"]);
// build api data
$api_user = 'api_user';
$api_key = 'api_key';
$param = array(
'parcel' => array(
'name' => $name,
'description' => '',
'sender' => array(
'name' => '',
'address1' => '',
'address2' => '',
'city' => '',
'state' => '',
'postal_code' => '',
'country' => '',
'phone' => '',
'email' => '',
'company' => '',
'tax_id' => '',
'vat_id' => '',
),
'weight' => '0.5',
)
);
// send post request to sendcloud
$url = 'https://panel.sendcloud.sc/api/v2/parcels';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Basic ' . base64_encode($api_user . ':' . $api_key)
));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
Please note that this is untested code created only for your reference. In this code I only get the name as an example, you would need to get all relevant data required.
To test this, you can create a fake request in Postman and simulate a webhook call so that you can check the response more easily than creating a test order each time.
Here I am using var_dump($param);
to check the data received over POST in the PHP file:
I hope this sheds some light into how you can get that working.
Thanks!