Answers.Body: <p>You need to provide same set of values to create address for members of the household with additional parameter master_id as Address foreign key id of household contact.</p>
  
  <pre><code>$addressParams = [
    'sequential' =&gt; 1,
    'contact_id' =&gt; $householdContact['id'],
    'location_type_id' =&gt; "Home",
    'is_primary' =&gt; 1,
    'street_address' =&gt; $form_state['storage']['contactInfoValues']['address1'],
    'supplemental_address_1' =&gt; $form_state['storage']['contactInfoValues']['address2'],
    'city' =&gt; $form_state['storage']['contactInfoValues']['city'],
    'state_province_id' =&gt;  $form_state['storage']['contactInfoValues']['state'],
    'country_id' =&gt; "US",
  ];
  $result = civicrm_api3('Address', 'create', $addressParams);
  
  $addressParams['master_id'] = $result['id'];
  $addressParams['contact_id'] = $primaryContact['id'];
  $result = civicrm_api3('Address', 'create', $addressParams);
  </code></pre>
  
  <p>HTH</p>
  
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-05T17:07:13.280Z
Answers.Text: Hi @pradeep, I just noticed that, we need to have 'is_primary' & 'location_type_id' to link household address to primary contact or any other 2 contacts which needs to be linked, I found this here in the answer given below and link is https://github.com/civicrm/civicrm-core/blob/865168d5d056d071d23d0273189051241c5261e5/tests/phpunit/CRM/Core/BAO/AddressTest.php#L446 .Also I tried just with master_id and contact_id and it did not work but with is_primary & location_type_id added along with contact_id and master_id it worked!
Answers.UserDisplayName: harshal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-05T13:39:22.480Z
Answers.LastActivityDate: 2018-06-05T13:39:22.480Z
Answers.UserDisplayName: Pradeep Nayak
Answers.Body: <p>You are currently supposed to add the address details to the address that is sharing the data from another address.</p>
  
  <p>You can see an example here:
  <a href="https://github.com/civicrm/civicrm-core/blob/865168d5d056d071d23d0273189051241c5261e5/tests/phpunit/CRM/Core/BAO/AddressTest.php#L446" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/865168d5d056d071d23d0273189051241c5261e5/tests/phpunit/CRM/Core/BAO/AddressTest.php#L446</a></p>
  
  <p>Your version should already create a linked address, but does not copy over the data.</p>
  
  <p>It seems only import and API suffer from this issue. The GUI actually does copy over the values. This seems like a usefull feature request.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-04T16:15:26.817Z
Answers.LastActivityDate: 2018-06-04T16:15:26.817Z
Answers.UserDisplayName: Thomas Schüttler
Body: <pre><code>$result = civicrm_api3('Address', 'create', array(
    'sequential' =&gt; 1,
    'contact_id' =&gt; $householdContact['id'],
    'location_type_id' =&gt; "Home",
    'is_primary' =&gt; 1,
    'street_address' =&gt; $form_state['storage']['contactInfoValues']['address1'],
    'supplemental_address_1' =&gt; $form_state['storage']['contactInfoValues']['address2'],
    'city' =&gt; $form_state['storage']['contactInfoValues']['city'],
    'state_province_id' =&gt;  $form_state['storage']['contactInfoValues']['state'],
    'country_id' =&gt; "US",
  ));
  
  $master_address_id = $result['id'];
  
  
  
   $result = civicrm_api3('Address', 'create', array(
            'sequential' =&gt; 1,
            'contact_id' =&gt; $primaryContact['id'],
            'master_id'  =&gt; $master_address_id,
            'location_type_id' =&gt; "Home",
          ));
  </code></pre>
  
  <p>I need to attach the household address with primary contact address . How can i achieve I tried by implementing above ,but it did not work?</p>
  
Tags: <api><addresses><households>
Title: How to connect your household address to its members in civicrm api v3?
ThreadText: # How to connect your household address to its members in civicrm api v3?
  
  (Asked by: username_0 on 2018-06-04)
  
  $result = civicrm_api3('Address', 'create', array(
    'sequential' => 1,
    'contact_id' => $householdContact['id'],
    'location_type_id' => "Home",
    'is_primary' => 1,
    'street_address' => $form_state['storage']['contactInfoValues']['address1'],
    'supplemental_address_1' => $form_state['storage']['contactInfoValues']['address2'],
    'city' => $form_state['storage']['contactInfoValues']['city'],
    'state_province_id' =>  $form_state['storage']['contactInfoValues']['state'],
    'country_id' => "US",
  ));
  
  $master_address_id = $result['id'];
  
  
  
   $result = civicrm_api3('Address', 'create', array(
            'sequential' => 1,
            'contact_id' => $primaryContact['id'],
            'master_id'  => $master_address_id,
            'location_type_id' => "Home",
          ));
  
  I need to attach the household address with primary contact address . How can i achieve I tried by implementing above ,but it did not work?
  
  **Tags:** api, addresses, households
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-06-05. Score: 2
  
  You need to provide same set of values to create address for members of the household with additional parameter master_id as Address foreign key id of household contact.
  $addressParams = [
    'sequential' => 1,
    'contact_id' => $householdContact['id'],
    'location_type_id' => "Home",
    'is_primary' => 1,
    'street_address' => $form_state['storage']['contactInfoValues']['address1'],
    'supplemental_address_1' => $form_state['storage']['contactInfoValues']['address2'],
    'city' => $form_state['storage']['contactInfoValues']['city'],
    'state_province_id' =>  $form_state['storage']['contactInfoValues']['state'],
    'country_id' => "US",
  ];
  $result = civicrm_api3('Address', 'create', $addressParams);
  
  $addressParams['master_id'] = $result['id'];
  $addressParams['contact_id'] = $primaryContact['id'];
  $result = civicrm_api3('Address', 'create', $addressParams);
  
  HTH
  Pradeep
  
  > **Comments:**
  > **username_0**: Hi @pradeep, I just noticed that, we need to have 'is_primary' & 'location_type_id' to link household address to primary contact or any other 2 contacts which needs to be linked, I found this here in the answer given below and link is https://github.com/civicrm/civicrm-core/blob/865168d5d056d071d23d0273189051241c5261e5/tests/phpunit/CRM/Core/BAO/AddressTest.php#L446 .Also I tried just with master_id and contact_id and it did not work but with is_primary & location_type_id added along with contact_id and master_id it worked!  
  
  ---
  
  ### Answer by username_2 on 2018-06-04. Score: 1
  
  You are currently supposed to add the address details to the address that is sharing the data from another address.
  
  You can see an example here:
  <https://github.com/civicrm/civicrm-core/blob/865168d5d056d071d23d0273189051241c5261e5/tests/phpunit/CRM/Core/BAO/AddressTest.php#L446>
  
  Your version should already create a linked address, but does not copy over the data.
  
  It seems only import and API suffer from this issue. The GUI actually does copy over the values. This seems like a usefull feature request.
  
  
  ---
  
  