Closed Sylvesterx1 closed 1 year ago
Hi,
Strange issue, I don't know what could be wrong. Maybe try curl https://sandbox-api-shipx-pl.easypack24.net
on your machine and check the result. Maybe your dns can't recognize sandbox host for some reason?
can you please confirm this library working with create shipping for both courier and paczkomaty ?
I'm put this code in codeigniter 3 controller;
<?php
defined('BASEPATH') or exit('No direct script access allowed');
require FCPATH . 'vendor/autoload.php';
use Imper86\PhpInpostApi\Enum\ServiceType;
use Imper86\PhpInpostApi\InpostApi;
class Inpost_controller extends Admin_Core_Controller
{
public function __construct()
{
parent::__construct();
}
/**
* Create shippment Inpost Post
*/
public function inpost_shippment_post()
{
set_time_limit(0);
$token = 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJkVzROZW9TeXk0OHpCOHg4emdZX2t5dFNiWHY3blZ0eFVGVFpzWV9TUFA4In0.eyJleHAiOjE5ODc3OTc4OTEsImlhdCI6MTY3MjQzNzg5MSwianRpIjoiM2Q4NmIxZTAtYzk2ZC00ZDczLWJlYmItOTA1MzI0NmUwMjc5IiwiaXNzIjoiaHR0cHM6Ly9zYW5kYm94LWxvZ2luLmlucG9zdC5wbC9hdXRoL3JlYWxtcy9leHRlcm5hbCIsInN1YiI6ImY6N2ZiZjQxYmEtYTEzZC00MGQzLTk1ZjYtOThhMmIxYmFlNjdiOnhyb2IyU2lVbmlrUGM4b2F5U1IwWVpPVEh3dXAydk9ibmd6WTBacGZ2RDAiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJzaGlweCIsInNlc3Npb25fc3RhdGUiOiI0YmYyZjljMC00MWZlLTQxNmMtODI4OC03ZTAwYWUxOTIwNWIiLCJzY29wZSI6Im9wZW5pZCBhcGk6YXBpcG9pbnRzIGFwaTpzaGlweCIsInNpZCI6IjRiZjJmOWMwLTQxZmUtNDE2Yy04Mjg4LTdlMDBhZTE5MjA1YiIsImFsbG93ZWRfcmVmZXJyZXJzIjoiIiwidXVpZCI6IjU3OWFlMWQwLTZlOTktNDFlZC1hMzUwLTY3ZmUzMjM0ODdkNSIsImVtYWlsIjoiYnJhbmR3cm94MUBnbWFpbC5jb20ifQ.KRWDP0NIUOTUe096Fht7q2DQltJexOpsdpw93WggbIzH_SGeT3E8jPBmX2b0cjS-Gr4QGLXk1fNEDzk9dbCPBAappnR6MfQzLtwST-rXl6YqaYQ4nkpbsvZpUBIBZXuG-0SimATkws8gYcc00sCaK6gzZAUVefjAvp4IrdvNMrIMT9U8CuBJ2T7kAB9XCtdBkJzJ8mb4qL5KK0UCN1FnwdQhmbOtc2uewPek_GaWXDyzYwa9IRd05bLoUu54zvUNETXb98n7sjuvxUPI9pZYDc6bcPyD1zWLSeJ27LNkaEfwecNeSMla7FASwHoUP_BLSC9FBDXE51I2SiZX_9-dOw';
$organizationId = '2773';
$isSandbox = true;
$api = new InpostApi($token, $isSandbox);
$response = $api->organizations()->shipments()->post($organizationId, [
'receiver' => [
'name' => 'Marek Kowalczyk',
'company_name' => 'Company name',
'first_name' => 'Jan',
'last_name' => 'Kowalski',
'email' => 'test@inpost.pl',
'phone' => '888888888',
'address' => [
'street' => 'Malborska',
'building_number' => '130',
'city' => 'Kraków',
'post_code' => '30-624',
'country_code' => 'PL',
],
],
'sender' => [
'name' => 'Marek Kowalczyk',
'company_name' => 'Company name',
'first_name' => 'Jan',
'last_name' => 'Kowalski',
'email' => 'test@inpost.pl',
'phone' => '888888888',
],
'parcels' => [
['template' => 'small'],
],
'insurance' => [
'amount' => 25,
'currency' => 'PLN',
],
'cod' => [
'amount' => 12.50,
'currency' => 'PLN',
],
'custom_attributes' => [
'sending_method' => 'parcel_locker',
'target_point' => 'KRA012',
],
'service' => ServiceType::INPOST_LOCKER_STANDARD,
'reference' => 'Test',
'external_customer_id' => '8877xxx',
]);
$shipmentData = json_decode($response->getBody()->__toString(), true);
if ($shipmentData['status'] !== 'confirmed') {
$response = $api->shipments()->get($shipmentData['id']);
$shipmentData = json_decode($response->getBody()->__toString(), true);
die(var_dump($shipmentData));
}
$labelResponse = $api->shipments()->label()->get($shipmentData['id'], [
'format' => 'Pdf',
'type' => 'A6',
]);
file_put_contents('/tmp/inpost_label.pdf', $labelResponse->getBody()->__toString());
}
}
When I post I get output:
array(26) { ["href"]=> string(65) "https://sandbox-api-shipx-pl.easypack24.net/v1/shipments/12039033" ["id"]=> int(12039033) ["status"]=> string(7) "created" ["tracking_number"]=> NULL ["service"]=> string(22) "inpost_locker_standard" ["reference"]=> string(4) "Test" ["is_return"]=> bool(false) ["application_id"]=> int(3268) ["created_by_id"]=> NULL ["external_customer_id"]=> string(7) "8877xxx" ["sending_method"]=> string(13) "parcel_locker" ["end_of_week_collection"]=> bool(false) ["comments"]=> NULL ["mpk"]=> NULL ["additional_services"]=> array(0) { } ["custom_attributes"]=> array(2) { ["target_point"]=> string(6) "KRA012" ["sending_method"]=> string(13) "parcel_locker" } ["cod"]=> array(2) { ["amount"]=> float(12.5) ["currency"]=> string(3) "PLN" } ["insurance"]=> array(2) { ["amount"]=> float(25) ["currency"]=> string(3) "PLN" } ["sender"]=> array(8) { ["id"]=> int(24081363) ["name"]=> string(15) "Marek Kowalczyk" ["company_name"]=> string(12) "Company name" ["first_name"]=> string(3) "Jan" ["last_name"]=> string(8) "Kowalski" ["email"]=> string(14) "test@inpost.pl" ["phone"]=> string(9) "881151121" ["address"]=> NULL } ["receiver"]=> array(8) { ["id"]=> int(24081362) ["name"]=> string(15) "Marek Kowalczyk" ["company_name"]=> string(12) "Company name" ["first_name"]=> string(3) "Jan" ["last_name"]=> string(8) "Kowalski" ["email"]=> string(14) "test@inpost.pl" ["phone"]=> string(9) "881151121" ["address"]=> array(8) { ["id"]=> int(22874656) ["street"]=> string(9) "Malborska" ["building_number"]=> string(3) "130" ["line1"]=> NULL ["line2"]=> NULL ["city"]=> string(7) "Kraków" ["post_code"]=> string(6) "30-624" ["country_code"]=> string(2) "PL" } } ["selected_offer"]=> NULL ["offers"]=> array(0) { } ["transactions"]=> array(0) { } ["parcels"]=> array(1) { [0]=> array(7) { ["id"]=> int(12505889) ["identify_number"]=> NULL ["tracking_number"]=> NULL ["is_non_standard"]=> bool(false) ["template"]=> string(5) "small" ["dimensions"]=> array(4) { ["length"]=> float(380) ["width"]=> float(640) ["height"]=> float(80) ["unit"]=> string(2) "mm" } ["weight"]=> array(2) { ["amount"]=> float(25) ["unit"]=> string(2) "kg" } } } ["created_at"]=> string(29) "2023-01-07T09:07:44.576+01:00" ["updated_at"]=> string(29) "2023-01-07T09:07:44.576+01:00" }
But the shipment does not get created in the sandbox api manager paczkomaty.
It is possible check this code?
can you please confirm this library working with create shipping for both courier and paczkomaty ?
Yup, working in production without any issue.
The response you pasted (the one with id 12039033
) means that the shipment was indeed created. AFAIR inpost api is asynchronous, so you must wait a moment until the label and tracking number are available to download. Please read Inpost shipx documentation.
The response you pasted (the one with id 12039033) means that the shipment was indeed created
I checked in: https://sandbox-manager.paczkomaty.pl/shipments/list
and I see only one package which I created manually: https://prnt.sc/-mbzgCH4-pEk
I not see any others packages, I try created about 30 shippments with this response.
Issue resolved.
We post some incorrect data. After modified some details in post structure working.
Hello, I try integrate this library with CI3. But everytime in Sandbox I get request timeout.
This is controller:
I have currently access API only to Paczkomaty Sandbox.