API email_invoice

Hi,

how can I send PDF as attachement by using API
curl -X POST ninja.dev/api/v1/email_invoice -H "Content-Type:application/json" -d '{"id":1}' -H "X-Ninja-Token: TOKEN"

It’s not supported. The invoice would need to first be saved through the web interface for the PDF to be cached/attached.

We’re looking into a server-side implementation of the PDF generator in a future release.

Thank you for quick response. It is interesting that user receives link where PDF is generated.

console.log('Loading a web page');
var fs = require('fs'),
    system = require('system'),
    page = require('webpage').create();

page.viewportSize = { width: 1920, height: 1080 };
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
page.settings.webSecurityEnabled = false;

var url = 'http://';
page.open(url, function (status) {
  if (status !== 'success') {
      console.log('Unable to access the network!');
  } else {

    var pdf_binary = page.evaluate(function() {
        try {
          onDownloadClick();
          return doc.output();
        } catch (err) {
          console.log("exception: " + err);
        }
    });
    fs.write('1.pdf', pdf_binary, 'b');
    phantom.exit();
  }
});

page.onConsoleMessage = function(msg) {
    //console.log(msg);
    console.debug(msg);
};

Here is workaround.

Thanks for sharing your solution!

No problem. This is phantomjs solution.

are there any changes with this topic? I created an invoice via API and send it via mail, but the pdf is not attached.

Does the test link on Settings > Email Settings work?

https://invoice-ninja.readthedocs.io/en/latest/configure.html#troubleshooting

just to be sure: everything works fine if we use the backend. This is the first time I created the invoice via API and send it directly.

If i view this invoice onetime in the browser everything works fine.

If you view the PDF in your browser the browser renders it, otherwise we use PhantomJS.