node.save and taxonomy

Events happening in the community are now at Drupal community events on www.drupal.org.
jamestraynor's picture

Hi,

I am trying to setup a link between a non-drupal site and a drupal 6.14. I am using xmlrpc to post pages to drupal. This is working fine for items such as title,body etc. but I need to also select taxonomy. The code is php and based on http://groups.drupal.org/node/27482 and all the taxonomy items are already setup on the site, I just need to link them into the node.save call. I have tried all the various possibilities of array, structs by name or by tid and none of them seem to work. I have searched for any examples but have come up blank. Could someone point me in the right direction.

The taxonomy is of the multipleselect but not tags variety and the services version is 6.x-2.x-dev if that makes any difference.

Thanks

James

Comments

the structure of the taxonomy

Methos76's picture

the structure of the taxonomy array in a node is kind of the following :

$node['taxonomy'][$vid][]=$tid;

You will have to xmlrpcval all of your values, which is something where I can't help you.

For a similar project i used Zend-Framework to do the data transfer to webservice, which is much handier than putting the XMLRPC code together by hand

Hope that helps a bit.

how would it look?

djschoone's picture

How would the code look if all the values have the xmlrpcval? I'm not able to get it figured out.

subscribe

sanjith's picture

james-

I am on the same page.

How to update taxonomy tag name in node, using xmlrpc-services
If you know any solutions suggest me...

-SVN

I'm not familiar with xmlrpc

waldmanm's picture

I'm not familiar with xmlrpc implementation, but as far as taxonomy terms, you need to know that the structure returned from node.get is not what node.save expects as input (because it calls drupal_execute() to save the node. See http://drupal.org/node/275045 for a bit more info, especially comments by heyrocker, the maintainer.

Here are some comments from a function I use to convert a node's taxonomy array (as returned from noad_load()) into what node.save expects. The function is in Flash, so won't help much, but the comment is useful, I hope:

     * transform 'taxonomy' into what Drupal expects on node save.
     * Typically, a req's 'taxonomy' is an array of TaxonomyTerm's indexed by tid (this is what Drupal returns).
     * However, the node.save method expects a two-layer array (array of arrays), where the first array is
     * indexed by vid, and for each vid there is an array of that vocabulary's terms (indexed by tid). 
     * An exception is those taxonomies which are free-tagging ('tags'). These are all contained as the 
     * value of the master array item with a key of 'tags' (i.e., one more level of nesting). This value is 
     * an array indexed by vid's with each vid having as a value a string containing a list of comma-separated
     * tag names.
     * Note that all vocabularies must be included in this array, even those that don't have any terms 
     * associated with this node, so as to remove the last term in a vocabulary if needed (indicate an empty
     * vocabulary).    

Thanks for you comments

sanjith's picture

I will check and reply back

multi dimensional array using xmlrpc

sanjith's picture

Hi,

Hi,

Finally I created my own set of method using node services to solve the problem!

Any one suggest a better way for handling multi dimensional array using xmlrpc via services module.

using node.save, I could not save the node with taxonomy tags !

So I written my own method to catch the node object and taxonomy terms and joined as needed for node_save.

But this is not the correct way I think ...

I want to pass a array(array) using xmlrpc and need to get and access in hook_services() ?

Thanks in Advance,
SVN

solution

sanjith's picture

serialized the array and pass to the hook_services().
hook_services() catch the serialized array and perform unserialize.

-SVN

Services

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: