Skip to content

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

@RUjmiak

Description

@RUjmiak
  1. Magento 2.1.2

Steps to reproduce

  1. Customer login
  2. Create cart (carts/mine)
  3. Add product to cart
  4. Create address (via put customers/me)
  5. Now I have address ID 109115
  6. 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

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

Actual result

  1. 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

Metadata

Metadata

Labels

Component: Framework/WebapiUSE ONLY for FRAMEWORK RELATED BUG! E.g If bug related to Catalog WEB API use just CatalogIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentimprovement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions