REST API 3.1

Discussion in 'ISPConfig 3 Priority Support' started by iamchris, Apr 30, 2016.

  1. iamchris

    iamchris New Member

    I saw that version 3.1 is shipped with a new REST API.
    Unfortunately i do not find the REST API, i only see the old SOAP API in the remoting_client directory.

    Does someone know where i can find the REST API / Endpoints?
     
  2. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    Last edited: Apr 30, 2016
    jnsc likes this.
  3. iamchris

    iamchris New Member

    Hi,
    thanks for your reply.
    Is there any properly Documentation about the API?
    How would i auth to the JSON API to authorize requests?

    I tried it with POSTMAN and a Basic Auth ( http://d.pr/i/sjzz ) , but i get a
    Code:
    {
      "code": "remote_fault",
      "message": "The SessionID is empty.",
      "response": false
    }
    I also tried to login with the username & password e.g
    Code:
    /json.php?login&username=api&password=testtest&client_get=4
    I get
    Code:
    {
      "code": "remote_fault",
      "message": "The login username is empty.",
      "response": false
    }
    Or with Guzzle
    PHP:
    $client = new GuzzleHttp\Client();

            
    $res $client->request('POST''https://178.62.204.18:8080/remote/json.php', [
                
    'verify' => false,
                
    'query' => [
                    
    'login' => [
                        
    'username' => "api",
                        
    'password' => "testtest",
                    ],
                    
    'client_get' => 4,
                ]
            ]);

            return 
    json_decode($res->getBody(), true);
    i get also "the username is empty" - But i passed the username?

    So how would i start the Session using JSON since there arent any Tokens or something like that?
    Btw: Why are there any tokens since this is the normal and "the way to go" auth for JSON APIs?

    And last question: Where can i find all Methods?
    I know the Examples Directory but in which file(s) are these Methods stored for the JSON API so that i can take a login for the login methods for example?

    PS: Okay the Methods are stored here:
    https://git.ispconfig.org/ispconfig...er/interface/lib/classes/remoting.inc.php#L70
     
    Last edited: May 22, 2016
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    There is no REST specific documentation available yet. But the functions and parameters are the same thean the soap api, REST is just another endpoint. So you can use the soap api docs. The complete remote api docs are in the remote_client folder of the ispconfig tar.gz.
     
  5. iamchris

    iamchris New Member

    Could you give me an Example how to receive a client for example?

    I really dont know how i should authenticate with the JSON API since i get always "the username is empty" but i think i passed the username as you can see in my guzzle example above.
    My query looked like this:
    /json.php?login&username=api&password=testtest&client_get=4
    A simple example would be super awesome, i cant get my head into this API .. o_O

    As i see from the Login Method the username & password is passed:
    https://git.ispconfig.org/ispconfig...er/interface/lib/classes/remoting.inc.php#L70
    e.g
    Code:
    public function login($username, $password, $client_login = false)
    ...
    ...
    So i dont know why i am getting that the username is empty since i passed it as a query
    Would it be possible to get an Example using curl?
     
    Last edited: May 22, 2016
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    The parameters have to be sent by POST request and not with GET like in your example. an you can not combine the login function with the client_get function in a single call.

    First login, this will return you a session id. This session id is then passed to all other functions as parameter.

    I have not written the REST connector, so I don't have any examples for it yet.
     
  7. iamchris

    iamchris New Member

    I did not send the request with GET i always did it with POST, where did you saw that?
    http://d.pr/i/15NlT
    The API Call just for testing is
    Code:
    https://178.62.204.18:8080/remote/json.php?login&username=api
    but i am still getting the error, that the username is empty.
    Who wrote the REST Connector? Can i mail him?
    PS: Its just a Test Droplet, so no worries about the server :)
     
  8. Croydon

    Croydon ISPConfig Developer ISPConfig Developer

    Please update again to the current stable branch (fixed the REST api).
    You find an example in remoting_client/examples/rest_example.php then.
     
    iamchris likes this.
  9. iamchris

    iamchris New Member

    Thanks for your help.
    I tried your example which did not work - I just got an empty white site with no error. If i die & dump i got a false.
    I had to replace the global var by
    Code:
    $remote_url = 'https://178.62.204.18:8080/remote/json.php';
    because the global var seems not be available in the restCall function.
    After replacing the global var with
    Code:
    $remote_url = 'https://178.62.204.18:8080/remote/json.php';
    e.g
    Code:
        $remote_user = 'api';
        $remote_pass = 'testtest';
    
        function restCall($method, $data) {
    
            $remote_url = 'https://178.62.204.18:8080/remote/json.php';
    .....
    .....
    And to get all clients as json it would be
    PHP:
            $result restCall('client_get', array('session_id' => $session_id'client_id' => array()));
            
    $result json_decode($resulttrue);
            if(
    $result) {
                return 
    $result['response'];
            }
    your example is working now. Thanks for your help and happy coding ;)
     
    Last edited: May 23, 2016
    fyberoptik likes this.
  10. sjau

    sjau Local Meanie Moderator

    Hi iamchris

    Would you be so kind to post your working example?
     

Share This Page