-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make headers of last response available trough (base) client #57
Conversation
… is needed for retrieving the track and trace.
…ng label endpoint. This contains the track and trace code.
Hi there, sorry not to post to the needed thread, I'm new here on github. |
@Majklas Yes, that is possible. The code is somewhat like this: $shipmentRequest = new Model\ShipmentRequest();
$shipmentRequest->shipmentReference = $picklist->picklistid;
$shipmentRequest->orderItems = $orderItems;
$shipmentRequest->transport = $transportInstruction;
$shipmentRequest->shippingLabelId = $shippingLabelId;
$process = $client->createShipment($shipmentRequest); But the required data is quite complex, so there is no easy example to give. Have a look at the Bol API docs, and then use the matching models in this client to create the shipment. |
@sanderlissenburg Als het werkt, dan kan het voor nu. Maar het is natuurlijk wel beroerd om geen headers te kunnen krijgen van het request wat je al gedaan hebt. Het kan zomaar dat deze HEAD request ook meetelt met je rate-limits, of andere vervelende side effects. Nog een reden om een nieuwe (simpele) client te gaan maken. |
@casperbakker dat risico is wel groot bij bol. En extra vervelend als call 1 slaagde en 2 niet. Ik denk dat het dan slimmer is om de last response in memory (op een property) te cachen en dan via een 'lastResponse(): ?ResponseInterface' method op de client beschikbaar te maken. Kan daar de headers aan opvragen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, dit is een betere oplossing dan een HEAD
request. Voelt nog wel een beetje gek om de headers van een response aan de client te moeten vragen nadat de request al gedaan is, maar dit is wel de manier om het te doen zonder grote aanpassingen, dus lijkt me prima! 💪
Ok, thank you, finally got it according to the needs. Please let me know how should I send that info? Which method? |
@Majklas There are no different permission roles in the Bol API as far as I know. So the auth credentials you provided are probably wrong. That is what "Unauthorized request" means. Maybe easier to check the auth with a simple GET call, for example to get the open orders. Once the auth works with that endpoint, you can move over to this more complicated one. |
Yeah, creds are ok, I can get the needed order list and orders accordingly with them. So maybe wrong method? |
@Majklas I cannot help you further, sorry. You have to debug it yourself. We use this feature ourselves, the method in the client works. |
funny story though.. I just wanted to post here. We had a server where all of apis are working, but seems admin installed the last version of your module which was capable on that server according to php version. Seems like it was missing in Client.php that createShipment method. Thank you, we moved to new fresh php and updated your module, now all is working. |
resolves PIC-925
Voor het verkrijgen van de track and trace code van een verzend label moet je een header van het get shipment label endpoint uitlezen.
De client is zo gebouwd dat alleen de response body decoded en returned kan worden.
Om het verkrijgen van de headers toch mogelijk te maken heb ik twee opties overwogen.Zie comments hier onder. Uiteindelijk gekozen voor een oplossing waarbij er via de client de headers van de laatste response worden beschikbaar gesteld.
De eerste optie, die in deze pull request terug te zien is checkt op de$method === 'HEAD'
. Zo ja/true, dan worden ALLEEN de headers returned. In het geval van het get shipment label endpoint is het namelijk mogelijk om met de methodHEAD
alleen de headers terug te krijgen. Wat handig is want je zal twee calls moeten doen bij het gebruik van deze client. Één voor de body, en één voor headers. Wil je dat in één call, dan zouden we de client grondiger moeten aanpassen. Zodat deze bijvoorbeeld de headers van de laatste call ergens beschikbaar maakt, of meer dan alleen de decoded body returned.Een tweede optie die ik heb overwogen, maar uiteindelijk niet heb gekozen is het uitbreiden van dedecodeResponse()
method. Waarbij ik dan een nieuweresponseType
zou introduceer genaamdheaders
.Maar dit voelde weer niet goed omdat dedecodeResponse
method naam impliceert dat het om het decoden van de body gaat.Twijfels:
I
k hebgetShippingLabelHeaders
toegevoegd aan de Client. Deze Client is echter auto generated, dus ik weet niet of het slim is om deze hier toe te voegen. Je zou ook in de applicatie (in ons geval Picqer) gewoon directrequest()
kunnen aanroepen.