Web API examples
The following section contains related examples of how you can use the described methods
in the Web API.
The examples use HTML, JSON and JQuery library for asynchronous requests.
Note
Information used in the examples
Note that the names of the methods, parameters and the JavaScript code are specified
without liability and can deviate from the current specification.
Example 1
Example 1 shows a client that wants to maintain a session with JavaScript. For this purpose,
it sends a single heartbeat request using the Api.Ping method. If the intervals at which the
heartbeat request is sent are less than 2 minutes, the user remains permanently logged in.
A permanent login is recommended for operating and monitoring tasks.
$.post({
url:"https://192.168.2.132/api/jsonrpc",
headers:{
'X-Auth-Token':"Sy8pe3VNv86rTMldzFBsYzmw12Lg"
},
data:JSON.stringify({jsonrpc:"2.0", method:"Api.Ping", id:1}),
success:function(data){ console.log(data); }
dataType:"text",
contentType:"application/json"
});
Note
X-Auth-Token
To extend the session, you must send the token (X-Auth token) as an HTTP header to the
CPU.
When you call the Api.Ping method without a token, the session is not extended because the
CPU cannot assign a token to the user.
Example 3 shows an example of a token in the HTTP request.
In the example, the selected user has the necessary authorizations. The methods after the
login request were successfully carried out, as the following result shows.
{jsonrpc:"2.0",id:1,result:"ZWlmbnJwZmplb3Nwd2l1Y3N3dWE="}
Web server
Function Manual, 11/2019, A5E03484625-AG
3.20 API (Application Programming Interface)
Web pages
167