Answers.Body: <p>At this point, no, at least as long as you aren't using the API as the member him/herself.  The relevant line is <a href="https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Activity/BAO/Activity.php#L1886" rel="nofollow">https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Activity/BAO/Activity.php#L1886</a>:</p>
  
  <pre><code>// create activity with target contacts
  $session = CRM_Core_Session::singleton();
  $id = $session-&gt;get('userID');
  if ($id) {
    $activityParams['source_contact_id'] = $id;
    $activityParams['target_contact_id'][] = $activity-&gt;contact_id;
  }
  </code></pre>
  
  <p>Basically, CRM_Member_BAO_Membership::create calls CRM_Activity_BAO_Activity::addActivity, and the code above just forces the source contact to be whoever's logged-in.</p>
  
  <p>Ironically, just a few lines above, the activity source contact is set to be the ID set in the <code>contact_id</code> property of the activity object passed to the function from the membership, but this overrides it.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-04T06:37:38.153Z
Answers.Text: Thanks @Andrew, and ironically indeed :-) I'll just go with my workaround.
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-03T16:51:49.747Z
Answers.LastActivityDate: 2015-08-03T16:51:49.747Z
Answers.UserDisplayName: Andie Hunt
Body: <p>In my project I am using a scheduled job to get street recruitment data from a csv file and create a new membership with the API if required. When the membership is created, an activitiy is also automatically created using the logged in user as the activity source contact. Does anyone know if I can influence this activity source contact with the API?
  My workaround is changing the activity once it is generated with the post hook. Works, but is a bit hackish :-)</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-03T19:40:45.913Z
Comments.Text: ErikH, interesting question, can you add the activities tag to it?
Comments.UserDisplayName: Joe McLaughlin
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-08-03T20:07:13.747Z
Comments.Text: I added the tag.
Comments.UserDisplayName: Jon G - Megaphone Tech
Tags: <civimember><api><extension><activities>
Title: Can I influence the activity source contact with the membership API Create action?
ThreadText: # Can I influence the activity source contact with the membership API Create action?
  
  (Asked by: username_0 on 2015-08-03)
  
  In my project I am using a scheduled job to get street recruitment data from a csv file and create a new membership with the API if required. When the membership is created, an activitiy is also automatically created using the logged in user as the activity source contact. Does anyone know if I can influence this activity source contact with the API?
  My workaround is changing the activity once it is generated with the post hook. Works, but is a bit hackish :-)
  
  **Tags:** civimember, api, extension, activities
  
  > **Comments:**
  > **username_1**: ErikH, interesting question, can you add the activities tag to it?  
  > **username_2**: I added the tag.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2015-08-03. Score: 3 | Accepted answer
  
  At this point, no, at least as long as you aren't using the API as the member him/herself.  The relevant line is https://github.com/civicrm/civicrm-core/blob/4.6/CRM/Activity/BAO/Activity.php#L1886:
  // create activity with target contacts
  $session = CRM_Core_Session::singleton();
  $id = $session->get('userID');
  if ($id) {
    $activityParams['source_contact_id'] = $id;
    $activityParams['target_contact_id'][] = $activity->contact_id;
  }
  
  Basically, CRM_Member_BAO_Membership::create calls CRM_Activity_BAO_Activity::addActivity, and the code above just forces the source contact to be whoever's logged-in.
  Ironically, just a few lines above, the activity source contact is set to be the ID set in the contact_id property of the activity object passed to the function from the membership, but this overrides it.
  
  > **Comments:**
  > **username_0**: Thanks @Andrew, and ironically indeed :-) I'll just go with my workaround.  
  
  ---
  
  