firstred / postnl-api-php

PostNL API PHP bindings
https://postnl-php.readthedocs.io
MIT License
26 stars 37 forks source link

"Unable to generate label" sending from NL to DE #58

Closed linaori closed 2 years ago

linaori commented 2 years ago

I'm trying to figure out how to send a package from NL to DE, but I'm getting a NotFoundException('Unable to generate label'). I suspect that I'm not configuring the Shipment properly but I also can't really find out what I should be doing in the first place. The PostNL API seems to have no examples for anything foreign other than BE. If i understand the flow correctly PostNL just doesn't generate any labels? It does mention something about "combilabels", but I couldn't find anything in the code in regards to that.

https://developer.postnl.nl/browse-apis/send-and-track/products/#destination-EU

A snippet of the code I'm using:

$customer = Customer::create();
$customer->setCollectionLocation($transport->getCollectionLocation());
$customer->setCustomerCode($transport->getCustomerCode());
$customer->setCustomerNumber($transport->getCustomerNumber());
$customer->setAddress($this->createShipmentSenderAddress($senderBranchId));

$client  = new PostNL($customer, $transport->getApiKey(), $transport->isSandboxMode());
$barcode = $client->generateBarcode();

$shipment = Shipment::create();
$shipment->setAddresses([$receiverAddress]);
$shipment->setBarcode($barcode);
$shipment->setProductCodeDelivery($shipmentMethod->getProductCode());

// this call fails with product code 4944 and 4952
$labelResponse = $client->generateLabel($shipment, 'Zebra|Generic ZPL II 200 dpi');

The documentation does mention something for a partner barcode, but I can't find what that is supposed to be or how to pass it into the Shipment.

TomKriek commented 2 years ago

@linaori Your best bet is to use a debugger like XDebug and step debug through the part that actually returns the CIFException with the error message in it. The unable to generate label is a sort of catch-all exception. Difficult to say otherwise what's wrong, But if I had to make a wild guess it's the barcode.

linaori commented 2 years ago

I'm not actually getting a CIFException, which is why I was curious if there was anything I missed in the Shipment setup. Is there any way to verify if the barcode is compatible with the given product code? The PostNL API is rather poorly documented so I can't make heads or tails of what's supposed to happen :(

TomKriek commented 2 years ago

In the client there is also generateBarcodeByCountryCode() see if using that function with DE al ISO code helps.

TomKriek commented 2 years ago

https://github.com/firstred/postnl-api-php/blob/v1.3.x/src/Service/LabellingService.php#L152

Is where that exception gets thrown, it's basicly the Nothing happened exception also check if your Sandbox environment and Live environment in PostNL are equal with the same product codes, we have some that work on sandbox and some that don't work. Maybe contact your Account Manager to verify that.

BBrunekreeft commented 2 years ago

I think you'll have to contact your account manager at PostNL. We are in the process of sending packages from NL to DE using PostNL, and it needs some configuration on the side of PostNL.

linaori commented 2 years ago

Thanks, I feared as much. The PostNL API contact form is broken and won't let me submit a question, so that's going to be fun. I was hoping this would just work in sandbox mode but alas.

Thanks for the pointers!