You can, like you could on the website, also send an invoice, quote, cash register ticket, order form or delivery note by email to the customer through the API.


To do this, use the POST method with, for example, /api/v1/invoices/1001?send_mail as a URL.


You do have to provide some additional information (in XML, JSON or form-encoding):


  • recipient (text): E-mail address or contact_id of the customer to which the e-mail is sent. Can also be specified: 'myself' (yourself in copy), 'main_contact' (general address of the customer), 'first_contact' (general address or other available e-mail address), 'all_contacts' (all available e-mail addresses). It is also possible to specify a space separated list of previous values.

  • recipients (list): List of recipient values (see above).

  • subject (text): The subject of the email. If not specified, the default subject will be used (see Settings of your account).

  • message (text): The text content of the email. If not specified, the default email content will be used (see Settings of your account). Alternatively, 'message_html' field can be specified.

  • message_html (html): The text content of the email. If not specified, the default email content will be used (see Settings of your account). Alternatively, 'message' field can be specified.

  • document_type: Type of document. Only applicable when sending an invoice. Can contain the following values: 'pdf', 'ubl', 'both' (= pdf + ubl), 'duplicate' (= duplicate invoice in pdf), 'reminder', 'reminder_summary' (= summary document reminder). If not specified, 'pdf' is used.

  • attachments (list): Optionally a list of attachments (see below).

You must provide at least 1 recipient with an application. Giving yourself up as a recipient is enough. A combination of different fields of recipients is possible.



An example in XML to pass on your data:

<data>
  <recipients>
    <recipient>customer1@hisdomain.com</recipient>
    <recipient>123548</recipient>
    <recipient>myself</recipient>
  </recipients>
  <message>Beste,
In bijlage vindt u uw factuur terug.</message>
  <attachments>
      <attachment>
          <upload_id>a9c4c541-33fc-4c34-894b-fcd091d45fc9</upload_id>
          <filename>Mijn Bijlage.docx</filename>
      </attachment>
  </attachments>
</data>

or

<data>
  <recipient>customer1@hisdomain.com 123548 myself</recipient>
  <message>Beste,
In bijlage vindt u uw factuur terug.</message>
</data>

An example in PHP how you can send an invoice via email:

$email = 'luc@mymail.com';
$password = '123456';
 
$post = array();
$post['recipient'] = "customer@hisdomain.com myself";
$post['message'] = "Beste,\\nIn bijlage vindt u uw factuur terug.";
 
$p = curl_init('https://app.simplybooks.be/api/v1/invoices/1001?send_mail');
curl_setopt($p, CURLOPT_USERPWD, $email . ':' . $password);
curl_setopt($p, CURLOPT_POSTFIELDS, $post);
curl_setopt($p, CURLOPT_RETURNTRANSFER, TRUE);
$result_in_xml_string = curl_exec($p);



Add attachments while sending e-mail (POST) via API

While sending an invoice or quotation by e-mail, you can also add additional attachments.


To do this, use the POST method with https://api.simplybooks.be/api/v1/uploads URL.


Send the file as form-data with 'file' as the key. The file size must not exceed 5MB. You can add multiple files at once by using 'file[]'. Optionally, you can also enter a file name along key 'filename'.


In response, you will receive a list of per uploaded file:


  • upload_id: You use this when sending the e-mail (argument attachments)
  • filename: Passed file name (however, this is not tracked and you have to pass it on again during forwarding the attachment by e-mail).
  • available_until: Validity period during which the file remains available (up to 1 hour after uploading the file).