Magento, Magento 2

How to add new customer address by REST API in Magento 2

How to add new customer address by REST API in Magento 2

In this tutorial, Today I will explain to you how to add new customer address by REST API in Magento 2. In Magento 2, If you want to add new customer address, you must require a customer token before add new customer address.

You can get customer access token from this below url. For that, you need to pass customer email and customer password.

You may also like this :

1) First of all, Set End Point of REST API :

{{url}}/rest/{store_code}/V1/customers/me

{{url}} = Your_Site_Base_Url

2) After that, Set your End point as URL and set Method : PUT

3) Set Headers as

  • Content-Type(key): application/json(value)
  • Authorization Bearer(key): {customer_access_toke}(value)

Request Body :

{
  "customer": {
    "email": "test@gmail.com",
    "firstname":"Rohan",
    "lastname":"Hapani",
    "website_id": 1,
    "addresses": [
      {
        "region": {
            "region_code": "NY",
            "region": "New York",
            "region_id": 43
        },
        "country_id": "US",
        "street": [
            "Add",
            "Add2"
        ],
        "firstname": "Rohan",
        "lastname": "Hapani"
        "default_shipping": true,
        "default_billing": true,
        "telephone": "1234567890",
        "postcode": "98761",
        "city": "New York",
      },
      {
        "region": {
          "region_code": "NY",
          "region": "New York",
          "region_id": 43
        },
        "country_id": "US",
        "street": [
          "Add3",
          "Add4"
        ],
        "firstname": "Rohan",
        "lastname": "Hapani",
        "defaultShipping": false,
        "defaultBilling": false,
        "telephone": "9876543210",
        "postcode": "10755",
        "city": "New York",
      }
    ]
  }
}

You just need to set data based on your customer details. Just copy this and paste into request body. After that, execute API and check it. Here, you need to pass firstname, lastname, email, website_id these all fields are required. For the address, you need to set value inside addresses array.

Using this API, You can set default_shipping and default_billing address by set value in request body json. After execute API, you will be display output based on your data.

That’s it !!!

I hope this blog is easy to understand about how to add new customer address by REST API in Magento 2. In case, I missed anything or need to add some information, always feel free to leave a comment in this blog, I’ll get back with proper solution.

Stay Safe and Stay Connected !!

Tagged , ,