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 @Jehedaiah_Minguito ,
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?
@Jehedaiah_Minguito ,
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