cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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
CarlosFigueira
Power Apps
Power Apps

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
CarlosFigueira
Power Apps
Power Apps

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!

Anonymous
Not applicable

Thank you very much Carlos. This was really helpful.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (5,156)