Services API Documentation

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

node.save

I had a very tough time finding what arguments were required by node.save... I finally guessed that a new node needed a "created" timestamp argument. Where should I post the following?

For new node creation be sure to set the creation time of the node:

var my_date:Date = new Date();
nodeObject.created = my_date.getTime();

and for editing existing nodes, be sure to set the changed time of the node:
var my_date:Date = new Date();
nodeObject.changed = my_date.getTime()

drupal 6 will complain if these arguments are not supplied. I used a simple if statement to handle both:
          public function nodeSave():void{

              var nodeObject:Object = new Object();
              var my_date:Date = new Date();
             nodeObject.type = "page";
                nodeObject.nid = nid.text; // set to zero to create new node
               nodeObject.title = title.text;
             nodeObject.body = body.text;           
               if (nodeObject.nid == 0) {
                 nodeObject.created = my_date.getTime();
                } else {
                   nodeObject.changed = my_date.getTime();
                }
             
               node.save(nodeObject);

            }

If the NID is 0, then a new node will be created. Hope this helps, I didn't know where else to post this. Any feedback would be greatly appreciated.

Thanks,

-Casey

Comments

Your post is greatly

Fixdit's picture

Your post is greatly appreciated over here :)

I cant get it to work

jomesili's picture

I am having a hard time saving a node because of nodeObject.created field, i am using D6 and Flex 3 AMFPHP
public function saveNode():void{

var my_date:Date = new Date();
    var nodeObject:Object = new Object();
nodeObject.type = "offencesheet";
    nodeObject.nid = 0; // set to zero to create new node
    if (nodeObject.nid == 0) {
     nodeObject.created = my_date.getTime();
    } else {
       nodeObject.changed = my_date.getTime();
    }
    nodeObject.title = field_formnumber.text;
    nodeObject.body = field_formnumber.text;
    nodeObject.field_address= [{value:field_address.text}];

node.save(nodeObject);

when is used the node.submit there was an error message saying node.submit does not exist

How do we rattle this?

Services

Group organizers

Group categories

Group notifications

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

Hot content this week