Forum Discussion

Nicolai's avatar
Nicolai
Frequent Visitor
9 years ago
Solved

Dynamic REST queries

So, I've been googling around a bit and found a lot of references to dynamic REST queries being possible, but unfortunately not enough to get me started with it.   So, I have a query that returns a...
  • Anonymous's avatar
    Anonymous
    9 years ago

    See the sample code below which may help explain:

    let
    //  Create sample data table
        Source = #table({"id", "Name"}, 
                        {{1,"Horse"},
                        {56, "Cow"},
                        {3543, "Sheep"},
                        {8777, "Dog"},
                        {23433, "Pig"},
                        {45454, "Cat"}}),
    //Ensure the "id" is Text for the next Text.Combine step
        ChangedType = Table.TransformColumnTypes(Source,{{"id", type text}, {"Name", type text}}),
    //Combine the id's into a CSV value
        CombinedIDs = Text.Combine(ChangedType[id], ","),
    //Create your URL including the CSV list of IDs
        url = "http://yourtargetsite.com?id=" & CombinedIDs,
    //Get JSON from your target site
        Json = Web.Contents(url),
    //Process the returned results as neeeded - e.g.
        FormattedAsJson = Json.Document(GetJson)
    in
        FormattedAsJson