I am using the Services module to add nodes from an external application.
I am using JSON via REST and everything is working fine except that I cannot seem to input dates in custom fields.

My content type has a field with type Date (Unix Timestamp).

When I use postman to get the format of the field I get the following:

"field_observation_date": {
        "und": [
                "value": "1408638600",
                "timezone": "Europe/London",
                "timezone_db": "UTC",
                "date_type": "datestamp"

So that's also exactly what I pass on when I add a new node however the value never makes it in the node. I also don' get an error.
I also did a test by adding "bla" as date value and I get the same behaviour. No error and no value in the node.

It seems like the Service module is ignoring date custom fields.
For text custom fields, it is working fine and i do get the values in the fields.

Is this a bug, known issue or am I just doing something wrong?


Sam Moore’s picture

Just a shot in the dark - I think datestamps are ints - what happens if you take the quotes out?
Like - "value": 1408638600,

Failing that, I'd ask in the Services module's issue queue.

Passero82’s picture

Thanks for the tip but it didn't make any difference.
Without the " " it is still blank...
It's strange that when I put invalid data in the field, I don't even get an error and the node gets created.
So for example I use "bla" as value and it went through but the value is blank as well...

maverick619’s picture

In case you didn't already figure it out or for people who come looking, the data you send via POST or PUT needs to be exactly how the form submits it eg:

"field_start_time": {
    "und": [
        "value": {
          "day": "17",
          "month": "9",
          "year": "2014",
          "hour": "9",
          "minute": "15",
          "ampm": "am"

It will then get go through all the hooks to turn it into whatever it needs to before entering it into the database.

Easiest way to see how it needs to be formatted is to have a block or module which uses devel's dpm to output the structure of $_POST. The structure depends on the widget you're using for the field.

My issue with dates right now is that it seems to always need something submitted even for fields which aren't required (when creating new) or already have a value which isn't changing (when updating a node). It's pretty annoying to always have to throw a dummy date in or resend a date that isn't changing.