GAS Wialon Local Remote API: Retrieve login data

250 Views Asked by At

Good day,

I have a Wialon Local server (GPS monitoring system) and am planning to update a shared Google sheet using time-driven installable triggers.

As per the Wialon documentation, I am able to get the desired response when entering my API call in a browser.

However, in GAS, I am getting the below error when trying to retrieve data from the response.

API Call:

  let apiURL = `http://my.tracking.site.come/wialon/ajax.html?svc=token/login&params={"token":"5dce19710a5e26ab8b7b898XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXFCEED7DC03BC48FF5F8"}`
  console.log(apiURL) // This URL works in a web browser as expected
  var resText = UrlFetchApp.fetch(apiURL).getContentText() // error is raised on this line
  console.log(resText)

The error:

11:48:27 AM Error   
Exception: Invalid argument: http://my.tracking.site.come/wialon/ajax.html?svc=token/login&params={"token":"5dce19710a5e26ab8b7b898XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXFCEED7DC03BC48FF5F8"}
wialonLogin @ wialon.gs:20

Kindly advise what I am doing wrong here as I have very little experience with both GAS and Wialon Remote API ... will appreciate any assitance.

Thanks.

1

There are 1 best solutions below

0
On

Solution is to encode the URL.

let apiURL = `http://my.tracking.site.come/wialon/ajax.html?svc=token/login&params={"token":"5dce19710a5e26ab8b7b898XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXFCEED7DC03BC48FF5F8"}`
  console.log(apiURL) // This URL works in a web browser as expected
  var urlEncoded = encodeURI(apiURL);
  var resText = UrlFetchApp.fetch(urlEncoded).getContentText() // error is raised on this line
  console.log(resText)