Here is the API Documentation:
- https://docs.osticket.com/en/latest/Developer%20Documentation/API%20Docs.html
- https://docs.osticket.com/en/latest/Developer%20Documentation/API/Tickets.html
To upload files to custom fields you should be able to just use the Variable name of the field as the key and then format the data exactly as you would the regular attachments.
As far as the template issue you’ll need to look at your web server error logs and PHP error logs for a related error.
Cheers.