Hello,
I've been trying to add new users to a Deki Wiki using the API but have only found a dozen ways on how *not* do it and I'm looking for some help on just 1 way to actually do it. I'm trying implement this in a python script although have also been messing with curl, I can successfully run GET commands and even other POST commands for pages, but I can't understand what I'm doing wrong when trying to POST new users.
Here's are the current curl commands:
testuser.xml is a xml file that I copied from the POST:users API documentation input format section:Code:#!/bin/bash curl -c cookies.txt -u {Username}:{Passwd} http://Deki.Wiki.Url//@api/deki/users/authenticate curl -b cookies.txt -X POST -d @testuser.xml "http://Deki.WIki.Url/@api/deki/users"
I've also tried removing the status and service.authentication parts as they are in the implementation section of the API doc.Code:<user id="200"> <username>JackSprat</username> <email>jsprat@gmail.com</email> <fullname>Jack Sprat</fullname> <status>active</status> <service.authentication id="1" /> <permissions.user> <role>contributor</role> </permissions.user> </user>
When I run this it complains that the username isn't specified:
I've already tried replacing -d in the curl code with --data-binary and --data-urlencoded as well as just pasting in the XML testuser information (whitespace removed), and using -d username=JackSprat etc... although none of them work.Code:<?xml-stylesheet type='text/xsl' href='/@api/host/resources/error.xslt'?> <error> <status>400</status> <title>Bad Request</title> <message>'username' not provided or invalid</message> <uri>http://Deki.Wiki.Url/@api/deki/users</uri> </error>
The end goal though is to have this running in a python script using a standard library module. Heres an example of what I've been using with urllib2:
This yields a HTTPError: HTTP Error 500: Internal Server ErrorCode:wikiURL = 'http://Deki.Wiki.Url' user = '{Username}' passwd = '{Password}' # Get the authentication info, save to cookieReponse url = wikiURL+"/@api/deki/users/authenticate" passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() passmgr.add_password(None, url, user, passwd) authhandler = urllib2.HTTPBasicAuthHandler(passmgr) opener = urllib2.build_opener(authhandler) cookieResponse = opener.open(url) # `input` is a string of the testuser.xml file, whitespace removed url = wikiURL+'/@api/deki/users/' request = urllib2.Request(url=url, data=input) request.add_header('Set-Cookie', cookieResponse.headers['Set-Cookie']) response = urllib2.urlopen(request)
I've been hacking at this for a while and am would like to not pull out all of my hair over this =) I'm not a window's user so using c# isn't much of an option for me. I'm also trying to refrain from just going into the database to play it safe although its looking like it might be easier. Any help on this would be *greatly* appreciated!
Cheers.




Reply With Quote