Forum Home › Forums › Development and Integration › Web API, REST API, version 6
Tagged: Web API
- This topic has 9 replies, 5 voices, and was last updated 1 year, 5 months ago by Mikhail.
-
AuthorPosts
-
May 30, 2022 at 2:11 pm #10315MikhailModerator
Take a look at WebApiClientSample, an example of calling a web API from a non-web application.
June 2, 2022 at 9:25 am #10326JWParticipantThis will be very helpful API!
Would you also consider an API that allow posting device data to scada?
June 2, 2022 at 12:27 pm #10328MikhailModeratorUsing the web API it’s possible to send a telecontrol command.
To write data to Server, TCP-based protocol should be used. I can provide the protocol specification.
However, it’s possible to develop any required web API by a contract. Or may be gRPC API.August 1, 2022 at 1:09 pm #10442haggaippParticipantHi, Mikhail.
Can I get data from this url: http://webserver/scada/ClientApiSvc.svc/GetCurCnlDataExt?cnlNums=&viewIDs=&viewID=1I use XMLHttpRequest in my JS code. But it always says, user not logged in. When i check the ScadaWeb.log it keeps adding User Information in every request. Can you solve this?
My Javascript code:
var xhttp = new XMLHttpRequest(); function main() { xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { // Typical action to be performed when the document is ready: let tmp = JSON.parse(xhttp.responseText); let response = JSON.parse(tmp.d); console.log(response); if (response.Success) { if (response.Data) { getData(); } else { console.log("SERVER NOT LOGGED IN"); logIn(); } } else { console.log("[ERROR]: " + response.ErrorMessage); } } }; xhttp.open("GET", "http://localhost:8080/scada/ClientApiSvc.svc/CheckLoggedOn", true); xhttp.send(); } function logIn() { xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { // Typical action to be performed when the document is ready: let tmp = JSON.parse(xhttp.responseText); let response = JSON.parse(tmp.d); console.log(response); if (response.Success) { if (response.Data) { console.log("LOG IN SUCCESSFUL!"); // getData(); // main(); } else { console.log("FAILED TO LOG IN!"); } } else { console.log("[ERROR]: " + response.ErrorMessage); } } }; xhttp.open("GET", "http://localhost:8080/scada/ClientApiSvc.svc/Login?username=admin&password=12345&callback=true", true); xhttp.send(); } function getData() { xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { // Typical action to be performed when the document is ready: let tmp = JSON.parse(xhttp.responseText); let response = JSON.parse(tmp.d); console.log(response); if (response.Success) { console.log("FETCH DATA SUCCESSFUL!"); console.log(response.Data) } else { console.log("[ERROR]: " + response.ErrorMessage); } } }; xhttp.open("GET", "http://localhost:8080/scada/ClientApiSvc.svc/GetCurCnlDataExt?cnlNums=&viewIDs=&viewID=2&callback=true", true); xhttp.send(); } getData();
Scada Web Log:
2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> Request SCADA-Server state 2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> Disconnect from SCADA-Server 2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> Connect to SCADA-Server "localhost" 2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> User information has been added. IP address: ::1. Session: fgkmemvsn0avgnhrfx1f40sw 2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> Login: admin (Administrator). IP address: ::1 2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> User information has been updated. IP address: ::1. Session: fgkmemvsn0avgnhrfx1f40sw 2022-08-01 20:07:59 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> Retrieve components from the installed plugins 2022-08-01 20:08:01 <DESKTOP-RLH5Q4C><DefaultAppPool><ACT> User information has been added. IP address: ::1. Session: ul23o4sslwbbznovlxl242w2 2022-08-01 20:08:01 <DESKTOP-RLH5Q4C><DefaultAppPool><EXC> Error getting extended current data by the filter where channels=, view id=2: Scada.ScadaException: User not logged on. at Scada.Web.UserMonitor.CheckLoggedOn(UserRights& userRights, Boolean throwOnFail) at Scada.Web.ClientApiSvc.GetCurCnlDataExt(String cnlNums, String viewIDs, Int32 viewID)
Or there is the other way to fetch data from OPC server? I use JS and PHP.
Thank You!
August 2, 2022 at 9:33 am #10445MikhailModeratorHi,
Or there is the other way to fetch data from OPC server? I use JS and PHP.
To get data from an OPC server, use the existing OPC client driver. See this link for details.
If you need another thing, please specify your question.
September 20, 2022 at 1:10 pm #10843kumajayaParticipantMy solution in Node-RED is a bit of tricky with Puppeteer help:
const puppeteer = global.get('puppeteer') const browser = await puppeteer.launch({headless: true, ignoreHTTPSErrors: true}) const page = await browser.newPage() await page.goto('https://localhost/scada/Login.aspx') await page.type('input[name="txtUsername"]', 'admin') await page.type('input[name="txtPassword"]', '12345') await page.click('[name="btnLogin"]') const cookies = await page.cookies() browser.close() msg.payload = cookies return msg;
And then access SCADA API using http request node with above session cookie.
October 7, 2022 at 4:39 am #11181kumajayaParticipantFeel so stupid. I just have to enable AllowAuthApi in ScadaWeb/config/ScadaWebConfig.xml and restart scadaweb6 service. Now I can access SCADA API from Node-RED easily.
October 7, 2022 at 11:13 am #11188MikhailModeratorNow I can access SCADA API from Node-RED easily.
Cool!
April 16, 2023 at 1:50 am #12441tgkim79ParticipantThis article is very helpful.
I also success login in by using REST API.
however I try to get and write data from Rapid Scada, but it’s not working the response statusCode is 401. how can I solve it?April 16, 2023 at 8:06 am #12448 -
AuthorPosts
- You must be logged in to reply to this topic.