I'm having a problem using some CCK form elements, such as the date picker and checkbox, with XML-RPC Services. When I create a field of that type, if I load the node then try to save it with no changes, I get a validation error. It appears that XML-RPC sends the raw value, but the code managing the field expects it to be broken up into the components and format used on the Web form.

I have reported this to the CCK folks, too. This bug report includes a detailed set of steps to reproduce: http://drupal.org/node/374558

Thanks!

Comments

scottgifford’s picture

I forgot to mention that if I change the fields to a simple date textbox and a multi-select list, everything works fine.

snelson’s picture

Status: Active » Postponed

Because the node.save process uses a drupal_execute, which is a programatic version of the node form submit, it expects the parameters to be passed in the same way as they would in a node form. Rule of thumb when trying to save nodes is to check the node form to see what its submitted data structure looks like.

Now, this is less than ideal as you should be able to do node.load and then node.save on the data that is returned, but until Drupal's data API is refined (this work is happening I believe), I don't think we have anyway around having to tweak the node before saving it.

greg.harvey’s picture

I won't change the status, but just to note there's something weird going on here with drupal_execute. I'm surprised this is the only place I can find mention of this problem, but I'm experiencing it too - not via Services, but with a straight drupal_execute in a module full of code to import data from another website.

I suspect this should be re-directed, either to core or to CCK - probably CCK. I'll expand on Scott's original post over there and re-open it, I think. =)

aaroninaustin’s picture

Version: 5.x-0.92 » 6.x-1.x-dev

What is the status of this issue? I am having the same issue in the 6.x code base, but unlike Scott, changing to a simple date select list did not fix the problem.

In my situation I'm using the date type created by datetools - and basically node.save just chokes when it encounters this. Everything thing else works just fine, I haven't tried any check boxes, just the date field.

Oddly though, I did some testing with the node_service.inc code and found that even if you change the drupal_execute() to a node_form_submit() I actually get the exact same behavior. Now I guess it could be node_form_submit is really calling drupal_execute() behind the scenes...

Not really sure where to go from here to keep debugging - if anyone can point me in the right direction that would be great.

scottgifford’s picture

@aaronmontana: I ended up writing a custom service that converts between some standard format for XML-RPC and the internal format that the nodes expect. It was pretty straightforward once I read through the Services documentation.

Good luck!

marcingy’s picture

Status: Postponed » Closed (won't fix)

As per comment in #3 this issue seems to be drupal excute itself

gweston’s picture

Would it be possible to get a sample of how to node.save with multiple checkboxes?

I can save one but can not seem to figure it out with multiple.

gweston’s picture

I got it like this

'field_services' => array(
array('value' => 'Service 1),
array('value' => 'Service 2')
),

gweston’s picture

You can add dates via node.save with

$dateofbirth = array (
'value' => '1955-05-10T00:00:00',
'timezone' => 'UTC',
'timezone_db' => 'UTC',
'date_type' => 'date',
);

then in your node build function

'field_dateofbirth' => array(0 => $dateofbirth),

stillfinder’s picture

Hello!
I have some problem with checkboxes and xmlrpc via services module. I write some application in C# and can't to send checkbox data to services. Maybe someone know in what format data must be sended?

With Date field I sending like this and all work perfect:

private static void AddArrayDateToNode(string fieldname, DateTime dt, XmlRpcStruct node)
        {
            XmlRpcStruct sMainDate = new XmlRpcStruct();
            XmlRpcStruct sDate = new XmlRpcStruct();
            sDate["year"] = dt.Year.ToString();
            sDate["month"] = dt.Month.ToString();
            sDate["day"] = dt.Day.ToString();
            sMainDate["value"] = sDate;
            object[] oDate = new object[] { sMainDate };
            node[fieldname] = oDate;
        }

So we have an array:

-		["field_exclusive_from"]	{object[1]}	
		Key	"field_exclusive_from"	object {string}
-		Value	{object[1]}	object {object[]}
-		[0]	Count = 1	object {CookComputing.XmlRpc.XmlRpcStruct}
-		["value"]	{CookComputing.XmlRpc.XmlRpcStruct}	
		Key	"value"	object {string}
-		Value	Count = 3	object {CookComputing.XmlRpc.XmlRpcStruct}
-		["month"]	"6"	
		Key	"month"	object {string}
		Value	"6"	object {string}
-		["year"]	"2011"	
		Key	"year"	object {string}
		Value	"2011"	object {string}
-		["day"]	"30"	
		Key	"day"	object {string}
		Value	"30"	object {string}

Thanks to all for any help.

stillfinder’s picture

Hi! I found solution for problems with cck fields (checkboxes and date time picker) and xml-rpc services node.save function

datetime cck field you need to send in following format:
[field_date] => Array
(
[0] => Array
(
[value] => Array
(
[year] => 2014
[month] => 7
[day] => 7
)
)
)

and CheckBoxes in this format:
[field_checkboxes] => Array
(
[value] => Array
(
[1991] => 1991
[1985] => 1985
)
)

Where 1991 is ID of taxonomy term.

If someone interested for C# code I can to send it.

Hacky’s picture

Status: Closed (won't fix) » Active

FOR JSON not worke please HELP

"field_datum_uebung":[{"0":[{"value":[{"day":"7"},{"month":"12"},{"year":"2011"},{"timezone":"Europe/Berlin"},{"timezone_db":"Europe/Berlin"},{"date_type":"date"}]}]}]}
marcingy’s picture

Status: Active » Closed (won't fix)

Please do not reopen random tickets.

beauz’s picture

I'm also having trouble saving a checkbox value via JSON, if anyone can help I have another issue here: http://drupal.org/node/1595366