Answers.Body: <p>For the first part did you try creator_id?</p>
  <p>For the second one yes just do it after. Relationship.create with a case_id parameter.</p>
  <p>EXAMPLES (for clarity):</p>
  <pre><code>// PHP
  // Create a NEW CASE with CLIENT contact_id=3175 and CASE MANAGER contact_id=1108
  // Pick the case_type_id you want and the status_id that you want.
  $results = civicrm_api4('Case', 'create', [
    'values' =&gt; [
      'case_type_id' =&gt; 4,
      'subject' =&gt; 'my subject',
      'details' =&gt; 'enter your case details here. whatever you want.',
      'status_id' =&gt; 1,
      'contact_id' =&gt; [3175],
      'creator_id' =&gt; 1108,
    ],
    'checkPermissions' =&gt; TRUE,
  ]);
  
  // Add ROLE of Counsellor Is for contact_id=799 to an existing Case.
  // contact_id_a should be the contact_id of the CLIENT (3175 in this example).
  // contact_id_b is the person that you want to asssign the role to (799 in this example).
  // Pick the relationship_type_id that you want, and then choose the case_id for the specific case that you want.
  $results = civicrm_api4('Relationship', 'create', [
    'values' =&gt; [
      'contact_id_a' =&gt; 3175,
      'contact_id_b' =&gt; 799,
      'relationship_type_id' =&gt; 17,
      'case_id' =&gt; 9,
    ],
    'checkPermissions' =&gt; TRUE,
  ]);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-13T06:44:32.277Z
Answers.Text: For Q1, yes creator_id worked! But for Q2, I do not want to create a relationship, but I am talking about the ROLES tab within the case. I can not figure out how to add a new ROLE to the case. (see screenshot I added to question)
Answers.UserDisplayName: jsherk
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-13T07:09:29.967Z
Answers.Text: Okay ignore my last comment... yes relationship.create DOES work. You must specify `contact_id_a` as the user id of the CLIENT of the case, and then `contact_id_b` as the user id of whoever you want the 'Counsellor' to be, and then `relationship_type_id` = 17 (in my case) and then finally set `case_id` to the id of the case.
Answers.UserDisplayName: jsherk
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-13T14:13:39.267Z
Answers.Text: Yes case roles are identical to relationships except they only exist for the life of the case. If I were to redesign the case management screen one thing I would do is combine the roles and other relationships sections to make this clearer. People put things like sibling into roles, but those are really regular relationships since they (usually) exist outside of the lifetime of the case.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-08-13T02:44:50.257Z
Answers.LastActivityDate: 2024-08-13T19:39:31.493Z
Answers.LastEditDate: 2024-08-13T19:39:31.493Z
Answers.UserDisplayName: Demerit
Body: <p>Some of these API calls get complicated, and I am unable to figure out the following...</p>
  <p>I am able to create a new case using the APIv4 as follows (client contact_id=3175):</p>
  <pre><code>$results = civicrm_api4('Case', 'create', [
    'values' =&gt; [
      'case_type_id' =&gt; 4,
      'subject' =&gt; 'My case subject',
      'start_date' =&gt; '2024-08-12',
      'details' =&gt; '&lt;p&gt;my case details&lt;/p&gt;',
      'status_id' =&gt; 1,
      'contact_id' =&gt; [3175],
    ],
    'checkPermissions' =&gt; TRUE,
  ]);
  </code></pre>
  <p>Q1:
  When the Case is created, it sets myself (administrator user) as the Case Manager (Case Coordinator Is). How can I create this case, but using a different user (contact_id=1108) as the case manager/coordinator (relationship_type_id=22)?</p>
  <p>Q2:
  The other thing I want to do is add another ROLE of Counsellor Is (relationship_type_id=17) John Doe (contact_id=803).
  How can I add this during creation as well (or add it after creation with another call)?</p>
  <p>Here is screenshot for Q2 ...
  <a href="https://i.sstatic.net/YjIL0W0x.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YjIL0W0x.jpg" alt="enter image description here" /></a></p>
  
Tags: <api><civicase><apiv4><api4>
Title: Use APIv4 to change Case Manager role and to add another role as well
ThreadText: # Use APIv4 to change Case Manager role and to add another role as well
  
  (Asked by: username_0 on 2024-08-13)
  
  Some of these API calls get complicated, and I am unable to figure out the following...
  I am able to create a new case using the APIv4 as follows (client contact_id=3175):
  $results = civicrm_api4('Case', 'create', [
    'values' => [
      'case_type_id' => 4,
      'subject' => 'My case subject',
      'start_date' => '2024-08-12',
      'details' => 'my case details',
      'status_id' => 1,
      'contact_id' => [3175],
    ],
    'checkPermissions' => TRUE,
  ]);
  
  Q1:
  When the Case is created, it sets myself (administrator user) as the Case Manager (Case Coordinator Is). How can I create this case, but using a different user (contact_id=1108) as the case manager/coordinator (relationship_type_id=22)?
  Q2:
  The other thing I want to do is add another ROLE of Counsellor Is (relationship_type_id=17) John Doe (contact_id=803).
  How can I add this during creation as well (or add it after creation with another call)?
  Here is screenshot for Q2 ...
  
  **Tags:** api, civicase, apiv4, api4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-08-13. Score: 2 | Accepted answer
  
  For the first part did you try creator_id?
  For the second one yes just do it after. Relationship.create with a case_id parameter.
  EXAMPLES (for clarity):
  // PHP
  // Create a NEW CASE with CLIENT contact_id=3175 and CASE MANAGER contact_id=1108
  // Pick the case_type_id you want and the status_id that you want.
  $results = civicrm_api4('Case', 'create', [
    'values' => [
      'case_type_id' => 4,
      'subject' => 'my subject',
      'details' => 'enter your case details here. whatever you want.',
      'status_id' => 1,
      'contact_id' => [3175],
      'creator_id' => 1108,
    ],
    'checkPermissions' => TRUE,
  ]);
  
  // Add ROLE of Counsellor Is for contact_id=799 to an existing Case.
  // contact_id_a should be the contact_id of the CLIENT (3175 in this example).
  // contact_id_b is the person that you want to asssign the role to (799 in this example).
  // Pick the relationship_type_id that you want, and then choose the case_id for the specific case that you want.
  $results = civicrm_api4('Relationship', 'create', [
    'values' => [
      'contact_id_a' => 3175,
      'contact_id_b' => 799,
      'relationship_type_id' => 17,
      'case_id' => 9,
    ],
    'checkPermissions' => TRUE,
  ]);
  
  > **Comments:**
  > **username_0**: For Q1, yes creator_id worked! But for Q2, I do not want to create a relationship, but I am talking about the ROLES tab within the case. I can not figure out how to add a new ROLE to the case. (see screenshot I added to question)  
  > **username_0**: Okay ignore my last comment... yes relationship.create DOES work. You must specify `contact_id_a` as the user id of the CLIENT of the case, and then `contact_id_b` as the user id of whoever you want the 'Counsellor' to be, and then `relationship_type_id` = 17 (in my case) and then finally set `case_id` to the id of the case.  
  > **username_1**: Yes case roles are identical to relationships except they only exist for the life of the case. If I were to redesign the case management screen one thing I would do is combine the roles and other relationships sections to make this clearer. People put things like sibling into roles, but those are really regular relationships since they (usually) exist outside of the lifetime of the case.  
  
  ---
  
  