Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Create user with API

Hi,

Is there any known way to create a new user using Vanilla API?

I use /users/edit calls successfully for already existent users, but need to add new ones as well. I've tried to use a couple of approaches suggested at this forum, but with no luck.

If it's impossible to implement with API, is there an easy and stable way to do it with direct writes to db? I basically only need to create a new user (Name + Email) with curtain role assigned, that's all. If it's possible, could you please provide more details - I'm a newbie at Vanilla.

Thank you,

Yuga

Tagged:

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    I was trying exactly the same yesterday! That's what I have done - but it didn't work :-(

       include('./httpful.phar');
    
       $response = \Httpful\Request::post('http://mysite.net/index.php?p=/entry/register')
          ->sendsJson()
          ->authenticateWith('my', 'site')
          ->body('{
             "Form_Name"               : "MyUser"
             , "Form_TermsOfService"   : "1"
             , "Form_Gender"           : "m"
             , "Form_Password"         : "MyPassword"
             , Form_DiscoveryText      : "Vanilla is great!"
             }')
          ->send();
    

    I thought that this library would be helpful http://phphttpclient.com/

  • R_JR_J Ex-Fanboy Munich Admin

    I get


    as if I've sent nothing...

  • R_JR_J Ex-Fanboy Munich Admin

    Btw. I wouldn't have asked that question here and I don't believe it will be answered. Giving a description means posting an introduction on how to write a spam bot ;-)

  • R_JR_J Ex-Fanboy Munich Admin

    See that piece of faulty pseudo code below?

    Some silly, drunken clown must have taken over my account and posted that. I deny that this was done by me!

    @R_J said:

       include('./httpful.phar');
    
       $response = \Httpful\Request::post('http://mysite.net/index.php?p=/entry/register')
          ->sendsJson()
          ->authenticateWith('my', 'site')
          ->body('{
             "Form_Name"               : "MyUser"
             , "Form_TermsOfService"   : "1"
             , "Form_Gender"           : "m"
             , "Form_Password"         : "MyPassword"
             , Form_DiscoveryText      : "Vanilla is great!"
             }')
          ->send();
    

    Oh, what a shame :-(

  • Actually, I've found a work-around, based on some research and intuition


    // example data
    $sendData = array(
    'Name' => 'Test',
    'User.Email' => 'test@test.com',
    'Email' => 'test@test.com',
    'Role.ID'=>8, // Member
    'Title'=>'',
    );

    // try to update Vanilla user first
    $res = makeCurl('edit', $sendData);
    
    // if not found, create new user
    if ($res->Code == 400) { // add check for 'not found' string in Exception
    
        // it's not covered in docs, but works this way
        $sendData['Role'] = $sendData['Role.ID'];
        unset($sendData['User.Email'], $sendData['Role.ID']);
    
        $res = makeCurl('save', $sendData);
        if($res->Code !== 200/* && $res->Exception === 'The name you entered is already in use by another member.'*/){
            //report an error or try to send the other name first
        }
    }elseif($res->Code !== 200){
        logError('Error on edit: ' . print_r($res, true));
    }
    



    function makeCurl($action, $sendData){
    $url = 'https://yourDomain.vf.com/api/v1/users/' . $action . '.json?access_token=tokenItself';
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt(
        $ch,
        CURLOPT_POSTFIELDS,
        $sendData
    );
    $res = curl_exec($ch);
    if (curl_exec($ch) === false) {
        logError('Curl error: on ' .$action . ' ' . curl_error($ch) . print_r($sendData, true));
        die();
    }
    curl_close($ch);
    return json_decode($res);
    

    }


    function logError($message){
    file_put_contents('error.log', $message, FILE_APPEND);
    }

  • If you post under an addon then it will be linked to that addon, then there the right people will be informed.

    grep is your friend.

  • If you post under an addon then it will be linked to that addon, then there the right people will be informed.

    precisely.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • yugayuga New
    edited September 2013

    Are moderators available here to move the topic to addon forum? Where to find it at all? It's not obvious.
    Anyway, I still didn't get any response which approach is advisable to use.

Sign In or Register to comment.