Forum Discussion

chonchar's avatar
chonchar
Helper V
2 years ago
Solved

New table based on iterative API calls

Hello! I have imported a table that is based on a CSV file. It is called table 1. In table 1, there is an "ID" column that needs to be referenced in an API call. Table 1 is below: 

 

I am able to create Table 2 based on this m code:

 

= Json.Document(Web.Contents("https:api_url_all_the_stuff", [Headers=[Accept="application/json", #"x-api-key"="API_Password_and_key_stuff", #"x-table1-id"="1001"]]))

 

The problem is that this only refers to a single "ID" from table 1 and there are hundreds of entries for "ID" in table 1. 

 

I need table 2 to look like this: 

 

 

I would like to make a new table with a single query that iterates each "ID" from table 1 and puts all of the information from the api call in table 2. 

 

Please advise! Kudos and Accepted Solutions are sure to follow. 

 

foodd parry2k amitchandak Greg_Deckler MFelix rajendraongole1 

 

  • chonchar here are quick steps:

     

    - click advanced editor of table 2 and get the copy of the M code

    - start new blank query, click advanced editor and type

    (id as text) =>
    and after this paste the M code 

     

    Save and close and you have M function with Is as parameter

10 Replies

  • chonchar create a m function with id as parameter and the use table2 code in this function, replace id with the parameter name.

     

    once it is done, add new column in table 1 and call function (created in step 1) with id as parameter. You will get a table returned from the function and the last step is to expand this new column. This will do it.

    • chonchar's avatar
      chonchar
      Helper V

      parry2k I am unfamiliar with how to create a parameter with M. I am looking into documentation now. 

  • chonchar here are quick steps:

     

    - click advanced editor of table 2 and get the copy of the M code

    - start new blank query, click advanced editor and type

    (id as text) =>
    and after this paste the M code 

     

    Save and close and you have M function with Is as parameter

    • chonchar's avatar
      chonchar
      Helper V

       

      parry2k I got to here, but I don't understand how to reference the column? This still only has on ID in the m code.

  • chonchar  Check my original reply

     

    once it is done, add new column in table 1 and call function (created in step 1) with id as parameter. You will get a table returned from the function and the last step is to expand this new column. This will do it.

    • chonchar's avatar
      chonchar
      Helper V

      parry2k I am so close. So, I have this:

      But once I open that table, it is only creating the ID from the original M. 

       

       

      What ID Value goes here, or the column name?

  • chonchar can you paste the m code (not screen shot) you are using to add a new column in table1, also can you paste the code for the new function you created (remove any sensitive API key) before sharing? 

    • chonchar's avatar
      chonchar
      Helper V

      parry2k I figured it out through your direction. I am going to mark another reply as the solution. Thank you for your help. Again.