I did manage to get the pdf from sales invoices this way:
var geturl = $"{url}companies({companyid})/salesInvoices(06921c8c-f891-ef11-8a6b-000d3add059a)/pdfDocument/pdfDocumentContent";
//read the pdf content as stream into pdf
var pdf = await httpClient.GetStreamAsync($"{geturl}");
//save the pdf to a file
var file = Path.Combine(Path.GetTempPath(), @"c:\temp\test.pdf");
using (var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None))
{
await pdf.CopyToAsync(fileStream);
}
This worked. But when I use the guid from a posted sales invoice coming from table Sales Invoice Header in stead of table Sales Header I always get a 404.
Copilot suggested using this:
GET https://api.businesscentral.dynamics.com/v2.0/{tenantId}/{environment}/api/v2.0/companies({companyid})/postedSalesInvoices({invoiceid})/pdfDocument({invoiceid})/content
But I cannot find documentation on this code, when I ask for a reference, CoPilot says there is no reference, hence he made this up.
In the documentation from Microsoft I cannot find a clue on how to get the posted sales invoice pdf. The only way possible I can think of is if the pdf was added as attachment, then I could find it perhaps, but this is not the case for me. I want to generate the invoice like the first call for sales invoices.
Is there anybody that has experience getting the pdf invoice document of a posted invoice through the API?
Thanks.