Error while connecting with Zapier

I’m using Invoice Ninja hosted on my VPS server with Nginx. When I try to set up a connection with Zapier (API key and URL are correct) it connects at first but when it comes to fetching invoices it throws an error:

Bargle. We hit an error fetching an invoice.
Unexpected token  in JSON at position 0. This is likely a problem with the app. Please contact support at contact@zapier.com
I contacted Zapier and they said:

“It looks like when we made a request to […url redacted…] we got this back: [\n {\n “account_key”: “TCI8JiFyWsIYVmWOpATSYvr6FwuoXcDZ”,\n “is_owner”: true.”

These three characters at the beginning () seem to be throwing Zapier off.

I researched quite a bit and tried to debug this on my own for about 2 hours. Looks like these characters are BOM markers used in UTF-8. I tried changing my server’s encoding to something else, to no avail. Tried some PHP and Nginx settings, and also temporarily switched to Apache, also to no avail. Ran CURL on the above URL, saved the result to a file and opened it on Notepad++, which correctly told me that the file was encoded as UTF-8 without BOM.

Any ideas on what might be going on? I understand this might be something on my server, and I’m comfortable changing settings, but I’m out of ideas for now.

Sorry, this is the first time I’ve heard of this problem.

Which PHP file actually sends the output of the API when requested?

I saw a simple script on StackExchange that would forcibly remove those characters, but I looked around Invoice Ninja files and couldn’t figure out which one of them did this (not very familiar with how Laravel works).

Also, is Zapier working correctly with the hosted version of Invoice Ninja? If it is, then it’s definitely something on my server.

https://github.com/invoiceninja/invoiceninja/blob/master/app/Http/Controllers/BaseAPIController.php

Zapier is working with the hosted version (which is running v4.4).