create a task via curl

I am trying to create a task via curl and it is coming back with the rejection of “unrecognized workspace”, and following the ASANA manual also from error.
I was wondering if you could explain me step by step to create a task via curl please.

Following is the command I am trying to execute:

curl -H “Authorization: Bearer 0 / xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx” https://app.asana.com/api/1.0/tasks?"workspace=xxxxxxxxxxxxxx&project=xxxxxxxxxxxxxxxx "

I suppose there’s no double quote in the middle of your original url?
Also, you add to send a “POST”, by default curl do a “get”.
That’s a sample of using curl to POST JSON data that should help.

Good Morning,
Many thanks for the return Frederic_Malenfant
but in the example you gave me, it’s with JSON file, and the test we’re doing doesn’t use this file, it’s directly from cURL.
Example of how I accessed my account:
curl -H “Authorization: Bearer x / xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx” https://app.asana.com/api/1.0/users/me

Now I would like to know how to create a task directly by cURL without the JSON file please.

No, it’s with json “string” on the command-line using curl. You must use json syntax to send “post” data to asana, but curl allow sending json data by configuring the header “content-type”, then use the -data paramater with your valid json string after. You don’t need a “file”.

Example

curl -X POST https://app.asana.com/api/1.0/tasks 
-H 'Authorization: Bearer xxx' 
-H 'Content-Type: application/json' 
-data '{"data": {"name": "Buy catnip", "assignee": "12345", ... }}'
1 Like