Skip to content
← Back to activity

Solution skill

Asana bad request when attempting to set custom field values (API)

Version 2Sign in to save

Complete solution

[RESOLVED] As suspected the issue had to do with the way in which I was formatting my request. For reasons I am not clear on the additional level created by the nested custom_fields dictionary was not being formatted in correct JSON format. I was able to resolve this using requests JSON parameter. ``` def postTaskToAsana(taskName, taskURL, taskCreated, taskCompleted, taskDue): token [your value] bearerToken [your value] " + token header = { "Authorization" : bearerToken } opt Use when hitting th

TL;DR

[RESOLVED] As suspected the issue had to do with the way in which I was formatting my request. For reasons I am not clear on the additional level created by the nested custom_fields dictionary was not being formatted in correct JSON format.

[RESOLVED] As suspected the issue had to do with the way in which I was formatting my request. For reasons I am not clear on the additional level created by the nested customfields dictionary was not being formatted in correct JSON format. I was able to resolve this using requests JSON parameter. ``` def postTaskToAsana(taskName, taskURL, taskCreated, taskCompleted, taskDue): token [your value] bearerToken [your value] " + token header = { "Authorization" : bearerToken } options = { "data" : { "projects" : ["123412341234"], "name" : "Review Task: " + taskName, "notes" : "Please review this task for where the process failed.\nTask: " + taskURL, "assignee" : "123412341234", "followers" : ["123412341234"], "customfields" : { "123412341234" : taskCreated, "123412342134" : taskDue, "123412341234" : taskCompleted } } } url = "https://app.asana.com/api/1.0/tasks" r = requests.post(url, headers=header, json=options) return r ```

Context: Stack Overflow question (score 2, has accepted answer): I am attempting to create a new task using the Asana API with https://app.asana.com/api/1.0/tasks endpoint. I have been successful in creating some test tasks in the desired project. However I am now trying to also set the values of the custom fields and seem to be hitting a road block. I am using the Python request library. I have a feeling this is an issue with the way I have formatted the post. I have checked a number of sources, including here, as well tinkered and modified the way in which I structure the "options" dictionary. However it does not seem to help. ``` def postTaskToAsana(taskName, taskURL, taskCreated, taskCompleted, taskDue): token [your value] bearerToken [your value] " + token header = { "Authorization" : bearerToken } options = { "projects" : ["234234234"

When to use

  • You hit this exact issue.
  • The symptom matches: Asana bad request when attempting to set custom field values (API).

When NOT to use

  • A different error or symptom; the cause here is specific to this one.

Compatibility

Per the linked source (mentions 1.0).

Edge cases

  • If your error message differs even slightly, this is probably a different issue; search the exact text.
  • If the fix does not help, capture the full error output and check the source link for updates.

Evidence

Stack Overflow question (score 2, has accepted answer): I am attempting to create a new task using the Asana API with https://app.asana.com/api/1.0/tasks endpoint. I have been successful in creating some test tasks in the desired project. However I am now trying to also set the values of the custom fields and seem to be hitting a road block. I am using the Python request library. I have a feeling this is an issue with the way I have formatted the post. I have checked a number of sources, including here, as well tinkered and modified the way in which I structure the "options" dictionary. However it does not seem to help. `` def postTaskToAsana(taskName, taskURL, taskCreated, taskCompleted, taskDue): token [your value] bearerToken [your value] " + token header = { "Authorization" : bearerToken } options = { "projects" : ["234234234" Resolved: [RESOLVED] As suspected the issue had to do with the way in which I was formatting my request. For reasons I am not clear on the additional level created by the nested custom_fields dictionary was not being formatted in correct JSON format. I was able to resolve this using requests JSON parameter. `` def postTaskToAsana(taskName, taskURL, taskCreated, taskCompleted, taskDue): token [your value] bearerToken [your value] " + token header = { "Authorization" : bearerToken } options = { "data" : { "projects" : ["123412341234"], "name" : "Review Task: " + taskName, "notes" : "Please review this task for where the process failed.\nTask: " + taskURL, "assignee" : "123412341234", "followers" : ["123412341234"], "custom_fields" : { "123412341234" : taskCreated, "123412342134" : taskDue, "123412341 Source: https://stackoverflow.com/questions/48575235/asana-bad-request-when-attempting-to-set-custom-field-values-api

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_lBc890MUR1SEKYdX6ZZ4UA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Asana bad request when attempting to set custom field values (API) <span>— Vectle</span></a>