Tuesday, April 21, 2020

Using powershell with UptimeRobots API

I got a chance to test Uptimerobots API with Powershell and I used it with a csv-list of urls with keywords to update my uptimerobot account.
Pretty good stuff where you also can output all your monitors with uptimelogs directly to PowerBI or equivalent.

Code:


To get UptimeRobot status from PowerBI the following queries can be used:

Example 1 - Simple query

let
   body = Text.ToBinary("api_key=#myAPIKey#&format=json&logs=1"),
   Options = [
   Headers=[#"Content-type"="application/x-www-form-urlencoded", #"cache-control"="no-cache"],
   Content=body
   ],
   result = Web.Contents(url, Options)
in
    result


Example 2 - Query using records


let
   content= [
      #"api_key"="#myAPIKey#",
      #"format" = "json",
      #"logs" = "1"
   ],
   query = Text.ToBinary(Uri.BuildQueryString(content)),
   Options = [
   Headers=[
      #"Content-type"="application/x-www-form-urlencoded",
      #"cache-control"="no-cache"],
      Content=query
   ],
   result = Web.Contents(Url, Options)
in
    result
 
Example 3 - Query using json
 
let
   content = "{
  ""api_key"": ""#myAPIKey#"",
  ""format"": ""json"",
      ""logs"": ""1""        
    }",
   query = Text.ToBinary(Uri.BuildQueryString(Json.Document(content))),
   Options = [
   Headers=[
      #"Content-type"="application/x-www-form-urlencoded",
      #"cache-control"="no-cache"],
      Content=query
   ],
   result = Web.Contents(Url, Options)  
in
    result

No comments:

Powershell and Uptimerobot

Uptimerobot can be quite tedious when you need to update many monitors at once. For example say you bought the license for Uptimerobot and n...