Link do dokumentacji
Token należy wygenerować w zakładce Dane Konta
Pobranie i wyświetlenie możliwych błędów, dostępnych kurierów oraz usług dodatkowych:
$token = "1f...32";
$urls = [
"errors" => "https://www.wysylajtaniej.pl/api/v1/service/errors",
"couriers" => "https://www.wysylajtaniej.pl/api/v1/service/couriers",
"services" => "https://www.wysylajtaniej.pl/api/v1/service/services",
];
function showData($name, $url, $token)
{
echo "=====================================\n";
echo "".$name."\n";
echo "=====================================\n";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
"X-AUTH-TOKEN: $token",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
var_dump(json_decode($response, true));
}
}
foreach ($urls as $name => $url) {
showData($name, $url, $token);
}
Wyszukiwanie punktów paczkomatów i punktów nadania/odbioru paczki:
$token = "1f...32";
$query = "Warszawa, Grzybowska 110";
$urlize = urlencode($query);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_URL => "https://www.wysylajtaniej.pl/api/v1/parcel/search/?query=$urlize",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded",
"X-AUTH-TOKEN: $token",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
var_dump(json_decode($response, true));
}
Walidacja przesyłki lub dodanie paczki do koszyka:
$token = "1f...32";
/**
* Paczka niestandardowa InPost z usługą odbioru paczki przez kuriera z domu i opisem paczki
*/
$data1 = [
'Order' => [
'courier' => 'InPost',
'sender' => [
'name' => 'Imię',
'surname' => 'Nazwisko',
'street' => 'Opolska',
'email' => 'example@example.com',
'phoneNumber' => '+48123123123',
'city' => 'Gdańsk',
'postCode' => '80-396',
'building' => '1',
'local' => '12',
],
'receiver' => [
'name' => 'Imię',
'surname' => 'Nazwisko',
'street' => 'Opolska',
'email' => 'example@example.com',
'phoneNumber' => '+48123123123',
'city' => 'Gdańsk',
'postCode' => '80-396',
'building' => '1',
'local' => '12',
],
'services' => [
[
'slug' => 'NST',
], [
'slug' => 'PICK_UP',
'values' => [
'DATE_RANGE' => '2018-12-24 11:00 - 16:15',
],
], [
'slug' => 'DESCRIPTION',
'values' => [
'DESCRIPTION' => 'OPIS PACZKI',
],
],
],
'packages' => [
[
'width' => 11,
'height' => 1,
'length' => 3,
'weight' => 1,
'shape' => [
'slug' => 'WHEELS',
],
],
],
],
];
/**
* Nadanie paczki przez przewoźnika 'Orlen Paczka'
*/
$data2 = [
'Order' => [
'courier' => 'PWR',
'parcel' => [
'senderPoint' => 'BD-106161-40-28',
'receiverPoint' => 'BD-112680-11-08',
],
'sender' => [
'name' => 'Imię',
'surname' => 'Nazwisko',
'street' => 'Opolska',
'email' => 'example@example.com',
'phoneNumber' => '+48123123123',
'city' => 'Gdańsk',
'postCode' => '80-396',
'building' => '1',
'local' => '12',
],
'receiver' => [
'name' => 'Imię',
'surname' => 'Nazwisko',
'street' => 'Opolska',
'email' => 'example@example.com',
'phoneNumber' => '+48123123123',
'city' => 'Gdańsk',
'postCode' => '80-396',
'building' => '1',
'local' => '12',
],
'services' => [
[
'slug' => 'DESCRIPTION',
'values' => [
'DESCRIPTION' => 'Opis paczki',
],
],
],
'packages' => [
[
'width' => 12,
'height' => 2,
'length' => 4,
'weight' => 1,
'shape' => [
'slug' => 'BOX',
],
],
],
],
];
$data_json = json_encode($data1);
$curl = curl_init();
/**
* Walidacja przesyłki
*/
$urlValidate = "https://www.wysylajtaniej.pl/api/v1/order/validate";
/**
* Dodanie przesyłki do koszyka
*/
$urlAdd = "https://www.wysylajtaniej.pl/api/v1/order/add";
curl_setopt_array($curl, array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_URL => $urlValidate,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data_json,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"X-AUTH-TOKEN: $token",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
var_dump(json_decode($response, true));
}
Walidacja lub dodanie paczki do koszyka z usługą uzupełnienia danych przez odbiorcę:
$token = "1f...32";
$data = [
'Order' => [
'courier' => 'InPost',
'sender' => [
'name' => 'Imię',
'surname' => 'Nazwisko',
'street' => 'Opolska',
'email' => 'example@example.com',
'phoneNumber' => '+48123123123',
'city' => 'Gdańsk',
'postCode' => '80-396',
'building' => '1',
'local' => '12',
],
'receiver' => [
'email' => 'example@example.com',
'phoneNumber' => '+48123123123',
"noData" => true,
],
'services' => [
[
'slug' => 'NST',
], [
'slug' => 'PICK_UP',
'values' => [
'DATE_RANGE' => '2018-12-24 11:00 - 16:15',
],
], [
'slug' => 'DESCRIPTION',
'values' => [
'DESCRIPTION' => 'OPIS PACZKI',
],
],
],
'packages' => [
[
'width' => 11,
'height' => 1,
'length' => 3,
'weight' => 1,
'shape' => [
'slug' => 'BOX',
],
],
],
],
];
$data_json = json_encode($data);
$curl = curl_init();
/**
* Walidacja przesyłki
*/
$urlValidate = "https://www.wysylajtaniej.pl/api/v1/order/validate";
/**
* Dodanie przesyłki do koszyka
*/
$urlAdd = "https://www.wysylajtaniej.pl/api/v1/order/add";
curl_setopt_array($curl, array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_URL => $urlValidate,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data_json,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"X-AUTH-TOKEN: $token",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
var_dump(json_decode($response, true));
}
Przykład dodwania paczki niestandardowej Inpost kurier do koszyka z usługą zamów kuriera
$token = "1f...32";
/**
* Paczka niestandardowa InPost z usługą odbioru paczki przez kuriera z domu i opisem paczki
*/
$data1 = [
'Order' => [
'courier' => 'InPost',
'sender' => [
'name' => 'Imię',
'surname' => 'Nazwisko',
'street' => 'Opolska',
'email' => 'example@example.com',
'phoneNumber' => '+48123123123',
'city' => 'Gdańsk',
'postCode' => '80-396',
'building' => '1',
'local' => '12',
],
'receiver' => [
'name' => 'Imię',
'surname' => 'Nazwisko',
'street' => 'Opolska',
'email' => 'example@example.com',
'phoneNumber' => '+48123123123',
'city' => 'Gdańsk',
'postCode' => '80-396',
'building' => '1',
'local' => '12',
],
'services' => [
[
'slug' => 'NST',
], [
'slug' => 'PICK_UP',
'values' => [
'DATE_RANGE' => '2019-12-24 11:00 - 16:15',
],
], [
'slug' => 'DESCRIPTION',
'values' => [
'DESCRIPTION' => 'OPIS PACZKI',
],
],
],
'packages' => [
[
'width' => 11,
'height' => 1,
'length' => 3,
'weight' => 1,
'shape' => [
'slug' => 'BOX',
],
],
],
],
];
$data_json = json_encode($data1);
$curl = curl_init();
/**
* Walidacja przesyłki
*/
//$urlValidate = "https://www.wysylajtaniej.pl/api/v1/order/validate";
/**
* Dodanie przesyłki do koszyka
*/
$urlAdd = "https://www.wysylajtaniej.pl/api/v1/order/add";
curl_setopt_array($curl, array(
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_URL => $urlAdd,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data_json,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"X-AUTH-TOKEN: $token",
"cache-control: no-cache"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
var_dump(json_decode($response, true));
}