Answers.Body: <p>Looking through the api code for relationships it doesn't appear to be case-aware. You can duplicate what happens in the UI by checking out CRM_Contact_Page_Ajax::relationship(), and note near the bottom where it calls CRM_Case_BAO_Case::createCaseRoleActivity().</p>
  
  <p>Depending on what you mean by "api", that might not be exactly what you're looking for, but you should just be able to add a call to CRM_Case_BAO_Case::createCaseRoleActivity() to the code you've written that already creates the relationship.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-09T19:55:00.460Z
Answers.Text: brill - thank you for digging into the code on that one.
Answers.UserDisplayName: Andrew West
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-07T00:35:45.907Z
Answers.LastActivityDate: 2015-11-07T00:35:45.907Z
Answers.UserDisplayName: Demerit
Body: <p>When you assign a case role through the UI it creates lines in the relationships and activities tables. I can't find an equivalent through the API - I can create the relationship (which then shows correctly in the case UI), but it doesn't create any activity lines. Does that matter? Or is there a better way?</p>
  
  <p>Edit: Running on Civi 4.5.8 on WordPress.</p>
  
  <p>Cheers,</p>
  
  <p>Andrew</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-06T21:02:12.353Z
Comments.Text: What version of CiviCRM are you working with?
Comments.UserDisplayName: DaveD
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-11-06T21:16:32.120Z
Comments.Text: 4.5.8 - have updated the question too.
Comments.UserDisplayName: Andrew West
Tags: <api><civicase>
Title: What's the best way to assign a case role via the API?
ThreadText: # What's the best way to assign a case role via the API?
  
  (Asked by: username_0 on 2015-11-06)
  
  When you assign a case role through the UI it creates lines in the relationships and activities tables. I can't find an equivalent through the API - I can create the relationship (which then shows correctly in the case UI), but it doesn't create any activity lines. Does that matter? Or is there a better way?
  
  Edit: Running on Civi 4.5.8 on WordPress.
  
  Cheers,
  
  Andrew
  
  **Tags:** api, civicase
  
  > **Comments:**
  > **username_1**: What version of CiviCRM are you working with?  
  > **username_0**: 4.5.8 - have updated the question too.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-11-07. Score: 1 | Accepted answer
  
  Looking through the api code for relationships it doesn't appear to be case-aware. You can duplicate what happens in the UI by checking out CRM\_Contact\_Page\_Ajax::relationship(), and note near the bottom where it calls CRM\_Case\_BAO\_Case::createCaseRoleActivity().
  
  Depending on what you mean by "api", that might not be exactly what you're looking for, but you should just be able to add a call to CRM\_Case\_BAO\_Case::createCaseRoleActivity() to the code you've written that already creates the relationship.
  
  > **Comments:**
  > **username_0**: brill - thank you for digging into the code on that one.  
  
  ---
  
  