Sylius / ShopApiPlugin

Shop API for Sylius.
https://sylius.com
129 stars 89 forks source link

[HELP] - Choosing a cart shipping method Endpoint - From where can we find the order ID of the current order? Is there any specific endpoint should we need to tryout to get the order ID ? #674

Closed hasithaarimac closed 4 years ago

hasithaarimac commented 4 years ago

Guys, I need a little help from you. Currently, I need to set a shipping method for my order. For that, I executed the first 3 endpoints of the Checkout flow in a sequence way and Those were succeeded. But for the 4th endpoint, there is a required parameter called "ID" in the payload (as per my understanding it asks for an order ID). So from where can we find the order ID of the current order? Is there any specific endpoint should we need to try out to get the order ID? Please help me to get a solution for this. Thank you

image

Endpoint : Choosing a cart shipping method endpoint (/checkout/:token/shipping/:id)

mamazu commented 4 years ago

Hello thanks for reporting the issue. We definitely need to revise the documentation for that.

The id you are looking for is the Id of the shipping method. This can be aquired by using the GET /checkout/{token}/shipping endpoint.

hasithaarimac commented 4 years ago

Hi mamazu,

Thank you for the quick response. As per the "GET /checkout/{token}/shipping" endpoint response, there is no ID for a shipping method. It has only code and a name. So I tried out the "Choosing a cart shipping method" using the shipment method code but still I'm getting the same response from the server. Please check the below response from the server,

Response message

{ "code": 500, "message": "Can not find shipment with given identifier." }

Response - GET /checkout/{token}/shipping Endpoint

{ "shipments": [ { "methods": { "shippingMethod": { "code": "shippingMethod", "name": "shippingMethod", "price": { "current": 10000, "currency": "USD" } } } } ] }

Also, we're sending the shipping method again in the request body too. Please check the attached screenshots.

image

These are the versions that we're using now.

Sylius - 1.7.0 (Latest) Sylius Documentation - 1.7 Sylius shop API - 1.1 (Latest) Sylius shop Documentation - 1.0.0

devel-pa commented 4 years ago

Hi,

https://github.com/Sylius/ShopApiPlugin/issues/649#issuecomment-633524599

Same with payment method. Best,

Paul

mamazu commented 4 years ago

The response of the get endpoint is correct. It looks like you only have one shipping method set up so if you want to use it you need the "id" to be 0. The id (which is usually short for identifier) is in this case the index in the response.

hasithaarimac commented 4 years ago

Hi Mamazu,

Thanks for the response again. We tried with the position code of the shipping method and still getting the same issue.

{ "code": 500, "message": "Can not find shipment with given identifier." }

Actually, there are 5 shipping methods available (Check the below postman screenshot). The "position ID" of the selected method is "3".

Please find the below curl of the request.

curl --location --request PUT 'http://{host}/shop-api/checkout/b56ceb12-969c-4c53-aa08-65ab6821580e/shipping/3' \
--header 'Content-Type: application/json' \
--data-raw '{
    "method": "shippingMethod"
}'

Please find the below screenshots of the admin panel and the request body as well.

image

image

image

image

mamazu commented 4 years ago

Can you try 0 as the id? (This should work).

If not can you please provide a stack trace on where this error is happening?

diimpp commented 4 years ago

@hasithaarimac you're using wrong index. Over here index is a position of shipment element in the cart-summary json output. Usually it will be 0 and it's not related to shipping method in the admin panel.

If it still doesn't work, I gather from your other ticket, that you have shipping_skipped state and no shipments in your cart, then this is your issue and you need to fix it first.

hasithaarimac commented 4 years ago

@diimpp @mamazu Thanks for the valuable inputs. Seems like I used the wrong index to add the shipping method to the cart. Now it works well. Thanks for the help guys. cheers!