So practically, i'm importing data over API and saving it like this :

(not all the code but only the relevant)

    ->setCustomAttribute('exact_address_id', $contactaddress['ID'])

    if ($contact['account']['AddressLine1'] == $contactaddress['AddressLine1']) {
    } else {
    try {

And everything seems to work fine , everything is filled in and in the database addresses are created.


Even though my database table customer_address_entity says 'BE' (which is id for Belgium) under country_id the field itself is empty.

Even more so when i save the customer myself with the address nothing really changes. Its still BE.

address example

Anyone any idea?

Github : Github magento 2 report

1 Answer 1


Add below code after $address->save and check

$address->getResource()->saveAttribute($address, 'country_id'); 
  • Which address repository/interface/model are you using? Because i have ->save in addressRepository and i have setcountryID in addressinterface and get resource in address model. But you are using the same variable for all 3? Sep 22, 2017 at 20:48
  • So you would set the country ID after the save? Sep 22, 2017 at 20:51
  • yes, you should add this two lines after save() function
    – Amit Bera
    Sep 23, 2017 at 7:19
  • those don't work because $addres komes from $address = $this->_addressRepository; --> Magento\Customer\Api\AddressRepositoryInterface; and that class does not have ->getResource() function. Sep 23, 2017 at 22:03
  • So from which class do you advice me to extend from? Sep 24, 2017 at 16:07

Your Answer

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

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