Here’s how to create a “global” Custom Field via the UI first:
And for the API to then to be able to assign it to tasks, you have to first add the Custom Field to the project (before trying to use it on tasks), as per @Matt_Bramlage’s instructions here: