Saving PDF to the file - Akamai Invoice API

In the recent weeks, I have been working on a weird problem. I could see the correct file and could save it, if I did the workflow in the Postman. But when I tried to do it in the JavaScript code, anything I tried gave me the empty file.

My first though was, that it had something to do with encoding, or with string vs. buffer, but none of the normal Nodejs things helped. Like using Buffer.from().toString() with any possible variation. I also tried to change the encoding on the file save or tried to add some headers.

I also tried to add some headers, if this will give me the data in the form, that I wanted.

I asked two of my coworkers for help. One of them then found the solution, and that was to add encoding: null option to the edge calls. So the final code sort of looked like this:

eg
  .auth({
    path: `invoicing-api/v3/contracts/${contractId}/invoices/${invoiceId}/download?fileFormat=PDF`,
    method: 'GET',
    encoding: null,
  })
  .send((error, pdfResponse) => {

There went way to many hours for the fix, that ended up with just one line of code. They have edgegrid as part of authentication. So I wish, this would be also edgegrid examples in the endpoint documentation.

Instead we get the direct endpoint calls, with comment, that authentication happens somewhere else. Having just that example, would have saved me way too much time.

I wonder if this is an Akamai specific solution, or do other API also use something like that.