cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
abhrai
Level: Powered On

Check Web Service or Server is up and running or not using PowerApps

I have one of the requirements in my project to create a dashboard to let the users know whether a particular web service is up and running or not. Also, whether a particular server is up and running or not. How I can achieve this set of Dashboard functionality in PowerApps. Please suggest.

 

~abhrai

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Check Web Service or Server is up and running or not using PowerApps

PowerApps by itself doesn't have a way to check an arbitrary web service, as all communication is done via connectors (data sources). You can, however, create a custom connector that can do this.

To test this I create an Azure Function with the code below:

using System.Net;
using System.Net.Http;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    // parse query parameter
    string url = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "url", true) == 0)
        .Value;

    if (url == null)
    {
        // Get request body
        dynamic data = await req.Content.ReadAsAsync<object>();
        url = data?.url;
    }

    if (url == null) {
        return req.CreateResponse(HttpStatusCode.BadRequest, "Please inform the URL to test");
    }

    using (HttpClient c = new HttpClient()) {
        try {
            var resp = await c.GetAsync(url);
            log.Info($"Url: {url}, Status: {resp.StatusCode}");
            return req.CreateResponse(HttpStatusCode.OK, new Result { StatusCode = (int)resp.StatusCode, Url = url });
        } catch (Exception ex) {
            log.Info($"Exception: {ex.GetType().FullName} - {ex.Message}");
            return req.CreateResponse(HttpStatusCode.OK, new Result { StatusCode = 0, Url = url });
        }
    }
}

public class Result {
    public string Url { get; set; }
    public int StatusCode { get; set; }
}

And then use a custom connector - for example, with the OpenAPI definition below:

{
  "swagger": "2.0",
  "info": {
    "title": "ForumThread235074",
    "description": "Connector for https://powerusers.microsoft.com/t5/General-Discussion/Check-Web-Service-or-Server-is-up-and-running-or-not-using/m-p/235074",
    "version": "1.0"
  },
  "host": "YOUR.HOSTNAME.GOES.HERE.net",
  "basePath": "/api/",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [],
  "paths": {
    "/ForumThread235074": {
      "post": {
        "responses": {
          "default": {
            "description": "default",
            "schema": {
              "type": "object",
              "properties": {
                "Url": {
                  "type": "string",
                  "description": "Url"
                },
                "StatusCode": {
                  "type": "integer",
                  "format": "int32",
                  "description": "StatusCode"
                }
              }
            }
          }
        },
        "summary": "GetStatus",
        "description": "GetStatus",
        "operationId": "GetStatus",
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": false,
            "schema": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string",
                  "description": "url"
                }
              }
            }
          }
        ]
      }
    }
  },
  "definitions": {},
  "parameters": {},
  "responses": {},
  "securityDefinitions": {},
  "security": [],
  "tags": []
}

With this custom connector you can then have an app that can use that connector to check a certain web server is running.

Hope this helps!

View solution in original post

2 REPLIES 2
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Check Web Service or Server is up and running or not using PowerApps

PowerApps by itself doesn't have a way to check an arbitrary web service, as all communication is done via connectors (data sources). You can, however, create a custom connector that can do this.

To test this I create an Azure Function with the code below:

using System.Net;
using System.Net.Http;

public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
    log.Info("C# HTTP trigger function processed a request.");

    // parse query parameter
    string url = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "url", true) == 0)
        .Value;

    if (url == null)
    {
        // Get request body
        dynamic data = await req.Content.ReadAsAsync<object>();
        url = data?.url;
    }

    if (url == null) {
        return req.CreateResponse(HttpStatusCode.BadRequest, "Please inform the URL to test");
    }

    using (HttpClient c = new HttpClient()) {
        try {
            var resp = await c.GetAsync(url);
            log.Info($"Url: {url}, Status: {resp.StatusCode}");
            return req.CreateResponse(HttpStatusCode.OK, new Result { StatusCode = (int)resp.StatusCode, Url = url });
        } catch (Exception ex) {
            log.Info($"Exception: {ex.GetType().FullName} - {ex.Message}");
            return req.CreateResponse(HttpStatusCode.OK, new Result { StatusCode = 0, Url = url });
        }
    }
}

public class Result {
    public string Url { get; set; }
    public int StatusCode { get; set; }
}

And then use a custom connector - for example, with the OpenAPI definition below:

{
  "swagger": "2.0",
  "info": {
    "title": "ForumThread235074",
    "description": "Connector for https://powerusers.microsoft.com/t5/General-Discussion/Check-Web-Service-or-Server-is-up-and-running-or-not-using/m-p/235074",
    "version": "1.0"
  },
  "host": "YOUR.HOSTNAME.GOES.HERE.net",
  "basePath": "/api/",
  "schemes": [
    "https"
  ],
  "consumes": [],
  "produces": [],
  "paths": {
    "/ForumThread235074": {
      "post": {
        "responses": {
          "default": {
            "description": "default",
            "schema": {
              "type": "object",
              "properties": {
                "Url": {
                  "type": "string",
                  "description": "Url"
                },
                "StatusCode": {
                  "type": "integer",
                  "format": "int32",
                  "description": "StatusCode"
                }
              }
            }
          }
        },
        "summary": "GetStatus",
        "description": "GetStatus",
        "operationId": "GetStatus",
        "parameters": [
          {
            "name": "body",
            "in": "body",
            "required": false,
            "schema": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string",
                  "description": "url"
                }
              }
            }
          }
        ]
      }
    }
  },
  "definitions": {},
  "parameters": {},
  "responses": {},
  "securityDefinitions": {},
  "security": [],
  "tags": []
}

With this custom connector you can then have an app that can use that connector to check a certain web server is running.

Hope this helps!

View solution in original post

abhrai
Level: Powered On

Re: Check Web Service or Server is up and running or not using PowerApps

Thank you very much Carlos. This was really helpful.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,055)