Skip to main content
12-Amethyst
April 16, 2025
Solved

Message ::TypeError: Cannot call method "GetJSON" of null

  • April 16, 2025
  • 1 reply
  • 458 views

Hi, 


I have a Scheduler that execute this code :

// Define the Thing that contains the service
me.flag1 = 1;
// Call the service (e.g., GetAPIData) of the API Thing
Things["Eastern.SecurityVehiclesAPI.parser"].GetAPIData();
logger.warn("Tracking.API.Scheduler_3 subscriptionToCallTheService executed");
me.flag1 = 2;

 
and here is the service code itself 

//code
// API endpoint and headers

var apiUrl = "http://212.70.49.13/ewe.agent/api/v1/online-history/fleet/2100/all-vehicles";
var headers = {
 "Accept": "*/*",
 "Accept-Encoding": "gzip, deflate, br",
 "ApiKey": "xxxxx" // Replace with your actual API key
};
logger.warn("getapidata 2");

//var result = contentLoader.GetJSON(params);

// Make the HTTP GET request
 var result = Resources["ContentLoaderFunctions"].GetJSON({
 url: apiUrl,
 headers: headers,
 timeout: 10000 // Timeout in milliseconds
 });
logger.warn("getapidata 3");
 // Store the response in a property or return it
	me.APIResult = result;
	//logger.warn("API Response: " + JSON.stringify(result));


the service itself when i run it it works fine without any errors , but when the Scheduler runs it i get this error: 
Error in: Eastern.SecurityVehiclesAPI.parser.GetAPIData javascript service. Message ::TypeError: Cannot call method "GetJSON" of null (GetAPIData#15)

please note that this service and scheduler used to work on another platform and was fine so i am sure that the codes are correct, also both platforms run the same thingworx version 

so what might be wrong or even how to debug more for this one ?

thanks 

Best answer by Rocko

The user executing the subscription may not have the necessary privileges (Visibility) on the Resources entity so it can't access the ContentLoaderFunctions. So check the user you entered in the scheduler.

1 reply

Rocko
Rocko19-TanzaniteAnswer
19-Tanzanite
April 16, 2025

The user executing the subscription may not have the necessary privileges (Visibility) on the Resources entity so it can't access the ContentLoaderFunctions. So check the user you entered in the scheduler.