Forum Discussion
Nicolai
9 years agoFrequent Visitor
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...
- Anonymous9 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
Nicolai
9 years agoFrequent Visitor
Yea, so the Ids are in a table already, via power query. That is correctly understood.
What I don't understand, is where I add this combined string?
Do I create it as a parameter on the table with the ids?
Anonymous
9 years agoNot applicable
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