I was having a similar problem and was digging into the AccountManagement class to find the proper payload. I noticed that the createAccount function checks if a customer ID exists and loads the stored data.
By performing a POST /V1/customers/:id
, I was able to add another address with the following payload:
{ "customer":
{
"email":"testing2@testing.com",
"firstname":"test",
"lastname":"test",
"websiteId": 0,
"addresses": [
{
"id": 9,
"firstname": "test",
"lastname": "test",
"company": "test technology",
"street": [
"Test Street 9",
"Tiny House 9"
],
"city": "City Nine",
"region_id": 12,
"region": "California",
"postcode": "91790",
"country_id": "US",
"telephone": "1234567890"
},
{
"firstname": "test",
"lastname": "test",
"company": "test technology",
"street": [
"Test Street 10",
"Tiny House 10"
],
"city": "City Ten",
"region_id": 12,
"region": "California",
"postcode": "91790",
"country_id": "US",
"telephone": "1234567890"
}
]
}
By post method how did you do this actually when i am trying it is showing me error of missing route did you write webapi.xml code for this route.
Another Way:
add endp point app/code/YourCompany/Customer/etc/webapi.xml
<route url="/V1/addresses" method="POST">
<service class="Magento\Customer\Api\AddressRepositoryInterface" method="save"/>
<resources>
<resource ref="Magento_Customer::manage"/>
</resources>
</route>
Body:
{
"address": {
"customer_id": "363",
"defaultShipping": true,
"defaultBilling": true,
"region": "Adabor - Dhaka",
"country_id": "BD",
"street": [ "304, Tejgaon IA" ],
"postcode": "1208",
"city": "Dhaka",
"firstname": "Matin",
"lastname": "Api Adrss",
"telephone": "01717676441",
"countryId": "BD"
}
}
If Update Existing address add addressID on body preload:
"id": 323,
"customer_id": "363",
Post: http://yourstore.com/rest/V1/addresses [admin integration token]
[get CustomerID http://yourstore.com/rest/V1/customers/me getMethod customer token]
Best Answer
@jsparo30 We have only one default shipping address and one default billing address, when you hit api first it sets to default shipping/billing address because you send a parameter
When you call it second time , i think you forget to make it false, that's why it deleted you previous address.