3

I have used This API as in the first image to create customer now I want to add the address for this customer please tell me how to do so? Thanks,

4

1 Answer 1

1

You can add address by using bellow api -

Endpoint: customers/me

Method: PUT/GET

Token: Customer-Token

Get method -> fetch information of customer.

Put method -> add or update address of customer.

Request Body(add edit only personal information or create user):

{
"customer":{
"firstname":"firstname",
"lastname":"lastname",
"email":"[email protected]",
"store_id": 1,
"website_id":1
}
}

Add address of existing customer - Method: Put

Request Body:

{
"customer":{
"firstname":"firstname",
"lastname":"lastname",
"email":"[email protected]",
"store_id": 1,
"website_id":1,
"addresses":[
{
"country_id":"IN",
"firstname":"Rakesh",
"lastname":"Chand",
"city":"Muktsar",
"telephone":"1234561230",
"postcode":"210302",
"Default_shipping":1,                          // 1 for true & 0 for false
"default_billing":1,
"Street":["ganj"],
"region":{
"region_code":"PB",
"region":"Punjab",
"Region_id":1678
}]
}
]
}
}

add one more address -

Method: Put

Request Body:

    {
        "customer":{
        "firstname":"firstname",
        "lastname":"lastname",
        "email":"[email protected]",
        "store_id": 1,
        "website_id":1,
        "addresses":[
        {
        "id": 181,    // use previous address id 
        "country_id":"IN",
        "firstname":"Rakesh",
        "lastname":"Chand",
        "city":"Muktsar",
        "telephone":"1234561230",
        "postcode":"210302",
        "Default_shipping":1,                          // 1 for true & 0 for false
        "default_billing":1,
        "Street":["ganj"],
        "region":{
        "region_code":"PB",
        "region":"Punjab",
        "Region_id":1678
        }, 
{  // this is one more address 
        "country_id":"IN",
        "firstname":"Rakesh1",
        "lastname":"Chand1",
        "city":"Muktsar",
        "telephone":"1234561230",
        "postcode":"210303",
        "Default_shipping":1,                          // 1 for true & 0 for false
        "default_billing":1,
        "Street":["ganj"],
        "region":{
        "region_code":"PB",
        "region":"Punjab",
        "Region_id":1678
        }
]
        }
        ]
        }
        }

Please note bellow points -

1-> if you want small changes on any one address then you need create request body of all address with changes address.

2-> if you remove any address from request body that means you want delete this address.

3-> don't change previous address id. if you do than magento delete this address and create new with new address id.

This information will help you.

9
  • Thanks for your response but if i want to change the address of existing customer? because i already created customer Feb 26, 2019 at 12:29
  • also, a person can have multiple addresses how can we achieve same Feb 26, 2019 at 12:47
  • Yes you can do both think. Feb 27, 2019 at 4:45
  • sir if I send it again then old address gets deleted and new stored how can we achieve multiple addresses can you please tell Feb 27, 2019 at 4:51
  • please check updated answer. Feb 27, 2019 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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