Forum Discussion

vinisz's avatar
vinisz
New Member
2 years ago

Help needed with using list of values in web API query

Hi all,

I have a challenge that I cannot quite solve...
I have a list of values ( I can also make that a column if that helps):

I need to loop through all these values and use them in a web call like below (where I need to replace "123" with the value from the list each time):

 

 

let
url = "https://api.server.nl",
headers = [#"Content-Type" = "application/json",#"Authorization"= #"Token"],
postData = Json.FromValue([RecordID = 123]),
response = Web.Contents(
url,
[
Headers = headers,
Content = postData
]
),
jsonResponse = Json.Document(response),
Navigation = jsonResponse[Records],

 

 


I hope my request is clear and someone can help me.

1 Reply

  • rubayatyasmin's avatar
    rubayatyasmin
    Community Champion

    Hi, vinisz 

     

    Got help from gpt

     

    try this M code

     

     

    let
        // Reference to your table
        Source = YourTableNameHere,
    
        // Function to make web call
        MakeWebCall = (value) =>
            let
                url = "https://api.server.nl",
                headers = [#"Content-Type" = "application/json", #"Authorization" = "Token"],
                postData = Json.FromValue([RecordID = value]),
                response = Web.Contents(
                    url,
                    [
                        Headers = headers,
                        Content = postData
                    ]
                ),
                jsonResponse = Json.Document(response),
                Navigation = jsonResponse[Records]
            in
                Navigation,
    
        // Invoke the function for each value in the "List" column
        Results = List.Transform(Source[List], each MakeWebCall(_))
    in
        Results

     

     

    see if this helps