1

Error 7 when creating account

Topic: Error 7 when creating account

Hi everyone, I am creating an interface using the Wialon Hosting remote API, and when I want to create an account from a resource, I get error 7, someone can explain to me that it is wrong in my code.




<?php
include_once 'api/wialon.php';

class controller{
    private $token = "admin token";
    private $wialon = null;
    private $master = "admin id";

    function __construct() {
        $this->wialon = new wialon();
    }

    public function registrar_cuenta($username, $password, $accountname, $planname){
        $creatorId = $this->registrar_usuario($this->master, $username, $password);
        $this->configuracion_usuario($creatorId, 0x4, 0x4); //activo permisos de creacion de objetos
        $resourceId= $this->registrar_recurso($creatorId, $accountname);
        //error (7) de acceso denegado para modificar el recurso a una cuenta.
        $param = array(
            'itemId' => $resourceId,
            'plan' => ''.$planname.''
        );
        $response = $this->wialon->login($this->token);
        $json = json_decode($response, true);
        if (!isset($json['error'])) {
            $resultado = $this->wialon->account_create_account(json_encode($param));
            $this->wialon->logout();
            $resultado = json_decode($resultado, true);
            if (!isset($resultado['error'])) {
                return "true";
            }else{
                return $resultado['error'];
            }
        }
    }

    public function registrar_usuario($creatorId, $username, $password){
        $param = array(
            'creatorId' => $creatorId,
            'name' => ''.$username.'',
            'password' => ''.$password.'',
            'dataFlags' => 0x1
        );
        $response = $this->wialon->login($this->token);
        $json = json_decode($response, true);
        if (!isset($json['error'])) {
            $resultado = $this->wialon->core_create_user(json_encode($param));
            $this->wialon->logout();
            $resultado = json_decode($resultado, true);
            if (!isset($resultado['error'])) {
                $userId = $resultado['item']['id'];
                return $userId;
            }else{
                return $resultado['error'];
            }            
        }else{
            return $json['error'];
        }

    }

    public function configuracion_usuario($creatorId, $flags, $flagsMask){
        $param = array(
            'userId' => $creatorId,
            'flags' => $flags,
            'flagsMask' => $flagsMask
        );
        $response = $this->wialon->login($this->token);
        $json = json_decode($response, true);
        if (!isset($json['error'])) {
            $resultado = $this->wialon->user_update_user_flags(json_encode($param));
            $this->wialon->logout();
            $resultado = json_decode($resultado, true);
            if (!isset($resultado['error'])) {
                return true;
            }else{
                return $resultado['error'];
            }
        }else{
            return $json['error'];
        }

    }

    public function registrar_recurso($creatorid, $name){
        $param = array(
            'creatorId' => $creatorid,
            'name' => ''.$name.'',
            'dataFlags' => 0x1
        );
        $response = $this->wialon->login($this->token);
        $json = json_decode($response, true);
        if (!isset($json['error'])) {
            $resultado = $this->wialon->core_create_resource(json_encode($param));
            $this->wialon->logout();
            $resultado = json_decode($resultado, true);
            $resourceId = $resultado['item']['id'];
            return $resourceId;
        }else{
            return $json['error'];
        }
    }

}
2

Error 7 when creating account

Re: Error 7 when creating account

Hello!

First check the token access rights with which you login. You need to have full access
Then to create new account you need to create firstly new user or apply ID of exist user which still not has own account. After you need to create resource from this user.
And then use this resource ID to create an account with billing plan

Diana Cheley
Wialon Hosting Expert
Gurtam