Example of HTTP PUT request to REST API

This is an example on how a PUT request to the REST API can be made in a script within GpsGate. This requires the REST API has been enabled and a token generated.

In this example, we are updating an accumulator for a specified device. 

Variables to change:

  • <YOUR_SERVER_URL>: The URL to your server
  • <YOUR_TOKEN>: Your REST API token (https://support.gpsgate.com/hc/en-us/articles/360010858619-How-to-get-an-API-token-and-authorization-in-REST)
  • <YOUR_APP_ID>: The application ID in which device is located in
var curDate = user.trackPoint.utcTimestamp; //Gives are timestamp in the format of "2022-06-22T11:21:39.0000000Z"
log(curDate);
curDate = curDate.toISOString().split('.')[0]+"Z"; //Removes the trailing 0:s, "2022-06-22T11:21:39Z"
log(curDate);

var strUrl = 'https://<YOUR_SERVER_URL>/comGpsGate/api/v.1/batch/applications/<YOUR_APP_ID>/accumulators';
var strContentType = 'Content-Type:application/json';
var strHeaders = 'Authorization:<YOUR_TOKEN>\nContent-Type:application/json';
var strBody = '[{"accumulatorTypeId":1,"timestamp":"'+curDate+'","userId":31,"value":0}]';

http.PUT(strUrl,strContentType,strHeaders,strBody);