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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Nick123
Frequent Visitor

Power Query - Dynamic DateTime Parameters in JSON

Hi,

 

Recently I succeeded in connecting Power Query with an API of a supplier to download data. I can only download 31 days at a time. Can anyone assist me in doing so?

 

In below is the working version for a single period. I was planning to turn the query into a function and make "from" and "to" dates as text parameters, but I ran into a problem "Web.Contents failed to get contents from... (500)" because of introducing the dates as parameters.

 

let
Login = Json.Document(Web.Contents("https://app.com/login?apikey=test", [Headers=[#"Content-Type"="application/x-www-form-urlencoded", Accept="application/json"], Content=Text.ToBinary("username=user&password=password&market=BE")])),
sessionId = Login[sessionId],
body = "{
""from"": ""2018-12-22 00:00:00"",
""to"": ""2019-01-18 00:00:00"",
""events"": [],
""venues"": [],
""admin"": [],
""promoter"": []
}",
Source=Json.Document(Web.Contents("https://app.com/eventSales?apikey=test", [Headers=[#"sessionId"=sessionId, #"marketcode"="BE", Accept="application/json",#"Content-Type"="application/json"], Content=Text.ToBinary(body)])),
in
Source

 

Thanks

1 ACCEPTED SOLUTION
v-yuezhe-msft
Employee
Employee

@Nick123,

Please change your power query code to the following and check if it works.

let
    Source1 = (param1 as date, param2 as date) =>


let 
Login = Json.Document(Web.Contents("https://app.com/login?apikey=test", [Headers=[#"Content-Type"="application/x-www-form-urlencoded", Accept="application/json"], Content=Text.ToBinary("username=user&password=password&market=BE")])),
sessionId = Login[sessionId],
body = "{
""from"": """& Date.ToText(param1) & """,
""to"": """ & Date.ToText(param2)&""",
""events"": [],
""venues"": [],
""admin"": [],
""promoter"": []
}",
Source=Json.Document(Web.Contents("https://app.com/eventSales?apikey=test", [Headers=[#"sessionId"=sessionId, #"marketcode"="BE", Accept="application/json",#"Content-Type"="application/json"], Content=Text.ToBinary(body)])),
in
Source

in
   Source1



Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-yuezhe-msft
Employee
Employee

@Nick123,

Please change your power query code to the following and check if it works.

let
    Source1 = (param1 as date, param2 as date) =>


let 
Login = Json.Document(Web.Contents("https://app.com/login?apikey=test", [Headers=[#"Content-Type"="application/x-www-form-urlencoded", Accept="application/json"], Content=Text.ToBinary("username=user&password=password&market=BE")])),
sessionId = Login[sessionId],
body = "{
""from"": """& Date.ToText(param1) & """,
""to"": """ & Date.ToText(param2)&""",
""events"": [],
""venues"": [],
""admin"": [],
""promoter"": []
}",
Source=Json.Document(Web.Contents("https://app.com/eventSales?apikey=test", [Headers=[#"sessionId"=sessionId, #"marketcode"="BE", Accept="application/json",#"Content-Type"="application/json"], Content=Text.ToBinary(body)])),
in
Source

in
   Source1



Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors