How can I automate printing address labels?
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 labels.php:
&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);

Then run the script with cv, e.g. cv scr --user=admin labels.php &gt; 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.