Sending Messages with Rest API

Is there a way to send REST API calls in AVEVA System Platform & OMI? I have seen some documentation on Rest API for Recipe Management and don't know if/how that would help me in this situation. After a button is clicked, I want to send a rest message with HTTP Post.

Parents
  • Hi Caroline,

    As Adam suggest, the WEBSVC will allow you to do connections to webservice and get or set data and presenting it in a OI Driver like way.

    Funneling the data into datapoints you could use in your objects.

    But there is also possible to do this using scripting, the following example will utilize a RestSharp.dll and the newtonsoft library for working with json

    'REST API Call
    dim client as RestSharp.RestClient;
    dim request as RestSharp.RestRequest;
    dim response as RestSharp.RestResponse;
    
    client = new RestSharp.RestClient("http://api.openweathermap.org/data/2.5/forecast?q=London&mode=json&units=imperial&cnt=7&appid=3b8af615471033987fdaa4bf2ef93231");
    client.Timeout = -1;
    'System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 |System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls13;
    request = new RestSharp.RestRequest(RestSharp.Method.GET);
    response = client.Execute(request);
    LogError(response.Content);
    
    Me.Result = response.Content;
    
    'JSON String parsing
    dim jinstance as Newtonsoft.Json.Linq.JObject;
    dim jarray1 as Newtonsoft.Json.Linq.JArray;
    
    jinstance = Newtonsoft.Json.Linq.JObject.Parse(response.Content);
    jarray1 = Newtonsoft.Json.Linq.JArray.FromObject(jinstance["list"]);
    
    
    'Assign values to Attibutes
    dim i as integer;
    for i = 0 to jarray1.Count - 1 step 1
    	Me.Humidity.Value[i + 1] = jarray1[i]["main"]["humidity"];
    	LogMessage(Me.Humidity.Value);
    	Me.Temperature.Max[i + 1] = jarray1[i]["main"]["temp_min"];
    	Me.Temperature.Min[i + 1] = jarray1[i]["main"]["temp_max"];
    
    next;
    Me.Run = false;

    I have some additional examples and files, but reach out to me (contact info in my profile) and I can send you some example files if you find it valuable.

Reply
  • Hi Caroline,

    As Adam suggest, the WEBSVC will allow you to do connections to webservice and get or set data and presenting it in a OI Driver like way.

    Funneling the data into datapoints you could use in your objects.

    But there is also possible to do this using scripting, the following example will utilize a RestSharp.dll and the newtonsoft library for working with json

    'REST API Call
    dim client as RestSharp.RestClient;
    dim request as RestSharp.RestRequest;
    dim response as RestSharp.RestResponse;
    
    client = new RestSharp.RestClient("http://api.openweathermap.org/data/2.5/forecast?q=London&mode=json&units=imperial&cnt=7&appid=3b8af615471033987fdaa4bf2ef93231");
    client.Timeout = -1;
    'System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 |System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls13;
    request = new RestSharp.RestRequest(RestSharp.Method.GET);
    response = client.Execute(request);
    LogError(response.Content);
    
    Me.Result = response.Content;
    
    'JSON String parsing
    dim jinstance as Newtonsoft.Json.Linq.JObject;
    dim jarray1 as Newtonsoft.Json.Linq.JArray;
    
    jinstance = Newtonsoft.Json.Linq.JObject.Parse(response.Content);
    jarray1 = Newtonsoft.Json.Linq.JArray.FromObject(jinstance["list"]);
    
    
    'Assign values to Attibutes
    dim i as integer;
    for i = 0 to jarray1.Count - 1 step 1
    	Me.Humidity.Value[i + 1] = jarray1[i]["main"]["humidity"];
    	LogMessage(Me.Humidity.Value);
    	Me.Temperature.Max[i + 1] = jarray1[i]["main"]["temp_min"];
    	Me.Temperature.Min[i + 1] = jarray1[i]["main"]["temp_max"];
    
    next;
    Me.Run = false;

    I have some additional examples and files, but reach out to me (contact info in my profile) and I can send you some example files if you find it valuable.

Children
No Data