Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin 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.
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
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
Please try replacing this line
""companies"" : """ & companyparameter &"""}",
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
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.
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
15 | |
11 | |
8 | |
8 | |
7 |
User | Count |
---|---|
15 | |
13 | |
9 | |
6 | |
6 |