Are there any examples on how to use the new Web Services API?

Are there any examples on how to use the new Web Services API?

by Kurt Rosivatz -
Number of replies: 20
Moodle 1.8 release notes say: "The Moodle Network code includes an XML-RPC call dispatcher that can expose the WHOLE Moodle API to trusted hosts".

Can anyone point me to some code examples how to use this XML-RPC call dispatcher? I know how to do XML-RPC in general, but need some information on the specifics of the Moodle Implementation (URL of the dispatcher, procedure names/parameters etc.).

I had a look at docs.moodle.org and the discussion threads regarding the API
but did not find any real examples how to use it.

Kurt

Average of ratings: -
In reply to Kurt Rosivatz

Re: Are there any examples on how to use the new Web Services API?

by Martín Langhoff -
You are right - it's not well documented, as it ended up being a bit of a side-feature. I'll ask Donal to prep a very short writeup -- maybe you can help us flesh it out?
Average of ratings: Useful (1)
In reply to Martín Langhoff

Re: Are there any examples on how to use the new Web Services API?

by Kurt Rosivatz -
I'll be glad to help fleshing the docs out, but I need a skeleton to start from ...

Kurt
Average of ratings: Useful (1)
In reply to Kurt Rosivatz

Re: Are there any examples on how to use the new Web Services API?

by Catalin Maican -
Hi,

what is the status of this doc?

I'm trying to access Moodle from an ASP.NET application, so my alternative would be Web Services and XML-RPC... I would like to test them both before deciding.

Thanks,
Catalin


In reply to Martín Langhoff

Re: Are there any examples on how to use the new Web Services API?

by Cory B -
Are there any docs out for the Web Services API yet? I would like to look into using it in Moodle 1.8, but I can't find documentation on how to do so.

Thanks!
In reply to Cory B

Re: Are there any examples on how to use the new Web Services API?

by Steve W -
I would also like documentation and/or examples on using the Web Services API, and would be happy to contribute documentation if I had any information to add.

I'd also like to know how to use the Moodle Network API. Specifically, the docs say:

A special mode can be enabled which would allow a machine with a specified IP address to make calls to the XML-RPC layer without using either encryption or signature envelopes.

How can I enable this unencrypted mode?

Thanks!
In reply to Steve W

Re: Are there any examples on how to use the new Web Services API?

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Start here: http://docs.moodle.org/en/Development:Web_services_API

This document still needs more work, all help is welcome, but high-five to Donal for finally getting it started!
In reply to Martin Dougiamas

Re: Are there any examples on how to use the new Web Services API?

by Steve W -
That's a start, but stops right when it gets to the good part. smile

The information on encryption is helpful and appreciated.

Also, system.listMethods doesn't work for me, but system/listMethods does. I believe using a "." as a seperator is normal XMLRPC syntax. It's at least what I see in plenty of XMLRPC examples.

The section on auth seems targeted towards someone who's writing Moodle, not a third party trying to integrate with it.

How would a third party verify a username/password?

How does one use the services returned by the listServices method? (Apologies if this should be obvious.)

A few other notes based on what I have been able to do. Maybe these would be better for bug reports?

The method signature for keepalive_server seems broken, it just returns a zero.

The method help for enrol/mnet/enrol.php/user_enrolments is empty.
In reply to Steve W

Re: Are there any examples on how to use the new Web Services API?

by Donal McMullan -
Hey Steve - thanks for this. I hope you'll be able to track the page as it evolves, and keep the suggestions coming - it's really useful.

Cheers
In reply to Donal McMullan

Re: Are there any examples on how to use the new Web Services API?

by Steve W -
Hi,

Thanks for the info. But it's still not quite what I'm looking for. I'd prefer not to have to write any modules/addons for Moodle unless I have to do so. This is so that users don't have to do extra work. Perhaps more docs on the mnet protocol is what I want?

http://docs.moodle.org/en/Development:Moodle_Network

is pretty sparse too.
In reply to Steve W

Re: Are there any examples on how to use the new Web Services API?

by Donal McMullan -
Hey Steve - can you give me an idea in non-programmer terms of what you'd like to achieve with the API? What application would you like to use to communicate with Moodle? What would you like it to do? What moodle functions or methods would you like to remotely access?

Cheers
In reply to Donal McMullan

Re: Are there any examples on how to use the new Web Services API?

by Steve W -
SSO, Rostering, Gradbook info.

Thanks!
In reply to Donal McMullan

Re: Are there any examples on how to use the new Web Services API?

by Steve W -
On a separate note, shouldn't the content type that's used for XML have a ; in it? I see this:

text/xml charset=UTF-8

shouldn't it be this:

