cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dkpcr5
Frequent Visitor

Dynamic table headers from API

Hi all,

 

I need help dynamically pulling headers when importing data via API in PowerQuery. I'm currently entering headers manually, which is terribly inefficient and requires manual updates whenever new fields are added to the API.

 

Here's what I have:

let

    endpoint = "(REST API endpoint URL)",
    directive= "A",
    cache    = "false",
    command  = Record.FromList({keys})  ,
    headers  = Record.FromList({command},{"Headers"}),
    payload  = Json.Document(Web.Contents(endpoint, headers)),
    value = payload[value],
    #"Converted to Table" = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {
"Header 1",
"Header 2",
"Header 3"        
})
 
in

    #"Expanded Column1"

In this query's current state, only the identified headers ("Header 1", "Header 2", "Header 3") are pulled into the table.

 

What I'd rather say is, "Give me every column from all headers available." That way, when I refresh the dataset, any new columns will be pulled dynamically.

 

Any help would be appreciated. Thanks!

1 ACCEPTED SOLUTION
lbendlin
Super User III
Super User III

#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", Headers)

View solution in original post

2 REPLIES 2
lbendlin
Super User III
Super User III

#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", Headers)

View solution in original post

dkpcr5
Frequent Visitor

It worked. Thanks so much!

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Top Solution Authors
Top Kudoed Authors