Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
suebayes
Resolver I
Resolver I

Json API with header details

I have a function that I’ve created that works with a JSON api with a query

let Source = (RelativePath) =>

// function to add as a custom column to pull in relative path from table using the name of the api call
let
Source = Json.Document(Web.Contents(
“https:/********/”,
// url remains static
[
RelativePath = RelativePath,
Query =
[
token=Token // token is parameterised
]
]
)),
#“Converted to Table” = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
#“Converted to Table”

in Source

Which works and I can add as a custom column to the table that holds the relative path within a column.

 

I’d like to try to do the same but using a url with a Headers field but am struggling.

The url is structured like this:

= Json.Document(Web.Contents(“https:///RelativePathstoredincolumn", [Headers=[#“X-SiteToken”="****”]]))

and I want to use a Headers parameter instead of query and token as above. I think it’s because it’s a list within a list and has special characters in it. Any suggestions?

//[Headers=[#"“X-SiteToken”"=""***********""]]))"

1 ACCEPTED SOLUTION

Hi Pat, I got it to work.  I'd tried putting it in as a parameter before but had neglected to change the parameter to a list type! So now when I put it in as a custom function within the column, I could then specify which column to use as the input and therefore which row.  A bit of an epic journey.

 

suebayes_0-1613300530556.png

@ImkeF  I got it to work and learnt a lot 🙂

View solution in original post

4 REPLIES 4
suebayes
Resolver I
Resolver I

Hi Imke,

Thank you for replying, really appreciate it.

Power BI and Json

I have a table that gives the name of the API call and two methods of calling the API. 

Both work when I use them within a blank query but I want to create a function using create a custom function column that will use the value in the API Call to fill in the APICallName and run the function.

 

suebayes_6-1613235572064.png

 

The query for API URL which works is

suebayes_7-1613235572066.png

 

This allows me to add this into a column as a function, add an index, and expand using index number

suebayes_8-1613235572069.png

 

 

Then I can use another function to Extract the Data by entering the index number

 

suebayes_9-1613235572071.png

 

 

The customer would prefer to use the url using the Headers option in the second column but I’m struggling to get the parameterised code working.

suebayes_10-1613235572071.png

 

This is my latest attempt but I think there must be something to do with the structure of the headers and it being a nested list with special objects in it.  When I add this code into the column I get an error message that I argument was passed to a function which expects 2.

 

suebayes_11-1613235572074.png

Have been trying all sorts of options, any thoughts would be gratefully appreciated.

 

Hopefully it makes a bit more sense,

Sue

 

 

It looks like you are putting the relative path into the body of the web call in the last image, instead of putting it in the relative path option of the Web.Contents function.  Did you try concatenating the relative path into the url?

 

url = "https://*****/" & RelativePath

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi Pat, I got it to work.  I'd tried putting it in as a parameter before but had neglected to change the parameter to a list type! So now when I put it in as a custom function within the column, I could then specify which column to use as the input and therefore which row.  A bit of an epic journey.

 

suebayes_0-1613300530556.png

@ImkeF  I got it to work and learnt a lot 🙂

ImkeF
Community Champion
Community Champion

Hi @suebayes ,

not sure I can follow.
But I would recommend to test out the desired URL in the browser or a tool like Postman to check general correctness.
Then we could try to "translate" it to Power Query and troubleshoot if necessary.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.