Example POST

<?xml version="1.0"?>
<methodCall>
   <methodName>user.register</methodName>
   <params>
     <param>
       <struct>
         <member>
           <name>name</name>
           <value><string>username</string></value>
         </member>
         <member>
           <name>mail</name>
           <value><string>example@example.com</string></value>
         </member>
         <member>
           <name>pass</name>
           <value><string>password</string></value>
         </member>
       </struct>
     </param>
   </params>
</methodCall>

If you want to add roles upon creation, add this in the same request:

  <member>
           <name>roles</name>
            <array>
           <data>
           <value><i4>4</i4></value>
         </data>
         </array>
         </member>

Expected responses

if successful:

200 OK

The body contains the newly created uid.

if unsuccessful:

Response codes:

406 Not Acceptable:
The name is already taken.
406 Not Acceptable:
The email address is already registered.
406 Not Acceptable:
The email address example@example.com is not valid.

Testing the code on your server

  • On your endpoint make sure you enabled the XMLRPC backend and the 'user' resource including the 'register' action.
  • Using one of these tools, POST the code to your resource's URL (http://mydrupalsite/foo/user), with 'content-type' being set to 'text/xml' or 'application/xml'.
  • In case you aliased the 'user' resource, both the POST URL and the <methodName> need to be adapted.
  • As both username and email address are unique, in order to repeat the test, you need to replace these values in the POST code by other test values.

Comments

Darren Shelley’s picture

Whilst we already have an example for user.login which highlights how to call an xmlrpc end point with multiple string values. User.register proved to be a more difficult implementation, requiring the use of xmlrpc structs to create a keyed array, in this case mimicking a user object.

Hacky’s picture

Have you a example how the node.update works ? The node.create worke fine @ my code. But node.update not: missing argument node ... xmrpc example for struct node.update would be nice.

dianacastillo’s picture

Here is an example of user.update, I suppose the format for node.update must be the same :

<?xml version="1.0"?>
<methodCall>
   <methodName>user.update</methodName>
   <params>
     <param>
       <struct>
         <member>
           <name>uid</name>
           <value><int>38</int></value>
         </member>
      </struct>
  <struct>
  <member>
           <name>name</name>
           <value><string>diana.ruiz12</string></value>
         </member>
         <member>
           <name>mail</name>
           <value><string>ndy.r@eeuwkern.org</string></value>
         </member>
         <member>
           <name>pass</name>
           <value><string>candy9223</string></value>
         </member>
      
       </struct>
     </param>
   </params>
</methodCall>

Diana Castillo

dianacastillo’s picture

Can you please add an example of how to include the roles in this xml for user create? thank you.

Diana Castillo

dianacastillo’s picture

figured it out, here is an example

<?xml version="1.0"?>
<methodCall>
   <methodName>user.register</methodName>
   <params>
     <param>
       <struct>
         <member>
           <name>name</name>
           <value><string>diana.ruiz12</string></value>
         </member>
         <member>
           <name>mail</name>
           <value><string>ndy.r@eeuwkern.org</string></value>
         </member>
         <member>
           <name>pass</name>
           <value><string>candy9223</string></value>
         </member>
       <member>
           <name>uid</name>
           <value><int>12930</int></value>
         </member>
    <member>
           <name>roles</name>
            <array>
           <data>
           <value><i4>4</i4></value>
         </data>
         </array>
         </member>
<member>
           <name>status</name>
           <value><int>1</int></value>
         </member>
       </struct>
     </param>
   </params>
</methodCall>

Diana Castillo

servantleader’s picture

What content type should be specified for this to work?

dugcodes’s picture

Does not work, always returns a (406) Not Acceptable
error, is there a setting in admin that needs to be in place that I am missing??

Has anyone else had this problem also??
Any help/advice is much appreciated..

jacobisreal’s picture

How would you add Profile2 fields to the registration in this example, or does this have to be done after the user is created? I have a service that calls my XMLRPC to create a user and complete his Profile2 fields fname, lname, secret_question, secret_answer, and ZID.

I need these fields to be entered when the user is created programatically. Can you please?

I also need to know how to access the Profile2 fields when creating the user element to register.

Jacob

dianacastillo’s picture

i want to create users but not let drupal assign the uid, I will send it , i tried this: but it ignores the uid and automatically creates the next available one. How can I avoid this? thanks, diana

<?xml version="1.0"?>
<methodCall>
   <methodName>user.register</methodName>
   <params>
     <param>
       <struct>
         <member>
           <name>name</name>
           <value><string>candy.ruiz12</string></value>
         </member>
         <member>
           <name>mail</name>
           <value><string>candy.r@eeuwkern.org</string></value>
         </member>
         <member>
           <name>pass</name>
           <value><string>candy9223</string></value>
         </member>
       <member>
           <name>uid</name>
           <value><string>12930</string></value>
         </member>
       </struct>
     </param>
   </params>
</methodCall>

Diana Castillo

jerryoh’s picture

Hello, I am new to Drupal.
I have tried to follow the instruction couple of days but I could not make it.

> On your endpoint make sure you enabled the XMLRPC backend

(Q1) I have "XMLRPC Server" enabled in Admin>Modules. Is it enough?
Or should I do something in Admin>Structure>Services ?

> and the 'user' resource including the 'register' action.

(Q2) I checked 'register' action under 'user' from Admin>Structure>Services>Resources
Is it correct?

•Using one of these tools, POST the code to your resource's URL (http://mydrupalsite/foo/user), with 'content-type' being set to 'text/xml' or 'application/xml'.

(Q3) I have a difficulty to figure out 'resource's URL'. I didn't change my default URL.
I tried different URLs and result is shown below:
(case 1) www.mysite.com/?q=user ---> registration didn't happen. STATUS 200 OK
(case 2) www.mysite.com/user. ---> internal server error STATUS 500 Internal Server Error
(case 3) www.mysite.com/ ---> registration didn't happen. STATUS 200 OK (same as case 1)

Do you know any video tutorial or screen shot or slide to show the procedure step-by-step?
Any help will be great!
Thanks