Read/Write Date custom field

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 either (but not both) a “date” key or a “date_time” key. These dates then follow the same formatting as due_on and due_at.

So to update a date custom field, the call would look something like:
“custom_fields”: {
“4578152156”: {“date”:“2022-08-18”}
},

I didn’t see this in the API docs yet and I didn’t find it when trying to search the forums.

If you use the wrong format, the API returns an error saying your object isn’t formatted correctly or that it was expecting an object, but it took a little trial and error to get it right. Hope this helps someone else.

6 Likes

Just ran into this issue, thank you so much!

1 Like

Excellent post, @Anthony_Tamalonis, thank you! I discovered this a week or two ago and should have posted here but didn’t - but you did the right thing! :clap:

1 Like

Thanks for sharing!

1 Like

Thanks for pointing this out. I think the API documentation should have a place where we can request updates to the documentation…

2 Likes

This is always done through forum posts :slight_smile:

1 Like

Does anyone know if this has changed?

“custom_fields”: {
“4578152156”: {“date”:“2022-08-18”}
},

I just tried doing this myself and i keep getting the incorrectly formatted error :frowning:

Further update: here’s a copy of the code i’m trying. The first custom field works… but the date doesn’t. Any ideas?

{
  "data": {
    "external": {
      "gid": "1204528349157612",
      "name": "Update: Store Closure Request",
	  "due_on": "2023-04-03"
    },
    "custom_fields": {
        "1203979628051359":"1203979628051360",
	"1204092771972125": {“date”:“2022-08-18”},
		}
	}

If you try just the date field, so you get an error message return; if so, what does it say?

I did manage to get it work. The placeholder is a ZD placeholder. which renders the date in this format: 2022-08-18. NFI why my original wouldn’t work.

“1204092771972125”: {
“date”: “{{ticket.ticket_field_16090500513433}}”
}

Thanks everyone. :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.