cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Power Apps Staff CarlosFigueira
Power Apps 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
Power Apps Staff CarlosFigueira
Power Apps 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
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

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

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (8,830)