1

Help with one issue

Тема: Help with one issue

HI, i,m new in the gurtam community and i like to get some help whit one Issue.

i'm working with notifications detailed information in gurtam sdk remote API, i'm using PHP for gurtam, from the github Wialon Remote API PHP library(https://github.com/wialon/php-wialon).
as you see in the gurtam sdk documentation (https://sdk.wialon.com/wiki/en/local/remoteapi1704/apiref/resource/get_notification_data#alarm_button_trigger
), the command requires two parameter which are "itemId" (resource ID) and "col"(array of notifications IDs).
in the php code the JSON array is encoded in this way:  {"itemId":119179,"col":[11]} according to the previous parameters, but when i send them the server returns to me error:7 which according to the gurtam api documentations means Access denied, but apparently i got all the access rights to the notifications.
the following PHP code is what i use to send the request to the server.
$NotificationParams=array("itemId"=>119179,
                              "col"=>array(11)); //PHP array of parameters
   
    echo "JSON ENCONDE: ".json_encode($NotificationParams)."<br>"; //to print the JSON array, encoding php array to json in order to send them in the following request

    echo "ARREGLO JSON NOTIFICACIONES: ".$wialon_api-> resource_get_notification_data(json_encode($NotificationParams))."<br>"; //to print the JSON response of the server(which returns error 7)

i like to know if i'm doing something wrong in the request or if it's just that i'm still do not have enough rights to the notifications.

THANKS!

2

Help with one issue

Re: Help with one issue

andres.apodaca, hello.
Make sure you have enough access rights to resource. This request expects you have 0x0000000100000 or 1048576 access right (View notifications) to resource. Make sure 119179 is id of your resource with notifications.

Head of Wialon Local Department
Gurtam
3

Help with one issue

Re: Help with one issue

Hello deal, thanks for the reply, I have enough rights, I already checked, when i send the request  like this: http://hst-api.wialon.com/wialon/ajax.html?svc=resource/get_notification_data&params={"itemId":12927886,"col":[4,1]}&sid=0315e2a90f594172bd9538122f43796b
(this works fine, brings the notifications in the JSON response, but the SID only lives for 5 minutos or less, and that's a problem)
originally in the gurtam documentation you only need to send itemId and col, but i add to the request the SID, which is the unique id from the current session, the problem now is that this authentication method is depreciated according to gurtam, I authenticate myself by token, what i tried to do was just take the SID generated in the session by token, but when i send that to the request the server throws me error 7, which does not happen when I use the old method of autentuficacion by user and password, collecting the SID generated from this.

I don't know what is the difference between these two SID's, ¿why one is accepted (the user and password method) by the request and the other(by token) is not ?

the following code is an example of what i'm trying to do (PHP code)

$token = '861f22d29e794b97252000301368857c00F7D91ADABC120B22A44AC30848C506CA0747DF'; //token autentication   

$result = $wialon_api->login($token); //calling the login php method
$json = json_decode($result, true); //Decoding the response from the server
    $userId= $json['user']['id']; //getting the user ID
   $sid= $json['eid'];  //GETTING the session ID(SID)

THE NEXT CODE IS THE WAY I GET THE RESPONSE FROM THE SERVER THROUGH STATIC SID(generated by user and password method)

$NotificationParams=array("itemId"=>11917979,
                                   "col"=>array(11,51)); //PHP ARRAY OF PARAMS

echo "<br>JSON ENCONDE: ".json_encode($NotificationParams)."&sid=03fbd6069ea7bd1bfef215e33fae6662"."<br>"; //Prints the JSON  //Prints the encoded JSON array adding in concat the SID(which only lives for 5 minutes)
   
echo "ARREGLO JSON NOTIFICACIONES: ".$wialon_api->
resource_get_notification_data(json_encode($NotificationParams)."&sid=03fbd6069ea7bd1bfef215e33fae6662")."<br>";
//prints the JSON response from the server, which brings us the notifications 11 and 51 correctly, but only while the SESSION SID is alive.

THE OTHER METHOD MENTIONED ONLY CHANGES IN THE SID, WHICH TAKES THE VALUE OF THE GENERATED BY THE TOKEN SESSION, IT VARIATES BUT THEORETICALLY I'D HAVE TO GIVE THE SAME RESPONSE, BRINGS THE NOTIFICATION IN A JSON ARRAY, BUT ANNYWAY THE SERVER STILL THROWING  ERROR 7.

echo "JSON ENCONDE: ".json_encode($NotificationParams)."&sid=".$sid.""."<br>"; //encodes the PARAMS and add the generated SID from the current token session in the variable $sid


    echo "ARREGLO JSON NOTIFICACIONES: ".$wialon_api-> resource_get_notification_data(json_encode($NotificationParams)."&sid=".$sid."")."<br>"; //prints the result of the server response, which returns error 7.}

I WOULD THANK YOU VERY MUCH IF YOU COULD HELP ME WITH THIS PROBLEM

THANKS!!

4

Help with one issue

(28/06/2017 10:31:50 отредактировано rual)

Re: Help with one issue

andres.apodaca пишет:

resource_get_notification_data(json_encode($NotificationParams)."&sid=03fbd6069ea7bd1bfef215e33fae6662")

This is looking suspicious. Looks like you are passing into function string:

{"someJSON": 42}&sid=SID

Maybe you need to do something like this:

"params=" . urlencode(json_encode($NotificationParams)) . "&sid=" . $sid

UPD: oh, I'm realized, that your method maybe prepends params=. But anyway, you need add urlencode, if you are just concatenating url params.

5

Help with one issue

Re: Help with one issue

andres.apodaca, hello. How did you create your token? May be your token has not enough rights. Try to create token with access_type=-1.
As for session lifetime (5 mins) - any request will extend session lifetime for 5 mins. You can send avl/evts request (https://sdk.wialon.com/wiki/en/sidebar/ … s/avl_evts) for example every 4.5 mins and session will not die.

Head of Wialon Local Department
Gurtam