1. Make REST API Calls from atvise (Using HTTPClient Class)

Created by Vester Business, Modified on Tue, 26 Aug at 10:20 PM by Agent Aaron Camacho

In atvise SCADA, REST API calls can be performed using the HTTPClient class (not just a function). This class allows you to send HTTP requests (GET, POST, etc.) directly from atvise to external systems, making it possible to integrate with databases, third-party applications, or other services.


This article provides practical examples of:


  • A GET request with basic authentication and JSON parsing.
  • A POST request with basic authentication to write data.


By the end, you will know how to use new HTTPClient() to build secure and effective REST integrations in atvise.



  1. Example to make a GET method call using BASIC authentication and parsing a JSON format reply from the REST Server.

    // Create an HTTPClient instance (class, not just a function)
    var http = new HTTPClient();
    
    // Execute a GET request with basic authentication
    var response = http.get(
        "http://localhost:3003/tag?cmd=read&path=/*",
        {
            auth: {
                method: "basic",
                user: "vnode",
                password: "vnode"
            }
        }
    );
    
    // --- Parse JSON response ---
    // Example response: {"data":{"value":1234}, "status":"ok"}
    
    // Define the search pattern
    var pattern = "\"data\":{\"value\":";
    
    // Find the index where the pattern starts
    var startIndex = response.data.search(pattern);
    
    // Find the next comma after the pattern
    var endIndex = (response.data.slice(startIndex)).search(",");
    
    // Extract only the clean value from the response
    var cleanValue = response.data.slice(
        startIndex + pattern.length,
        startIndex + endIndex
    );
    
    // Print to console for debugging
    console.log("Extracted Value:", cleanValue);
    
    // Return the extracted value
    return cleanValue;
  2. Example to make a POST method using BASIC authentication.

    // Create an HTTPClient instance (class, not just a function)
    var http = new HTTPClient();
    
    // Execute a POST request with basic authentication
    var response = http.request({
        protocol: "http",
        hostname: "localhost",
        port: 3003,
        path: "/tag?cmd=write",
        method: "POST",
    
        // Data to be sent in JSON format
        data: JSON.stringify({
            "path": "/prueba",     // Tag or node path
            "value": writevalue    // Value to be written
        }),
    
        // Basic authentication credentials
        auth: {
            method: "basic",
            user: "vnode",
            password: "vnode"
        }
    });
    
    // Print server response for debugging
    console.log("POST Response:", response);
    
    // Return the server response
    return response;


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article