Last updated April 21, 2013. Created on October 10, 2011.
Edited by Pancho, jackbravo, Hacky. Log in to edit this page.

Example POST (D6)

<?xml version='1.0' ?>
<methodCall>
  <methodName>node.create</methodName>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>type</name>
            <value>
              <string>story</string>
            </value>
          </member>
          <member>
            <name>body</name>
            <value>
              <string>Create body input</string>
            </value>
          </member>
          <member>
            <name>title</name>
            <value>
              <string>Test title</string>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>

(For code applying to the D7 node model, see this comment)

Expected responses

Response code:

if successful:

200 OK

The body contains the nid of the new node.

if unsuccessful:

Response codes:

401 Unauthorized:
Wrong username or password.
406 Not Acceptable:
Title field required / type field is required

Testing the code on your server

  • On your endpoint make sure you enabled the XMLRPC backend and the 'node' resource including the 'create' action.
  • For unauthenticated testing, give anonymous users the permission to create 'article' nodes.
  • Using one of these tools, POST the code to your resource's URL (http://mydrupalsite/foo/node), with 'content-type' being set to 'text/xml' or 'application/xml'.
  • If you aliased the 'node' resource, both the POST URL and the <methodName> need to be adapted.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Hacky’s picture

can anyone tell what to node.update?

MiSc’s picture

I can not get the example to work - the body field is not inserted, while the title is. Something different in the structure?

// Mikke Schirén @ http://wunderkraut.com/

tilon’s picture

I'm trying to create nodes using node.create method but I received an error Access denied. In service 3.x doens't have parameter to set session or username,password, so how I can pass those parameters?

Drupal experts in Argentina! www.tilon.com.ar

isagarjadhav’s picture

XML not working in D7. D7 has different structure for body field. thats why body is not getting saved.

Co-founder, webmaffia

MiSc’s picture

Do you have av example on the structure in D7?

// Mikke Schirén @ http://wunderkraut.com/

piotrbo111’s picture

I have thesame problem. Howto create node with body ?

pretender’s picture

Same problem, can't create body. Can u please share some documentation or code?

piotrbo111’s picture

I managed to add node in c#. But only anonymous (you must turn on anonymous adding node in your Drupal) and without specified language.

Code as follow:

Drupal stuff :
public struct DrupalNode
{
public string type;
public string title;
public XmlRpcStruct body;
//public string language;
//public string uid;
// public string status;
//public string promote;
//public string comment;
}

Interface:
[XmlRpcUrl("http://test.mysite.com/services")]
public interface IServiceSystem : IXmlRpcProxy
{
[XmlRpcMethod("system.connect")]
Drupal Connect();

[XmlRpcMethod("user.login")]
// Drupal UserLogin1(string hash, string timestamp, string domain, string nonce, string sessid, string username, string password);
Drupal UserLogin(string username, string password);

[XmlRpcMethod("node.retrive")]
void NodeRetrive(int nid, string[] fields);

[XmlRpcMethod("user.logout")]
void UserLogout();

[XmlRpcMethod("node.create")]
XmlRpcStruct NodeSave(DrupalNode Node);
}

And main engine to add node:

DrupalNode node = new DrupalNode();

XmlRpcStruct innerValue = new XmlRpcStruct();
innerValue.Add("value", "body txt");

XmlRpcStruct language = new XmlRpcStruct();
language.Add("0", innerValue);

XmlRpcStruct body = new XmlRpcStruct();
body.Add("und", language);
node.body = body;
node.type = "article";
node.title = "title123421";
XmlRpcStruct responseStruct= iss.NodeSave(node);

It works for me, BUT:
no idea how to add node as logged user and in neutral language. My 'und' language (look at code) doesn't work. In database I've got empty field in language column.

This is how it looks in Drupal in admin content module:
title123421 Article Anonymous (not verified) published 01/26/2012 - 21:08 Undefined language ()

Anyone have ideas ???

Piotr

DigitalFrontiersMedia’s picture

<?xml version='1.0' ?>
<methodCall>
  <methodName>node.create</methodName>
  <params>
    <param>
      <value>
        <struct>
          <member>
            <name>type</name>
            <value>
              <string>article</string>
            </value>
          </member>
          <member>
            <name>body</name>
            <value>
              <struct>
                <member>
                  <name>und</name>
                  <value>
                    <array>
                      <data>
                        <value>
                          <struct>
                            <member>
                              <name>value</name>
                              <value>
                                <string>My test body text.</string>
                              </value>
                            </member>
                          </struct>
                        </value>
                      </data>
                    </array>
                  </value>
                </member>
              </struct>
            </value>
          </member>
          <member>
            <name>title</name>
            <value>
              <string>My test node title</string>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>

--
Web: http://digitalfrontiersmedia.com
Phone: 941.677.DFM1 ( 941.677.3361 )
Skype: DigitalFrontiersMedia
Twitter: DigitalFrontier
--

Ne0nka’s picture

Please, help.
does anybody have an example post of file.create

moisei’s picture

have you looked at http://drupal.org/node/1699354

Ne0nka’s picture

does anybody has an xmlrpc post for file.update. i use entity, and i always have that:'exception 'UuidEntityException' with message 'Trying to save a Файл entity with empty or invalid UUID.'
and i cant do field_collection_item.update. i cant reference to a host entity. i think is one of the param, am i wrong? this is my post

<?php
 
<?xml version="1.0" encoding="UTF-8"?
<
methodCall><methodName>field_collection_item.update</methodName>-<params>-<param>-<value><string>field_collection_item</string></value>-<value><string>86f2adf0-5473-4988-affa-e5e30cff4e8a</string></value>-<value>-<struct>-<member><name>uuid</name>-<value><string>86f2adf0-5473-4988-affa-e5e30cff4e8a</string></value></member>-<member><name>field_name</name>-<value><string>field_updates</string></value></member>-<member><name>host_entity</name>-<value><string>taxonomy_term</string></value></member>-<member><name>field_files_href</name>-<value>-<struct>-<member><name>und</name>-<value>-<array>-<data>-<value>-<struct>-<member><name>value</name>-<value><string>ссылка</string></value></member></struct></value></data></array></value></member></struct></value></member>-<member><name>field_files_title</name>-<value>-<struct>-<member><name>und</name>-<value>-<array>-<data>-<value>-<struct>-<member><name>value</name>-<value><string>подпись</string></value></member></struct></value></data></array></value></member></struct></value></member>-<member><name>field_files_size</name>-<value>-<struct>-<member><name>und</name>-<value>-<array>-<data>-<value>-<struct>-<member><name>value</name>-<value><string>размер</string></value></member></struct></value></data></array></value></member></struct></value></member>-<member><name>field_files_date</name>-<value>-<struct>-<member><name>und</name>-<value>-<array>-<data>-<value>-<struct>-<member><name>value</name>-<value><string>2012-12-26T00:00:00</string></value></member></struct></value></data></array></value></member></struct></value></member>-<member><name>host_entity</name>-<value><string>product_types</string></value></member></struct></value>-<value><struct/></value></param></params></methodCall>
?>