text/xml; charset=UTF-8

Then again, I think the default charset for xml is UTF-8, so specifying it may not be necessary.

Steve

In reply to Martin Dougiamas

Re: Are there any examples on how to use the new Web Services API?

by Donal McMullan -
Hey guys. Sorry this has taken so long to get started. "Spare time" has been a little sparse this year.

I'm finding some bugs in the system as I write the docs, which is good and bad. They're related to exporting functions from modules, so they don't affect the auth and enrol stuff that was our focus during the development, but they're likely to bite anyone that's trying to export functions from a module.

I'll try to make some commits to MOODLE_18_STABLE and head to fix these issues, and put together a patch for anyone who's unable to track the latest CVS. I think the delta will be fairly small.

I appreciate criticisms/comments on the doco, because when you've written the code yourself, lots of things seem obvious and not worth mentioning that are actually really critical.
In reply to Donal McMullan

Re: Are there any examples on how to use the new Web Services API?

by Steve W -
Hi folks,

A quick question about APIs. Why the separation between the Moodle Network API and the Web Services API? Is that purely related to the encryption? Or is there some other reason?

The reason I ask is I'm wondering, if a third party wants to interact with Moodle as though it were another Moodle (even though it's not), using the Moodle Network API, is that kosher? This assumes of course that the encryption is done, etc. But right now, that seems to be the only way to do the things I want to be able to do, so that seems my only route.

Thanks,
Steve
In reply to Steve W

Re: Are there any examples on how to use the new Web Services API?

by Donal McMullan -
Hi Steve

The Moodle Network API was intended to be a secure transport layer over which people could run web services securely. There are probably a few places in the API where we assume that the app communicating with us is also a Moodle, but we should be able to resolve that if people start wanting to use the transport for other stuff.

We recently did some work at Catalyst to implement the Moodle Network transport layer into Mahara, so a proof of concept that other apps can use this feature already exists.

Mahara implements most of the xmlrpc-auth methods; enough to provide bi-directional SSO with Moodle.

Mahara is free (GPL) and our repo is here:
http://git.catalyst.net.nz/gitweb?p=mahara.git;a=summary

The Moodle Network and SSO code is in Master, which will become Mahara 0.8 sometime this week. You can get a tarball of the Mahara code at any time by clcking on 'master' from the list of heads at the bottom of the screen, and clicking on 'Snapshot'.

Cheers

Donal

In reply to Donal McMullan

Re: Are there any examples on how to use the new Web Services API?

by Steve W -
Hi Donal,

Thanks for the info!

I do have a bit of a snag though, the application I'm writing isn't GPL'd and won't be, so I'm trying to avoid my code being 'based on' GPL code. Unfortunately, this means reading the GPL'd example code and the Moodle source code is out.

So instead I've been working from tcpdump output between two Moodle instances I've setup and from the documentation. Which is why I was asking about the protocol docs. Does this change the answer to any of my previous questions?

Thanks,
Steve
In reply to Kurt Rosivatz

Re: Are there any examples on how to use the new Web Services API?

by Colin Chambers -
Hi Kurt,

I have posted some documentation of an example on the related documentation thread in this forum at http://moodle.org/mod/forum/discuss.php?d=70908#p346424
I hope this helps smile
In reply to Colin Chambers

Re: Are there any examples on how to use the new Web Services API?

by John McLear -
Still not seen any good links to any solid examples of what XML data each API wants and/or URLS for any exposed API paths and the functions.

Tried a few moodle partners to get more info, very disappointed in their willingness to help on this. Partner status isn't a quality assurance mark?

Ideally I would like to see an example someone has written, I need it so I can post images from classdroid to moodle.
In reply to John McLear

Re: Are there any examples on how to use the new Web Services API?

by Bryan Williams -
John,

Tried a few Moodle Partners to get more info, very disappointed in their willingness to help on this. Partner status isn't a quality assurance mark?

Moodle is open source software, which means you are free to look at everything and to figure things out on your own; that is, assuming you are a developer and have taken the time to look at the wealth of Moodle documentation that's available. Both web service API's in Moodle were contributed by Moodle partners, work very well and have been used in a number of novel ways by lots of people in the community. Why would your problem be the fault of Moodle partners?
In reply to Kurt Rosivatz

Re: Are there any examples on how to use the new Web Services API?

by Spyridon Karavanis -
You have to declare the external functions you need
and then make a normal call from a client. You need to specify the authentication for example for soap server http://192.168.1.121/workspace/moodle/webservice/soap/server.php?wstoken=89bf91d2f1f855c5a95fa521c1af8875 it is the same for XML_RPC. IF you create the external functions then it is trivial.