3

This is what i am following...

1. Add Configurable product in cart.

http://magento-host/index.php/rest/default/V1/carts/mine/items
  • method : POST
  • Authorization : Bearer <customer token>
  • body data : json

{
  "cartItem": {
    "sku": "HKrh15hc", <product SKU>
    "qty": 5,
    "quote_id": "75", <Quote ID - Cart ID>
    "product_option": {
      "extension_attributes": {
        "configurable_item_options": [
          {
            "option_id": "93",
            "option_value": 49
          },
          {
            "option_id": "141",
            "option_value": 168
          }
        ]
      }
    },
    "extension_attributes": {}
  }
}

Now, this is saving my configurable product in my cart.


2. Get & put Shipping Information.

http://magento-host/index.php/rest/V1/carts/mine/shipping-information
  • method : POST
  • Authorization : Bearer <customer token>
  • body data : json

{
    "addressInformation": {
        "shippingAddress": {
            "region": "MH",
            "region_id": 0,
            "country_id": "IN",
            "street": [
                "221,Baker-street (e)"
            ],
            "company": "Lumos",
            "telephone": "12345678",
            "postcode": "400001",
            "city": "Mumbai",
            "firstname": "Aditya",
            "lastname": "Shah",
            "email": "Aditya@Shah.com",
            "prefix": "address_",
            "region_code": "MH",
            "sameAsBilling": 1
        },
        "billingAddress": {
            "region": "MH",
            "region_id": 0,
            "country_id": "IN",
            "street": [
                "221,Baker-street (e)"
            ],
            "company": "Lumos",
            "telephone": "12345678",
            "postcode": "4000001",
            "city": "Mumbai",
            "firstname": "Aditya",
            "lastname": "Shah",
            "email": "Aditya@Shah.com",
            "prefix": "address_",
            "region_code": "MH"
        },
        "shipping_method_code": "flatrate",
        "shipping_carrier_code": "flatrate"
    }
}

  • Now, this 2nd STEP - Do i need to add shipping and Billing address every-time ?
  • Whenever i place a new order with the same customer ?

3. Get payment method.

http://magento-host/index.php/rest/V1/carts/75/payment-methods
  • method : POST
  • Authorization : Bearer <customer token>

4. Place an order.

http://magento-host/index.php/rest/V1/carts/mine/order
  • method : POST
  • Authorization : Bearer <customer token>
  • body data : json

{
    "paymentMethod": {
        "method": "checkmo"
    }
}

Concern


IN Step -2

1. Do i need to add address (Billing and Shipping) every-time to place an order ?

2. Is there any thing like pass the address_id or default address - so i don't need to add addresses every-time.

4
  • when you set the use as default shipping/billing address for customer it does not automatically use those addresses in the api?
    – djfordz
    Dec 24 '18 at 13:59
  • No it doesn't -REST API is not fetching defaultShipping address value. Dec 24 '18 at 14:08
  • did you get the solution?
    – Hiren
    Mar 26 '19 at 12:22
  • Yes I got the solution. Mar 26 '19 at 12:45
1

Magento 2 have API - which we can select from existing address from customer account addresses API, so customer don't need to add address every time whenever he/she places a new order.

quoteShippingMethodManagementV1

Interface ShippingMethodManagementInterface

POST /V1/carts/mine/estimate-shipping-methods-by-address-id

Data

{
  "addressId": 0
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.