Avatar

How to get Logs text message using api

0

 Hi I was wondering if it is possible to get text message from logs.For example I have created a custom rule when entering customer zone the alert I set was log which is set to me and also have custom template for the log with the required info I need.I can see the logs in the notifications tab with the custom message.I would like to get the log with message using the api I am unable to see where to get the messages the log has created.

 

Tara Hibbins

Please sign in to leave a comment.

2 comments

0
Avatar

Hi Tara,

Could you specify exactly how the notifications for this exception rule is set-up? It is possible to have notifications be sent out by text message using the Add email option, and it is also possible to have messages sent to Geotab Drive using the Add driver feedback --> Text Message option. There is often confusion with how the option within driver feedback states Text message, but actually means a message to the Drive app. 

If you could also provide the database you are working on, I could take a look at your specific use of this.

Thanks,

Christoph Middleton 0 votes
1
Avatar

As per the details in our ticket: "We have a system that needs to constantly update to show if the customer has visited the zone on the day. We setup zones and are seeing the events for the vehicle on geotab, but would like to pull this information into our system via our program." & "{Device} entered zone {Zone} at address {Address}. This triggered this rule {Rule}".

Firstly, when a rule in MyGeotab is broken, an exception is created. The exception reports provide information about the vehicle and device, location, zone and the rule that was triggered. These can be accessed via MyGeotab --> Rules & Groups --> Exceptions. The details can also be collected by calling on the exceptions from the rules. The problem is the script will become very complex to include all of the information that you guys want. This method would be a much more direct method of collecting all the information and it is what I would recommend. The only downside is it will be quite a bit of work to setup a script that functions correctly. 

The alternative is just calling on the users Notifications. If you already have the notifications setup to display within a users MyNotifications: , then we can call on those.

This is done using the following call: 

api.call("GetUserNotifications",{"startAfterVersion":null}); 

The user with the notifications will need to be logged in. As I said, I would not recommend this since it will be more difficult to specify search criteria and work with the results. 

My recommendation would be to use the exceptions although this may be more complicated. I developed a script that will run through the exceptions and remove the details you specified. The variables "Exceptions", "LogRecord", "Address", "Device", "Zone" and "Rule" should have all the details you guys want, and even more. 

api.call("Get", {
        "typeName": "ExceptionEvent",
        "search": {
            "deviceSearch": {
                "id": "b2"
            },
            "ruleSearch": {
                "id": "aOODN0UbEtEGIxLqyICqZZg",
                "includeZoneStopRules": false
            },
            "fromDate": "2018-11-28T05:00:00.000Z",
            "toDate": "2018-11-28T07:59:59.000Z"
        }
    },
    function(Exceptions) {
        for (var i = 0; i < Exceptions.length; i++){
            doit(Exceptions[i]);
        }
    }
);

function doit(Exceptions) {
    //console.log(Exceptions);
    api.call("Get", {
        "typeName": "LogRecord",
        "search": {
            "fromDate": Exceptions.activeFrom,
            "toDate": Exceptions.activeTo,
            "deviceSearch": {
                "id": Exceptions.device.id
            }
        }
    }, function(LogRecord) {
        //console.log(LogRecord);
        api.call("GetAddresses", {
            "coordinates": [{
                "x": LogRecord[0].longitude,
                "y": LogRecord[0].latitude
            }],
            "movingAddreses": false,
            "hosAddresses": false
        }, function(Address) {
            //console.log(Address);
            api.call("Get", {
                "typeName": "Device",
                "search": {
                    "id": Exceptions.device.id
                }
            }, function(Device) {
                //console.log(Device);
                api.call("Get", {
                        "typeName": "Zone",
                        "search": {
                            "id": Address[0].zones[0].id
                        }
                    }, function(Zone) {
                        //console.log(Zone);
                        api.call("Get", {
                            "typeName": "Rule",
                            "search": {
                                "id": Exceptions.rule.id
                            }
                        }, function(Rule) {
                            //console.log(Rule);
                            console.log(Device[0].serialNumber + " entered zone " + Zone[0].name + " at address : " + Address[0].formattedAddress + ". This triggered this rule " + Rule[0].name);
                        });
                    }
                );
            });
        });
    });
}

This can be run in the api runner. From this, you should be able to edit the inputs, to change the search range, rules and devices ect. 

Let me know if you guys have any other questions or need help setting up anything,

Christoph Middleton 1 vote