restful api

I am trying to use the restful api that comes with elgg and am having some difficulty. I tried passing:

http://mysite.com/pg/api/rest/xml/?method=auth.gettoken&username=myuser&password=mypassword

but it keeps giving me this error:

Missing parameter username in method auth.gettoken

and obviously it is there. Am I missing something?

  • The rest api is very buggy. Using POST currently doesn't work. Methods become anonymous when they aren't suppose to be. If you're not proficient with PHP I wouldn't even try.

  • I am proficient with php so any help is appreciated. I am trying to create an application that uses the restful api and I can correct bugs if needed.

  • should i just create my own restful api?

  • It took me most of a day to fix the bugs in the rest api code of Elgg. I think you'd be hard pressed to implement all of that from scratch in a day. If you do a search on "rest" in trac, you find some of the bug reports that I filed on this. I still have more to submit.

  • I am still trying to figure out how to use the api. I have figured out that you must use the expose_function() method to create a function. I would like to be able to return some data from the wire in xml format. For example I would like the wire to return this:

    <username>username here</username>

    <profileicon>profile icon here</profileicon>

    However, I am unable to figure out how to return the data from thewire object. Is there a way to do this? Also, the only place I have found that you can call the expose_function is from the start.php file. Is there anywhere else that you can call the expose_function()?

  • I recommend creating a plugin http://docs.elgg.org/wiki/Plugin_skeleton

    Then in the start.php of the plugin, define a function that returns the string "hello, world". That's all it needs to do. Now put an expose_function() call in start.php that exposes that function via rest. Hit the appropriate URL and it should return your string in xml format.

    Once you have that working, it shouldn't be too difficult to add parameters and/or start returning wire posts.

  • I actually already had that working. I was just returning test but same difference. However, I am trying to return something in xml format and it does not seem to like it. Is there any way to return the data as xml? When I tell it to return as xml it doesnt seem to like it because it just shows it all on the same line. Any ideas? For example I would do this:

    function test(){

    return '<post>testing</post>';

    }

  • I think I figured out why it is happening. I am just not sure how to fix it. When I look at the page source instead of displaying '<post>' it is displaying '&tl;post&gt;'. Is there any way to get it to display the regular source? It looks like htmlspecialchars() is getting run on it.

  • Ok so for the time being so I could return the data as xml I just removed htmlentities() from the xml.php file and it is now returned as xml. But I am trying to return the recent wireposts. If I do it in my browser while I am logged in it is working fine. However, if I am not logged in it is not working. In my expose_function() i have authentication set to false and anonymous set to true. am I missing something? seems to me like its not authenticating. here is my expose_function():

    expose_function("myapi.test", "test_import", array( "username" => array(type => "string", required => false), "password" => array(type => "string", required => false)), "imports an profile", "GET", false, true);