Forum Discussion

Tommy____G's avatar
Tommy____G
Frequent Visitor
5 years ago
Solved

API returns 1 Product. I need to loop through and return all products into 1 table

Hi,   Problem Statement I need a full inventory of stock and there's an API I can use but I have to pass a single Product ID.  I have a list of Product IDs so I want to be able to loop through the...
  • lbendlin's avatar
    5 years ago

    No need to delete anything - Power Query always starts from scratch.

     

    The standard approach is

    - have  a list of Product IDs

    - construct the URL for each of them

    - use Web.Contents() to fetch the data for each

    - expand the result into additional columns

     

    It will still have to call the API for each individual product which sounds cumbersome, but that seems to be your environment restriction anyway.

  • lbendlin's avatar
    lbendlin
    5 years ago

    You add a custom column, and in its code specify 

     

    =Web.Contents([URL])

     

    This will then translate into an "each"  process that pulls the data from all the product pages. The column contents will read "binary" and will be clickable.  Think of it as tables inside table cells.

     

    You can then encapsulate that with your JSON parser or whatever the format is.

  • Tommy____G's avatar
    Tommy____G
    5 years ago

    Thanks so much!  A nights sleep and this just made sense this morning, a whole new M query world has just opened up for me....  Have a great day Ibendlin!