Some help with XML-RPC call

Some help with XML-RPC call

by Michael Simpson -
Number of replies: 2
So without going into the full story, I'm trying to do a quick test on our moodle server using xml-rpc

I've created an external service, assigned it the functions I want, and set my own user as the only authorised user for the service.
I've generated a token for the service.
My user has the capabilities to use the functions assigned to the service, and the xml-rpc protocols.

I wrote some quick python code just to make a test request (snippet below):

proxy = xmlrpc.client.ServerProxy(moodle_url)

username = '<someuser>'
token = '<mytoken>'
user_info = proxy.core_user_get_users(token, {'criteria': [{'key': 'username', 'value': username}]})

However, upon execution it's spitting out the error:
<Fault 89159464: 'Invalid token - token not found | ERRORCODE: invalidtoken'>

However, the token is copy/pasted exactly as it appears on the service, it does not expire and I'm able to use it without issue for another RESTful integration that I use.

At this point I'm not really sure which token it's expecting, (If I user the token.php endpoint with my user login details the token it returns is the same as the token I'm using) or where I'm going wrong!

In reply to Michael Simpson

Re: Some help with XML-RPC call

by Michael Simpson -
Ok so the issue was I can't just send "token" in the proxy method arguments, I have to append it to the site_url string with "?wstoken="

Now to build the parameters correctly haha
In reply to Michael Simpson

Re: Some help with XML-RPC call

by Michael Simpson -
My new issue is ofc the classic - how on earth do I structure the enrol request to enrol a user?

The following xml-rpc request works:
    user_criteria ={'key': 'username', 'value': '<username>'}
   

    user_info = proxy.core_user_get_users([user_criteria])

However the following returns "invalid parameter" fault:
enrolment = {
            "roleid": 5,
            "userid": 1301483,
            "courseid": 474,
            "timestart": 1705659088,
            "timeend": 1706569201,
            "suspend": 0
        }

enrolment_result = proxy.enrol_manual_enrol_users([enrolment])

The same parameter values (and similar structure) work on RESTful calls without issue, but for now I'm specifically trying to make the xml-rpc call. (Short story is edwiser bridge is not synchronising courses enrolled via REST API call - I suspect due to their own "filter" function checking the global $_POST variable - I basically want to test the xml-rpc call which shouldnt be using $_POST