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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. 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
v-yiruan-msft
Community Support
Community Support

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

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
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
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.