Answers.Body: <p>So I'm fairly sure this issue was actually a dev environment specific issue. The dev database wasn't using the full 'activity' table (as it was so large) and thus creating some oddities. </p>
  
  <p>If I see it again on a live env I'll have to investigate in future though.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-18T23:19:25.210Z
Answers.LastActivityDate: 2016-10-18T23:19:25.210Z
Answers.UserDisplayName: RupertDance
Body: <p>So we create an activity when a contact 'refers a friend', we want it on both users Contact. This is working thus:</p>
  
  <pre><code>$activity = civicrm_api(
        'Activity',
        'create',
        array(
            'version' =&gt; 3,
            'sequential' =&gt; 1,
            'activity_type_id' =&gt; 60, //refer activity
            'status_id' =&gt; 2,  // complete
            'source_contact_id' =&gt; $post['contactId'], 
            'target_contact_id' =&gt; $contact['contact_id'], //person who created it
            'activity_subject' =&gt;
               'Referred by a mate: ' . $post['contactId'],
        )
  );
  </code></pre>
  
  <p>Works correctly to link the two contacts via the Activity.</p>
  
  <p>But - in the 'With' field, it also adds a second person each time, unrequested. The extra persons contactId increments by 1 each time - which may be a hint.</p>
  
  <p>We've logged all through our code, and through Core trying to find where this is being added, but can't find. Does anyone have any hints on where to look/log for this behaviour?</p>
  
Tags: <contacts><api><activities><activity>
Title: Creating activities in code adds extraneous contact to 'with' field
ThreadText: # Creating activities in code adds extraneous contact to 'with' field
  
  (Asked by: username_0 on 2016-10-13)
  
  So we create an activity when a contact 'refers a friend', we want it on both users Contact. This is working thus:
  $activity = civicrm_api(
        'Activity',
        'create',
        array(
            'version' => 3,
            'sequential' => 1,
            'activity_type_id' => 60, //refer activity
            'status_id' => 2,  // complete
            'source_contact_id' => $post['contactId'], 
            'target_contact_id' => $contact['contact_id'], //person who created it
            'activity_subject' =>
               'Referred by a mate: ' . $post['contactId'],
        )
  );
  
  Works correctly to link the two contacts via the Activity.
  But - in the 'With' field, it also adds a second person each time, unrequested. The extra persons contactId increments by 1 each time - which may be a hint.
  We've logged all through our code, and through Core trying to find where this is being added, but can't find. Does anyone have any hints on where to look/log for this behaviour?
  
  **Tags:** contacts, api, activities, activity
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-10-18. Score: 1
  
  So I'm fairly sure this issue was actually a dev environment specific issue. The dev database wasn't using the full 'activity' table (as it was so large) and thus creating some oddities.
  
  If I see it again on a live env I'll have to investigate in future though.
  
  
  ---
  
  