Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet 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
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.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
35 | |
16 | |
12 | |
11 | |
9 |
User | Count |
---|---|
45 | |
27 | |
16 | |
14 | |
14 |