Answers.Body: <p>Unfortunately, as of this writing, there is no access to <code>EntityFile</code> in Api v4. This is the missing link between the <code>Activity</code> and <code>File</code> that you created. (In Api v3, you could add a file to an activity using <code>Attachment.create</code>, but that has not yet been ported to Api v4 either.)</p>
  <p>I added a <a href="https://lab.civicrm.org/dev/core/-/issues/2486#note_87390" rel="nofollow noreferrer">comment on this page</a>, which tracks which entities are supported by Api v4.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-02T01:35:52.563Z
Answers.LastActivityDate: 2023-02-02T14:53:22.223Z
Answers.LastEditDate: 2023-02-02T14:53:22.223Z
Answers.UserDisplayName: Noah Miller
Body: <p>I create activities using the API, and now I need to add an uploaded file (meaning it was uploaded in a Drupal form) to the activity. I tried this:</p>
  <pre><code>$results = \Civi\Api4\Activity::create()
  -&gt;addValue('activity_type_id', 91)
  -&gt;addValue('target_contact_id', [ 8, ])
  -&gt;addValue('source_contact_id', 2)
  -&gt;addValue('subject', 'test')
  -&gt;addChain('uploaded_invoice', 
    \Civi\Api4\File::create()-&gt;addValue('mime_type', 'text/plain')
       -&gt;addValue('document', 'Just Testing')
       -&gt;addValue('description', 'Invoice Scan')
  )
  -&gt;execute();
  </code></pre>
  <p>But this doesn't work, it creates the Activity, but no file is attached.</p>
  
Tags: <php><apiv4>
Title: How can I Add a File to an Activity in API v4?
ThreadText: # How can I Add a File to an Activity in API v4?
  
  (Asked by: username_0 on 2023-01-25)
  
  I create activities using the API, and now I need to add an uploaded file (meaning it was uploaded in a Drupal form) to the activity. I tried this:
  
  ```
  $results = \Civi\Api4\Activity::create()
  ->addValue('activity_type_id', 91)
  ->addValue('target_contact_id', [ 8, ])
  ->addValue('source_contact_id', 2)
  ->addValue('subject', 'test')
  ->addChain('uploaded_invoice', 
    \Civi\Api4\File::create()->addValue('mime_type', 'text/plain')
       ->addValue('document', 'Just Testing')
       ->addValue('description', 'Invoice Scan')
  )
  ->execute();
  
  ```
  
  But this doesn't work, it creates the Activity, but no file is attached.
  
  **Tags:** php, apiv4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-02-02. Score: 0
  
  Unfortunately, as of this writing, there is no access to `EntityFile` in Api v4. This is the missing link between the `Activity` and `File` that you created. (In Api v3, you could add a file to an activity using `Attachment.create`, but that has not yet been ported to Api v4 either.)
  
  I added a [comment on this page](https://lab.civicrm.org/dev/core/-/issues/2486#note_87390), which tracks which entities are supported by Api v4.
  
  
  ---
  
  