Create a task with an existing custom Field

Hmm, it certainly seems to be on the project!

I can’t imagine this would be related but one thing to point out - when you use html_notes, you must always wrap it in a <body></body> tag set.

In fact it is wrapped but the forum interprets it too haha
Without the “custom_fields”: {…} it works perfectly

Ok I finally got it.

I was sending this Json:
{
“data”: {
“custom_fields”:{
“1181175364270501”: “test”
},
“name”: “Buy catnip”,
“project”: “1181175364270497”,
“resource_subtype”: “default_task”,
“workspace”: “17325551900806”
}
}

where I specified the line “project” but because I don’t specify it also in the “memberships” secton, the tasks I created with postman where not attached to my project, and so it didn’t find the field.
I just don’t really get what is the use of the “project” field if we need to fill the section “memberships” too

Oh wait, sorry I missed this earlier: there is no field project on a task object; the field is projects.

1 Like

Hello,

Similar issue. I’ve read some post in this forum to search for an answer but I didn’t find anything that solve the creating task with custom Field.

Here is what I did

import os
import asana

token = os.getenv("ASANA_TOKEN")
client = asana.Client.access_token(token)
workspaces = client.workspaces.get_workspaces()
for workspace in workspaces:
  print(workspace)

WORKSPACE_GID = "__FROM_THE_PREVIOUS_PRINT__"

projects = client.projects.get_projects_for_workspace(WORKSPACE_GID)
for project in projects:
  print(project)

PROJECT_GID = "__FROM_THE_PREVIOUS_PRINT__"

custom_fields = client.custom_fields.get_custom_fields_for_workspace(WORKSPACE_GID)
for custom_field in custom_fields:
  print(custom_field)


FIELD_NAME_GID = "__FROM_THE_PREVIOUS_PRINT__"
FIELD_ENUM_GID = "__FROM_THE_PREVIOUS_PRINT__"

task_custom_field = {}
task_custom_field[FIELD_NAME_GID] = FIELD_ENUM_GID

data = {
    "workspace": WORKSPACE_GID,
    "projects": [PROJECT_GID],
    "custom_fields": task_custom_field,
    "name": "Test"
}

client.tasks.create_task(data)

Invalid Request: Custom field with ID __ is not on given object

I don’t know what is wrong in what I am doing. CustomField is enum. Also, without the custom_fields in data, the task is created.

Can you help me? Maybe you have an idea of what could be wrong.

Thank you in advance!

Hi @sovanna and welcome to the forum!

I have two possible theories as to your issue. The first is, I’m kind of doubtful that the exact format for custom fields you end up with inside your data structure is correct. But I can’t tell since it’s being built in the task_custom_field array.

Can you post exactly what data looks like - the exact contents of that string - right before the client.tasks.create_task(data) call? Then we can see the exact format of what you’re sending.

If that line of analysis doesn’t work out, we’ll move onto another possibility. But I’m betting the above is the problem.

Hi Phil, sorry for my late response.

The task_custom_field is a python dict structure
When I do print(data), it looks like:

{'workspace': '811706066050666', 'projects': ['1201373587372433'], 'custom_fields': {'1201373293611759': '1201373293611760', '1201373292789783': '1201373292789786'}, 'name': 'Test'}

Offhand that looks right the correct format.

So my second hunch is that one or both of the custom fields you’re trying to add does not exist in the project’s custom_field_settings. You can only add custom fields to a project where the fields exist in the project.

Thank you so much Phil!
it was actually the custom_field_settings from the project.

Thank you again!

Generally speaking, it’s a bit confusing, Asana should clear things on the documentation…
We can get the custom_field of the workspace witch could be the same for a project.
But the IDs are completely different and values are the same.

Moreover, to create a task with custom field, it just says “custom field”, so you will look for custom_field.
There is no way to thing about “look for custom_field_settings”…

Anyways, it’s weird but I happy you were here to help! Thanks again !

2 Likes