Forum Discussion

martin__smith's avatar
martin__smith
Frequent Visitor
4 years ago
Solved

How can I dynamically add Query parameters in Web.Contents call?

I am calling Azure Monitor Rest API via PowerQuery.   I would like to make a fairly generic function which I can use for various different metrics.   Some of the QueryString parameters passed to ...
  • martin__smith's avatar
    4 years ago

    Ah figured it out

     

     

    (ResourceUri as text, metricnames as text, aggregation as text, interval as text, timespan as text, optional top as text, optional orderby as text) =>
    let
        QueryParams =  Record.Combine({
        [aggregation = aggregation, interval = interval, metricnames = metricnames, timespan=timespan],
        if orderby<>"" and orderby <> null then  [orderby = orderby] else [],
        if top<>"" and top <> null then  [top = top] else []
    }),
        Source = Json.Document(Web.Contents(
                "https://management.azure.com/" & 
                ResourceUri & "/providers/microsoft.insights/metrics?api-version=2018-01-01&%24filter=CollectionName%20eq%20%27*%27%20and%20DatabaseName%20eq%20%27*%27",
                [Query=QueryParams])),