Open cgsmith opened 1 year ago
@bohdan-vorona can you take the lead on this one?
The original way this functionality worked was like this:
Here is what will be needed for integrating with Amazon SP API:
I copied the AmazonMWS Class to AmazonSPAPI (feel free to delete this and start over)
This codebase is useful and can be added in jlevers/selling-partner-api
[ ] Replace Amazon MWS with Amazon SP API
[ ] (optional) Create CRUD for Customer Meta data
[ ] Integrate with label service to print Amazon's suggested label
[ ] Integrate with label service with the user selecting Amazon carrier and service (this one can be done later)
@cgsmith ok
@cgsmith I'm asking just in case.
1)
You started adding and using classes from ShippingV1
and ShippingV2
but, as I understand, we have to fully switch to ShippingV2
?
Shipping API v2
has a different workflow - https://developer-docs.amazon.com/amazon-shipping/docs/amazon-shipping-api-v2-use-case-guide#workflow-for-creating-a-shipment
So, if I'm correct, as the result, we must have a new class which uses this Shipping API v2
with the corresponding workflow presented by Amazon? And, https://github.com/jlevers/selling-partner-api/blob/main/docs/Api/ShippingV2Api.md it's just a wrapper for Amazon's workflow.
2)
I saw you extended the plugins from AmazonSPAPI
. Am I right that all Amazon* carriers must use this new V2 functionality?
3)
In the test data I have only one order with "Shipping=Amazon FedEx" but without any needed data (it's empty). I can try to change existing test data but maybe, if it's possible, you can send real data related to Amazon shipping? With items, packages, etc.
Yes all amazon carriers and services will use the SP API functionality. I think we can use the directPurchase wrapper as I think that just selects the best rate and provides a label.
We can add rate request in later.
I'll get some production data today and post here.
Yes all amazon carriers and services will use the SP API functionality. I think we can use the directPurchase wrapper as I think that just selects the best rate and provides a label.
We can add rate request in later.
I'll get some production data today and post here.
@cgsmith thanks
@bohdan-vorona here is an open order for Tia Lupita that you can test with a label. If a label is generated please send it to me so the warehouse can fulfill it:
INSERT INTO shipwise.orders (id, customer_id, order_reference, customer_reference, status_id, tracking, created_date, updated_date, address_id, notes, uuid, requested_ship_date, carrier_id, service_id, origin, po_number, label_data, label_type, ship_from_name, ship_from_address1, ship_from_address2, ship_from_city, ship_from_state_id, ship_from_zip, ship_from_country_code, ship_from_phone, ship_from_email, transit, packagingNotes, must_arrive_by_date) VALUES (2688656, 49, '2732379', '113-2709605-8262607', 8, null, '2023-02-09 13:10:10', '2023-02-09 13:15:09', 2464822, 'STL', '113-2709605-8262607', '2023-02-10 00:00:00', 3, 29, 'AmazonSPAPI', null, null, null, 'Tia Lupita', '', '', '', 0, '', null, '', '', 2, '', null);
INSERT INTO shipwise.items (id, order_id, quantity, sku, name, uuid, alias_quantity, alias_sku, notes, type) VALUES (62253903, 2688656, 1, 'U-HS-HOT', 'Tia Lupita Hot Sauce | 8 oz x 1 Bottle | Flavorful Heat, Medium ', '73410353121921', null, null, null, '');
INSERT INTO shipwise.items (id, order_id, quantity, sku, name, uuid, alias_quantity, alias_sku, notes, type) VALUES (62253904, 2688656, 1, 'PKG6X6X6', 'Liner', null, null, null, null, '');
INSERT INTO shipwise.items (id, order_id, quantity, sku, name, uuid, alias_quantity, alias_sku, notes, type) VALUES (62253905, 2688656, 1, 'RNBW-INS', 'Insert', null, null, null, null, '');
INSERT INTO shipwise.items (id, order_id, quantity, sku, name, uuid, alias_quantity, alias_sku, notes, type) VALUES (62253906, 2688656, 1, 'BBLE-BAG-4X7', 'Bubble bag', null, null, null, null, '');
@cgsmith thanks
@cgsmith
Here I pushed some of my work - https://github.com/CGSmith-LLC/shipwise-api/tree/hotfix/113-amazon-mws-deprecated
What I did:
1) I created a new own class - common\models\shipping\extension\AmazonSellingPartner
which uses https://github.com/jlevers/selling-partner-api/blob/main/docs/Api/ShippingV2Api.md.
2) I extended existing plugins (AmazonUSPSPlugin, AmazonFedExPlugin, ...) from this ^ class.
3) The logic in AmazonSellingPartner
uses the needed data structure and needed classes. For example, we need to use SellingPartnerApi\Model\ShippingV2\Address
for addresses. Also, I read this guide - https://developer-docs.amazon.com/amazon-shipping/docs/amazon-shipping-api-v2-use-case-guide
4) I tried sending requests using our app as well as raw POST requests with formed data. Amazon always returns error 500 without any detailed explanation. Since I had to change the data like packages
manually, I have an assumption that my local data can just be invalid or sort of.
5) There are three steps in the base ShipmentPlugin
: shipmentPrepare, shipmentExecute, and shipmentProcess. I implemented shipmentPrepare
and shipmentExecute
which send requests to Amazon.
In AmazonSellingPartner
-> shipmentExecute
I left exit
. Can you please test until this point on your real data locally? You can just open /order/shipping-label?id={id}
where {id}
is the needed ID.
Thanks @bohdan-vorona - I will try to look at today. I don't think the packages are required if we are using the use directPurchaseShipment()
method.
I will test though.
I was running tests with the direct purchase shipment method. I receive this error which I think is from Amazon...
@bohdan-vorona I am wondering if you can get started on adding a call to their rating API? Not sure if this would help with the issue or if it is just and error on Amazon's side. I'll open a request with Amazon.
I did have to add some logic for the packages loop. Ideally the weight, height, width will come from Amazon when I pull orders in (working on that in my integration script).
Here is the updated order
. Note, this order will close out by 11a-2pm today because the warehouse will need to ship it. Not sure if Amazon Seller Central SP-API has a sandbox?
INSERT INTO cgsmpoim_shipwise.orders (id, customer_id, order_reference, customer_reference, status_id, tracking, created_date, updated_date, address_id, notes, uuid, requested_ship_date, carrier_id, service_id, origin, po_number, label_data, label_type, ship_from_name, ship_from_address1, ship_from_address2, ship_from_city, ship_from_state_id, ship_from_zip, ship_from_country_code, ship_from_phone, ship_from_email, transit, packagingNotes, must_arrive_by_date) VALUES (2574455, 49, null, '114-6493630-9001822', 9, null, '2023-02-13 12:42:15', '2023-02-13 13:16:09', 2350564, 'PRIME', '114-6493630-9001822', '2023-02-13 00:00:00', 1, 27, 'AmazonSPAPI', null, null, null, 'Tia', '34 Fairmont City Blvd', null, 'Fairmont City', 14, '62071', null, '618-227-2700', null, null, null, null);
@cgsmith Thanks. Yes, it seems that the issue on Amazon's side and related to directPurchaseShipment
. Ok, I should probably try Purchase a shipment from a rate
.
Ok. Let me know if you need anything from me. I looked at that call and it looks like a couple requests need to be sent first.
@cgsmith 👌
@bohdan-vorona added my code changes
@cgsmith Implementing the new approach with requesting rates first, now I get:
[400] { "errors": [ { "code": "InvalidInput", "message": "Invalid input", "details": "Provided input is invalid. Please verify." } ] }
I played with different request data formats, and, for example, if omit packages
:
[400] { "errors": [ { "code": "InvalidInput", "message": "Invalid input", "details": "1 validation error detected: Value null at \u0027packages\u0027 failed to satisfy constraint: Member must not be null" } ] }
It's "a bit better"...
The lib we use has its own validation. Actually, I recognized it at the beginning when I started working with it and I used the validation rules for classes of the lib.
The data I send to Amazon passes the validation rules of the lib.
Also, I tried to send raw data without any library using Talend API (an analogue of Postman).
In all cases, Amazon returns errors but without any explanations... The worst API ever)) Just take a look:
It sends some useful headers that can be used to contact them (x-amzn-RequestId
). Like:
For /shipping/v2/shipments/rates
:
Array ( [Date] => Array ( [0] => Mon, 13 Feb 2023 19:00:17 GMT ) [Content-Type] => Array ( [0] => application/json ) [Content-Length] => Array ( [0] => 158 ) [Connection] => Array ( [0] => keep-alive ) [x-amzn-RequestId] => Array ( [0] => 7da40158-f5bd-4fe2-bd29-ba3f21d0c186 ) [x-amzn-RateLimit-Limit] => Array ( [0] => 80.0 ) [x-amz-apigw-id] => Array ( [0] => ASpOPEEpoAMFSuw= ) [X-Amzn-Trace-Id] => Array ( [0] => Root=1-63ea88c1-0143af0748fa91336c7004c7 ) )
For /shipping/v2/shipments/directPurchase
:
Array ( [Date] => Array ( [0] => Mon, 13 Feb 2023 19:01:58 GMT ) [Content-Type] => Array ( [0] => application/json ) [Content-Length] => Array ( [0] => 158 ) [Connection] => Array ( [0] => keep-alive ) [x-amzn-RequestId] => Array ( [0] => 4a79ac4e-a5a7-4a59-ab8a-65e935b137cc ) [x-amz-apigw-id] => Array ( [0] => ASpeHGg2IAMFioQ= ) [X-Amzn-Trace-Id] => Array ( [0] => Root=1-63ea8926-3ac1a83d673e714406b1f13f ) )
How critical this task is? There is their contact email on the page https://developer-docs.amazon.com/amazon-shipping/docs/shipping-api-v2-reference - probably it's worth contacting them by providing the x-amzn-RequestId
. Or maybe you have access to the ticket system with them or so.
It is a priority to fix and switch to. I did open a ticket but did not send them the Request ID. I'll add that on the ticket.
I have 49-2574455
as the idempotency key. Do you want me to send one you were testing?
@cgsmith
It is a priority to fix and switch to.
Ok, I understand.
I did open a ticket but did not send them the Request ID. I'll add that on the ticket.
Thanks. Please let me know if there is any response from them)
Do you want me to send one you were testing?
Yes, please. Maybe it would be helpful.
Describe the bug When the user is trying to print for Amazon shipping labels the MWS calls are failing. SP API needs to be used instead.
Error