Fetch all open tickets with API key / Login

Went looking for a way to fetch all open tickets, but couldn't find any existing method.
Made one instead.
Certainly open for suggestions to make this more efficient / remove excessive code, first time working with curl in php.