API Authentication

Home Forums Conduit: AEP Model API Authentication

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #26891

    How works API authentication ?
    I don’t find any information about that in http://www.multitech.net/developer/software/aep/conduit-aep-api/
    When I try to send commands, I get “not logged in” error message.

    #26892
    Jeff Hatch
    Keymaster

    Hello Denis,

    Currently, on the AEP Conduit you can use the following example:

    This curl example can be used externally to do a login:

    curl -ik -c cookies -X POST -H ‘Content-Type: application/json’ -d ‘{“username”:”admin”,”password”:”admin”}’ https://192.168.2.2/api/login

    Get the token from the response:

    HTTP/1.1 200 OK
    Set-Cookie: token=F2A41FB275BF23F5AB382373DB7B20A4; Max-Age=300; Path=/; Secure
    Cache-Control: no-cache
    Content-type: application/json
    Transfer-Encoding: chunked
    Date: Wed, 22 Feb 2017 09:36:42 GMT
    Server: rcell

    {
    “code” : 200,
    “result” : {
    “address” : “192.168.2.200”,
    “permission” : “admin”,
    “port” : “45170”,
    “timestamp” : “9:36:42:216”,
    “token” : “F2A41FB275BF23F5AB382373DB7B20A4”,
    “user” : “admin”
    },
    “status” : “success”
    }

    Then use the token in the curl POST request to send an SMS:

    curl -k -X POST -H “Content-Type:application/json” -d ‘{“recipients” : [“1234567890”], “message” : “This is a test of sms_send” }’ https://192.168.2.2/api/sms/outbox?token=F2A41FB275BF23F5AB382373DB7B20A4
    {
    “code” : 200,
    “status” : “success”
    }

    In the future this is going to change due to multiple user support and API changes that are being made.

    Jeff

    #26895

    Thanks Jeff.
    For people who prefer php scripts (Thanks to Adlane):

    <?php

    function transfert($url,$tabData){
    $data=json_encode($tabData);
    $ch = curl_init();
    $options = array(
    CURLOPT_URL=>$url,
    CURLOPT_RETURNTRANSFER=> 1,
    CURLOPT_POST => true,
    CURLOPT_SSL_VERIFYHOST => 0,
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_HTTPHEADER => array(‘Content-Type:application/json’),
    CURLOPT_POSTFIELDS => $data
    );
    curl_setopt_array($ch,$options);
    $result = curl_exec($ch);
    if (curl_error($ch)) {
    $result = curl_error($ch);
    echo ‘erreur ‘.$result;
    }
    curl_close($ch);
    return $result;
    }

    //1ere URL Login :
    $url=”https://192.168.30.38/api/login&#8221;;

    //param authentification  :
    $login[‘username’]=”admin”;
    $login[‘password’]=”admin”;

    //envoi de la requete d’authentification et récupération du résultat:
    $result_Gw=transfert($url,$login);
    $result_Gw=json_decode($result_Gw);

    //recuperation du token
    $token_Gw=$result_Gw->result->token;

    if(isset($token_Gw)){
    //2eme URL pour l’envoi du SMS
    $url2=”https://192.168.30.38/api/sms/outbox?token=&#8221;.$token_Gw;

    //construction de la requete :
    $SMS[‘recipients’]=[“+33012345678″];
    $SMS[‘message’]=”TEST MESSAGE”;

    //envoi de la requete :
    $result_Gw2=transfert($url2,$SMS);

    //affichage du resultat final :
    print_r($result_Gw2);

    }

    ?>

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.