Web API, REST API, version 6

Forum Home Forums Development and Integration Web API, REST API, version 6

Tagged: 

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #10315
    Mikhail
    Moderator

    Take a look at WebApiClientSample, an example of calling a web API from a non-web application.

    #10326
    JW
    Participant

    This will be very helpful API!

    Would you also consider an API that allow posting device data to scada?

    #10328
    Mikhail
    Moderator

    Using 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.

    #10442
    haggaipp
    Participant

    Hi, Mikhail.
    Can I get data from this url: http://webserver/scada/ClientApiSvc.svc/GetCurCnlDataExt?cnlNums=&viewIDs=&viewID=1

    I 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!

    #10445
    Mikhail
    Moderator

    Hi,

    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.

    #10843
    kumajaya
    Participant

    My 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.

    #11181
    kumajaya
    Participant

    Feel 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.

    #11188
    Mikhail
    Moderator

    Now I can access SCADA API from Node-RED easily.

    Cool!

    #12441
    tgkim79
    Participant

    This 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?

    #12448
    Mikhail
    Moderator

    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?

    Will reply here.

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.