XML-RPC methods/struct to create new node question
I'm trying to create a simple c# app that logs into my drupal site and creates a node, doesn't need to be secure or fancy.
[XmlRpcMissingMapping(MappingAction.Ignore)]
public struct DrupalUser
{
// Fields
public string name;
public string email;
}
[XmlRpcMissingMapping(MappingAction.Ignore)]
public struct Drupal
{
public string sessionid;
public DrupalUser user;
}
public struct DrupalNode
{
public string type;
public string nid;
public string title;
public string body;
}
[XmlRpcUrl("http://mysite.com/services/xmlrpc")]
public interface IServiceSystem : IXmlRpcProxy
{
[XmlRpcMethod("system.connect")]
Drupal Connect();
[XmlRpcMethod("user.login")]
Drupal Login(string username, string password);
[XmlRpcMethod("node.save")]
Drupal Save(DrupalNode Node);
}
/// <summary>
/// Enter App
/// </summary>
[STAThread]
static void Main(string[] args)
{
IServiceSystem iss = XmlRpcProxyGen.Create<IServiceSystem>();
Console.WriteLine(iss.Connect());
iss.Login("username", password");
DrupalNode Node;
Node.type = "story";
Node.nid = "1";
Node.title = "Test";
Node.body = "Test";
iss.Save(Node);
Console.ReadLine();
}What is incorrect about my struct or permissions or method to create a new story? I get an access denied error on the iss.Save();
Groups:
Login to post comments
Hello, three things came up
Hello,
three things came up to my mind concerning your problem
System.connect returns a sessionid whitch is needed by the user.login as a kind of authentication
user.login itself returns a new sessionid for the user you loged in. This session id you will need for every command you send
to Drupal.
I write this cause i realy don't know wether c# does this things in background or not.
given node.id
Maybe one of that helps.
Greeting
Methos
Thanks methos, I removed the
Thanks methos,
I removed the requirement for using sessionIDs, they are not required (nor are API keys at this point). I was using the connect command on the line before to verify the connection, I cleaned it up a bit.
Now I'm getting a "use of unassigned local variable Node" error before the build.
[XmlRpcMissingMapping(MappingAction.Ignore)]
public struct DrupalUser
{
public string name;
public string email;
}
[XmlRpcMissingMapping(MappingAction.Ignore)]
public struct Drupal
{
public string sessionid;
public DrupalUser user;
}
[XmlRpcMissingMapping(MappingAction.Ignore)]
public struct DrupalNode
{
public string type;
public string nid;
public string title;
public string body;
}
[XmlRpcUrl("http://mysite.com/services/xmlrpc")]
public interface IServiceSystem : IXmlRpcProxy
{
[XmlRpcMethod("system.connect")]
Drupal Connect();
[XmlRpcMethod("user.login")]
Drupal Login(string username, string password);
[XmlRpcMethod("node.save")]
Drupal Save(DrupalNode Node);
}
/// <summary>
/// Enter App
/// </summary>
[STAThread]
static void Main(string[] args)
{
IServiceSystem iss = XmlRpcProxyGen.Create<IServiceSystem>();
Drupal cnct = iss.Connect();
iss.Login("username", "pass");
DrupalNode Node;
Node.type = "story";
Node.title = "Test";
Node.body = "Test";
iss.Save(Node);
Console.ReadLine();
}
Thats more an c# problem
Thats more an c# problem ;)
you defined Node to be a DrupalNode, but you didn't initiate the struct (completely) before using it.
Try to remove the line public string nid; for testing purposes or initialize nid with 0 (zero).
btw nid is expected to be an integer not a string, i think this will cause problems generating the XML representation send to the server by your program.
hope that thelps.
I could only google your error message, cause i do not code in c#
Haha, yeah Visual Studio
Haha, yeah Visual Studio isn't being so kind to me this morning.
What sort of permissions or access do I need to grant? I am getting an [1] Access denied. run-time exception when attempting to call the Save command?
Thanks again!
Zak
that depends on what actions
that depends on what actions you want to perform through the webservices.
In your case i think permissions to create a node of type story should be enough.
If it doesn't work, you should try to access the webservice with your admin-user.
If this doesn't work at all, the problem is some where else than the permission to save a node of that type
The problem is definitely
The problem is definitely somewhere else than the permissions. I did it in two different versions of Drupal and gave full permissions to everything and was able to post from the site. But not the program. I might be making the code too simplistic? Am I forgetting something?
Any solution?
Hello,
did you manage to solve this issue? I have the same problem but with Java.
I can execute all (read-methods) but saving a node does not work either.
Same thing here...
udo.
Suggestions
Fellow Drupallers,
See http://drupal.org/node/585014 for an example of node.save with XML-RPC. I created a role of "Web Service" for the import user, and the permissions for the role are as follows. I probably don't even need as many permissions as listed here, but this is verified working.
content_permissions module (really just all checked)
edit field_byline
edit field_category
edit field_docid
edit field_expiredate
edit field_filename
edit field_overline
edit field_positionrank
edit field_positionsection
edit field_positionsequence
edit field_publication
edit field_section
edit field_sectionname
edit field_subhead
view field_byline
view field_category
view field_docid
view field_expiredate
view field_filename
view field_overline
view field_positionrank
view field_positionsection
view field_positionsequence
view field_publication
view field_section
view field_sectionname
view field_subhead
node module (again, all checked)
access content
administer content types
administer nodes
create event content
create page content
create story content
delete any event content
delete any page content
delete any story content
delete own event content
delete own page content
delete own story content
delete revisions
edit any event content
edit any page content
edit any story content
edit own event content
edit own page content
edit own story content
revert revisions
view revisions
node_service module
load node data
path module (not sure if this is necessary, but pathauto works when importing)
administer url aliases
create url aliases
search module
search content
use advanced search
system_service module
check module exists from remote
clear cache from remote
get variable from remote
send mail from remote
set variable from remote
views module
access all views
I got it finished a while ago, forgot to post the resolution
I think it was as simple as typing in the wrong address and not stepping through the debugger. I tend to do those mistakes often.
I'll post the source if anyone wants when I get to work monday. The project ended up not being used but it was a cool intro to connector languages. If only RTD worked as well