Hello,
Good Day. Kindly help.
My goal is to update date custom field of a specific task.
I sent put request: https://app.asana.com/api/1.0/tasks/{task_gid}
{
"data": {
"custom_fields": {
"12032479587XXXX": {
"date_value": {
"date": "2022-11-18"
}
}
},
"workspace": "XXXXXX"
}
}
But I encountered error: “date_value: DayAndDateTime should have exactly one of: date, date_time”
I have tried including both date and date_time but still the same error.
{
"data": {
"custom_fields": {
"120324795XXXXX": {
"date_value": {
"date": "2022-11-18",
"date_time": null
}
}
},
"workspace": "XXXXXX"
}
}
1 Like
Hi @anon26434489 ,
I know it goes against what the error message says, but try setting both - set date
formatted as just the date portion, and set date_time
to the date formatted as a full date-time value.
Hello @Phil_Seeman !
I already tried including both date and date_time but still the same error.
Did you format them exactly as I mentioned?
Example:
"date_value": {
"date": "2022-08-05",
"date_time": "2022-08-05T14:30:00.000Z"
},
Hello @Phil_Seeman . Yes, I have tried including both date and date_time (Code#1). I also tried if only date_time (Code#2). Both cases unfortunately encountered the same error.
Code#1
{
"data": {
"custom_fields": {
"12031552XXXXXX": {
"date_value": {
"date": "2022-10-27",
"date_time": "2022-10-27T03:40:23.771Z"
}
}
},
"workspace": "XXXXXX"
}
}
Code#2
{
"data": {
"custom_fields": {
"12031552XXXXXX": {
"date_value": {
"date_time": "2022-10-27T03:42:32.683Z"
}
}
},
"workspace": "1180352XXXXXX"
}
}
Possibly unrelated, by why do you give the workspace gid as well?
@anon26434489 ,
Sorry I gave you the wrong syntax; here’s the right one:
Wanted to share since I hadn’t seen this anywhere yet. For the new Date custom field type, when reading a date value via the API you receive
“date_value”: {
“date”: “2022-08-18”,
“date_time”: null
}
For a date. If the value was a datetime, then you would have “date”:null and “date_time” would have an appropriate value.
When updating a custom field in a task, instead of simply specifying the value for the field as “2022-08-18” like you might for a text field, you have to pass an object with…
So to update a date custom field, the call would look something like:
“custom_fields”: {
“4578152156”: {“date”:“2022-08-18”}
},
2 Likes
Thank you, that was extremely helpful. I didn’t the reference to custom fields in the API docs and wasn’t sure how to populate a date field. Life saver!
1 Like
This solution is still giving me the same error “Could not parse request data, invalid JSON”.
Does this look correct?
{
“data”: {
“custom_fields”: {
“1203375592841130”: {“date”:“2023-08-11”},
“1203571454482797”: {“date”:"2023-08-18”}
}
}
}
That does look right, @anon3121589 .
Are you sure you have the body content type set to “application/json”?
Thanks for your reply @Phil_Seeman
Yes, content type is set correctly.
@anon3121589 did you ever have any luck? I’ve tried all kinds of JSON formatting but my custom date field is just not happy!!
@Adam_Ennis ,
That’s the right format for a custom date field. What’s the exact error message you’re getting? (Are you sure it’s related to the date field?)
Thanks, @Phil_Seeman . Looks like it was a coincidence that I swapped out my test record at the same time I added my date field and assumed the latter was the problem. Looks like it was the html_body all along, as the new test record has embedded line breaks, which are causing the JSON parsing error. But the date field is working great!
Glad you solved that one, @Adam_Ennis !
FYI you should be able to include line breaks by using \n