Answers.Body: <p>It depends what you mean by &quot;API&quot;. If it's a script you're going to run overnight you could do something like this and put it in a file, let's say <code>labels.php</code>:</p>
  <pre><code>&lt;?php
  $form = new CRM_Contact_Form_Task_Label();
  // Array of contact ids - could get this from wherever.
  $form-&gt;_contactIds = array(2,3,4);
  $params = array(
    'label_name' =&gt; 3475,
    'location_type_id' =&gt; NULL,
    'do_not_mail' =&gt; 1,
  );
  $form-&gt;postProcess($params);
  </code></pre>
  <p>Then run the script with <code>cv</code>, e.g. <code>cv scr --user=admin labels.php &gt; output.pdf</code></p>
  <p>Or some variation of that. There's some trickiness to capturing the output within the script if you didn't want to redirect to a file - you'd either have to duplicate a lot of code or rely on something that is <a href="https://github.com/civicrm/civicrm-core/blob/42560b220ea8da1f57a75bc69e86283d53f420d5/CRM/Contact/Form/Task/Label.php#L334" rel="nofollow noreferrer">internally used</a> for unit tests and could disappear.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-05-11T01:10:52.803Z
Answers.LastActivityDate: 2021-05-11T01:10:52.803Z
Answers.UserDisplayName: Demerit
Body: <p>Is there an API call available which could automatically create address labels?</p>
  
  <p>This could be very handy with CiviRules, to have an automatic API-action to create address labels overnight.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-05-06T09:37:40.783Z
Comments.Text: AFAIK civi rules gets triggered on a condition, do you want to print address label for all the contact automatically or after update to address or contact for a contact?
Comments.UserDisplayName: Pradeep Nayak
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-05-08T18:03:57.030Z
Comments.Text: I am interested in how the address label creation works, and if there is an action that could easily be used both by CiviRules and FormProcessor to create both single and batches of address labels
Comments.UserDisplayName: Flying
Tags: <api><civirules><address-labels><form-processor>
Title: How can I automate printing address labels?
ThreadText: # How can I automate printing address labels?
  
  (Asked by: username_0 on 2015-10-12)
  
  Is there an API call available which could automatically create address labels?
  
  This could be very handy with CiviRules, to have an automatic API-action to create address labels overnight.
  
  **Tags:** api, civirules, address-labels, form-processor
  
  > **Comments:**
  > **username_1**: AFAIK civi rules gets triggered on a condition, do you want to print address label for all the contact automatically or after update to address or contact for a contact?  
  > **username_0**: I am interested in how the address label creation works, and if there is an action that could easily be used both by CiviRules and FormProcessor to create both single and batches of address labels  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2021-05-11. Score: 1
  
  It depends what you mean by "API". If it's a script you're going to run overnight you could do something like this and put it in a file, let's say labels.php:
  _contactIds = array(2,3,4);
  $params = array(
    'label_name' => 3475,
    'location_type_id' => NULL,
    'do_not_mail' => 1,
  );
  $form->postProcess($params);
  
  Then run the script with cv, e.g. cv scr --user=admin labels.php > output.pdf
  Or some variation of that. There's some trickiness to capturing the output within the script if you didn't want to redirect to a file - you'd either have to duplicate a lot of code or rely on something that is internally used for unit tests and could disappear.
  
  
  ---
  
  