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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

How to pass parameter in the body of POST API call?

Hi All,

 

I am quite new to Power Query / BI. Your support would be greatly appreciated. 

I am receiving data via API using Post method. See the code below. I am using a parameter LastYear in the body of the request. 

 

let
lastyearparameter = LastYear,

//LastYear is a parameter (text)

 

url = "https://url.url.com/endpoint/APIKEY",
content= "{
""year"" : "& lastyearparameter &",
""ID"" : ""0""}",


Source= Json.Document(Web.Contents(url,
[Headers = [#"user" = "USERKEY", #"company" = Company, #"Content-type" = "application/json"],
Content = Text.ToBinary(content)])),

 

in Source

 

This works fine, it returns the data of the given year from LastYear parameter. BUT:

If I am trying to use the same method at another endpoint with a parameter which contains a given company code, I get 400 - Bad request error. See my code below:

 

let

companyparameter = Company

//Company is a parameter

url = "https://url.url.com/endpoint2/APIKEY",
content = "{
""starting-date"" : ""2015-01-01"",
""until-date"" : ""2030-12-31"",
""companies"" : "& companyparameter &"}",

Source= Json.Document(Web.Contents(url,
[Headers = [#"user" = "USERKEY", #"Content-Type" = "application/json"],
Content = Text.ToBinary(content)])),

 

in Source

 

Could you help me, what am I doing wrong? If am writing the specific code (e.g. ""X4"") instead of "& companyparameter &" then I am getting back the correct dataset. 

 

Thx

David

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

Whether the problem has been resolved? If yes, could you please mark the helpful post as Answered? It will help other members in the community find the solution easily if they face the similar problem with you. Thank you.

Best Regards

mahoneypat
Microsoft Employee
Microsoft Employee

Please try replacing this line

 

""companies"" : """ & companyparameter &"""}",

 

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


Anonymous
Not applicable

Thx Pat, I replaced, but still no result, I am getting bad request error.

Try just returning your content variable in the "in", so you can see what is actually being converted to binary.  That's how I thought it was fixed.  Note there is an extra carriage return in there that I just removed.

mahoneypat_0-1613310843273.png

 

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


Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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