Hi,

I would like to create a new user via REST server with module Services 3.x
For the user it is mandatory to specify birthday date.

I'm sending the data as JSon:

{..., "field_fecha_nacimiento":{"und":[{"value":"Sun May 19 12:56:15 CEST 1970"}]}, ...}

Values for drupal field_fecha_nacimiento are of unix timestamp type.
I'm trying with time in millis as integer, millis as string, I tried 12/05/1980, 05/12/1980, 1980-05-12, 1980/05/12, always getting the same response:

Error 406.
Not Acceptable: The value input for field Fecha de nacimiento is invalid

How should I send a date field to a REST server in JSON format?

Comments

miqmago’s picture

Project: Date » Services
Issue summary: View changes

Adding details of the data I am sending to the server

jjemmett’s picture

Version: 7.x-2.5 » 6.x-3.1
Component: Date Field » Code

Sending this request to the correct project.

jjemmett’s picture

I am also having a problem with uploading values to CCK date fields. Please let us know how best to do this.

miqmago’s picture

I don't really know why you changed the version. In fact I use 7.x version and have this problem...

Workaround for me worked:

Send data {... "timezone":"Europe/Andorra","fecha_nacimiento":13131231..., ...}
fecha_nacimiento as long Timestamp in seconds.

In the server:

    require_once variable_get('password_inc', './includes/password.inc');
    $newuser                   = new stdClass;
    $newuser->is_new           = TRUE;
    $newuser->name             = my_module_generar_user_name($account['mail']);
    $newuser->pass             = user_hash_password($account['pass']);
    $newuser->timezone         = $account['timezone'];
    $newuser->mail             = $account['mail'];
    $newuser->init             = $account['mail'];
    $newuser->signature_format = 'filtered_html';
    $newuser->status           = TRUE;

    $fecha_nacimiento = new DateTime(null, new DateTimeZone($account['timezone']));
    $fecha_nacimiento->setTimestamp($account['fecha_nacimiento']);
    $fecha_nacimiento->setTimezone(new DateTimeZone(variable_get('date_default_timezone', 0)));

    $newuser->field_nombre[LANGUAGE_NONE][0]           = array('value' => $account['nombre'], );
    $newuser->field_apellidos[LANGUAGE_NONE][0]        = array('value' => $account['apellidos'],);
    $newuser->field_fecha_nacimiento[LANGUAGE_NONE][0] = array('value' => $fecha_nacimiento->getTimestamp(), );
    $newuser->field_geolocation[LANGUAGE_NONE][0]      = array('lat' => $account['lat'], 'lng' => $account['lng'], );
    field_attach_presave('user', $newuser);
miqmago’s picture

Take care on updating the received timestamp to the server timezone.. otw you get wrong times (not a problem with birth dates, could be worst in other cases)

ygerasimov’s picture

Status: Active » Fixed

You need to send date values how they are passed in the form. See http://drupal.org/node/1662912#comment-6193900

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Added field type in server

jagermonster’s picture

Ok well since no one actually added an example of this i decided to add an example of the array to be posted

Array ( 
  [und] => Array ( 
    [0] => Array ( 
      [value] => Array ( 
        [date] => 17 Dec 2013 
        [time] => 03:30 pm 
      ) 
      [value2] => Array ( 
        [date] => 18 Dec 2013 
        [time] => 03:30 pm 
      ) 
    ) 
  ) 
) 

JSON
"field_date": {
      "und":[
        {
          "value":{
            "date":"17 Dec 2013",
            "time":"02:45 pm"
          },
          "value2":{
            "date":"19 Dec 2013",
            "time":"02:45 pm"
          }
        }
      ]
    },
prempatel2447’s picture

Version: 6.x-3.1 » 8.x-4.x-dev
Issue summary: View changes
rahul_sankrit’s picture

Hi All,

Here I am sharing the example for JSON format of drupal 7 services, here I am using POST method to register/create a user.

Endpoint URL : http://localhost/project/api/user/register
Method : POST.
Request Header : Content-Type/application/json.
Body :

{
"name" : "your_username",
"mail" : "email_id@example.com",
"pass" :"password",
"field_first_name": {"und": [{"value": "Rahul"}]},
"field_last_name": {"und": [{"value": "Sankrit"}]},
"field_gender":{"und":"male"},
"field_custom_entity_reference": { "und": [ "2" ] },
"field_date_of_birth":{"und":[{"value":{"date":"06-14-1989"}}]},
"field_mobile_number": {"und": [{"value": "99XXXXXX12"}]}
}

Thanks