Forum Discussion
M - Date Format YYYY-MM-DD in Query while sending request to an API
Hi, what worked for me to make Date dynamic in API was the following:
Before:
= Json.Document(Web.Contents("https://LINK/?from_date=2022-01-01&to_date=2024-01-31", [Headers=[Accept="TOKEN"]]))
After:
= Json.Document(Web.Contents("https://LINK/?from_date=2022-01-01&to_date=" & Today, [Headers=[Accept="TOKEN"]]))
Basically, you make necessary calculations with date intelligence in M as usual (starting from basic today) and save it as separate Query - in my case for ease of understanding I used "Today", then you make changes in your API string as shown above (remove manual date and add & with your supporting Query name (Today).
Sample Today query for reference below, note I have formatted it as per text format requirements in API:
= Date.ToText(DateTime.Date(DateTime.LocalNow()), "yyyy-MM-dd")
Hope that works for you guys!