How to make REST API calls from atvise

Created by Vester Business Support Team, Modified on Tue, 02 Nov 2021 at 08:49 PM by Vester Business Support Team

atvise has a function called "HTTPClient" which you can find in the HELP menu.  This function is used to call REST methods.


Here are 2 examples


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


//Open conection HTTPClient()

var http = new HTTPClient()


//Execute GET command

var res = http.get("http://localhost:3003/tag?cmd=read&path=/*",

{auth: {method: "basic", user: "vnode", password: "vnode"}

});


//PARSING

var cadena_patron="\"data\":{\"value\":";

var indice=(res.data).search(cadena_patron);

var indice2=((res.data).slice(indice)).search(",");

var data_limpia=(res.data).slice(indice+cadena_patron.length,indice+indice2);

console.log(data_limpia);


//Return clean value

return(data_limpia);



2. Example to make a POST method using BASIC authentication.


//Open conection HTTPClient()

var http = new HTTPClient()


//POST Command execute

var res = http.request({

    protocol: "http",

    hostname: "localhost",

    port: 3003,

    path: "/tag?cmd=write",

    method: "POST",

    data: JSON.stringify({"path": "/prueba", "value": writevalue}),

    auth: {method: "basic", user: "vnode", password: "vnode"}

});

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 atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article