Fork me on GitHub
Please upgrade to 2.1.x here. The 2.0 branch is no longer being updated.
Critical: Update to 2.1.8, released 15 Jan.

Additional functionality for Vanilla API?

edited October 2011 in Vanilla 2.0 Help

I'm very new to Vanilla but was attracted to it due to the possibility of a baked-in web services API ( However, this API seems to be for read-only access to the data. Are there any plans to extend the API to allow modification of discussions, user data, etc.? Even if the API will not go all the way to being fully RESTful, just a basic CRUD interface for the main elements (users, categories, discussions, posts) would be great.

EDIT: If there are no current plans for this, can you point me in the right direction to put that functionality in myself?



Best Answer

  • x00x00 MVP
    edited October 2011 Answer ✓
    This a basic idea just messing around as a plugin:
    $PluginInfo['ExtendAPI'] = array(
    'Name' => 'ExtendAPI',
    'Description' => "ExtendAPI",
    'Version' => '0.1',
    'Author' => 'me'

    if (!function_exists('unserialize_xml')) {
    function unserialize_xml($input, $callback = null, $recurse = false){
    // Get input, loading an xml string with simplexml if its the top level of recursion
    $data = ((!$recurse) && is_string($input))? simplexml_load_string($input): $input;
    // Convert SimpleXMLElements to array
    if ($data instanceof SimpleXMLElement) $data = (array) $data;
    // Recurse into arrays
    if (is_array($data)) foreach ($data as &$item) $item = unserialize_xml($item, $callback, true);
    // Run callback and return
    return (!is_array($data) && is_callable($callback))? call_user_func($callback, $data): $data;

    class ExtendAPI extends Gdn_Plugin {

    public function PostController_Render_Before(&$Sender){
    if ($Sender->Request->RequestMethod()== 'POST') {
    $RawContent = file_get_contents("php://input");
    $Data = json_decode($RawContent);
    //dependent on some basic xml parser in this case using SimpleXML.
    $Data = unserialize_xml($RawContent);


    foreach($Data As $NodeName => $NodeValue ){
    SetValue( $Sender->Form->InputPrefix.'/'.($NodeName=='TransKey'?'TransientKey':$NodeName),$_POST,$NodeValue);

    if ($Sender->Form->AuthenticatedPostBack() === TRUE) {
    //TO DO validation, save, draft, etc.
    //TO DO output succes/fail, etc
    }else if ($Sender->Request->RequestMethod() == 'GET') {
    $Sender->SetData('TransKey',Gdn::Session()->TransientKey());//'TransientKey' is strippped out so use 'TransKey'




    grep is your friend.


Sign In or Register to comment.