cancel
Showing results for 
Search instead for 
Did you mean: 

Rest API: Unable to add shipping address by ID to cart

0 Kudos

Rest API: Unable to add shipping address by ID to cart

Feature request from RUjmiak, posted on GitHub Oct 19, 2016

  1. Magento 2.1.2

    Steps to reproduce

  2. Customer login
  3. Create cart (carts/mine)
  4. Add product to cart
  5. Create address (via put customers/me)
  6. Now I have address ID 109115
  7. I checked available shipping for my address (V1/carts/mine/estimate-shipping-methods-by-address-id) and in response I get that flatrate is available.

    Expected result

  8. One simple call with which I can add shipping address ID to cart.

    Actual result

  9. You need to use POST V1/carts/mine/shipping-information where you cant use just ID

{ "addressInformation": { "shippingAddress": { "id": 109115, "customerAddressId": 109115 }, "shippingMethodCode": "flatrate", "shippingCarrierCode": "flatrate" } }

result: Error 400 Shipping address is not set

or when { "addressInformation": { "shippingAddress": { "customerAddressId": 109115 }, "shippingMethodCode": "flatrate", "shippingCarrierCode": "flatrate" } }

result: Error 400 Shipping address is not set

or when { "addressInformation": { "shippingAddress": { "id": 109115 }, "shippingMethodCode": "flatrate", "shippingCarrierCode": "flatrate" } }

result: Error 400 Shipping address is not set

OK lets to add address. Here is another funny part. You cant use address ID because it is not working (and we are just starting)

{ "addressInformation": { "shippingAddress": { "id": 109115, "region": "", "regionId": 0, "regionCode": "", "countryId": "SK", "street": [ "string" ], "telephone": "0902222", "postcode": "82100", "city": "Bratislava", "firstname": "My name", "lastname": "My last name", "customerAddressId": 109115, "customerId": 124252 }, "shippingMethodCode": "flatrate", "shippingCarrierCode": "flatrate" } }

response Error 400: Unable to save shipping information. Please check input data.

Here we can look on another weird thing - why right now we are using another address attribute name asi it is on customers/me calls? For example on customers/me call region is array, customer_id vs customerId, region_id vs regionId, country_id vs countryId... The right hand does not know what makes left...

So how we can set saved address to cart? We cant... What we need to do is to get address from customers/me, then rewrite it to different structure in shipping-information call AND delete address ID. So call should look like

{ "addressInformation": { "shippingAddress": { "region": "", "regionId": 0, "regionCode": "", "countryId": "SK", "street": [ "string" ], "telephone": "0902222", "postcode": "82100", "city": "Bratislava", "firstname": "My name", "lastname": "My last name" }, "shippingMethodCode": "flatrate", "shippingCarrierCode": "flatrate" } }

Vuala - this is working - but is this good? I think that this is bug and it should be done more simple.

Thanks guys

2 Comments
apiuser
New Member
Status changed to: Investigating
 
apiuser
New Member

Comment from SerhiyShkolyarenko, posted on GitHub Oct 26, 2016

@RUjmiak V1/carts/mine/shipping-information is a composite(aggregate) service which processes shipping address, billing address, shipping carrier code and shipping method code, then returns payment information. It was created for one page checkout higher performance. It needs full data object(full address data).

In Magento quote address and customer address are different instances, so they are not fully compatible. So you need to convert them. Created a ticket for improvement MAGETWO-60153(simple services for setting shipping address and setting shipping method). Thank you for reporting!