Forum Discussion
Sending a POST API request using PowerQuery on Excel/PBI with a request body?
- Anonymous3 years ago
For anyone who it might help, I successfully solved this. Here is my code:
let url = "https://myapi.com/analytics", headers = [#"Content-Type"="application/json", #"X-Impersonate-User"=Impersonation_Token, Authorization="Bearer "&API_Key], body = "{""start_date"":""" & Start_Date &""",""end_date"":""" &End_Date &""",""time_resolution"":""" & Time_Dimension &"""}", response = Json.Document(Web.Contents(url, [ Headers = headers, Content = Text.ToBinary((body)) ])), in
Hi Anonymous
Please try below code
let
url = "https://myapi.com/data",
headers = [#"Content-Type"="application/json", #"X-Impersonate-User"="usr_12345", Authorization="Bearer xxxxxxxxxxxxxx"],
body = [
start_date = "2022-08-01T08:00:00.000Z",
end_date = "2022-08-10T08:00:00.000Z",
space_ids = "spc_12345",
time_resolution = "day"
],
response = Json.Document(Web.Contents(url,
[
Headers = headers,
Content = Text.ToBinary(Uri.BuildQueryString(body))
]))
in
response
Then it will pop up "Please specify how to connect." Click "Edit Credentials" and select Anonymous type.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
When I try that and click anonymous, I receive this error back from BI.
- v-jingzhang3 years agoCommunity Support
Hi Anonymous
Can you please capture screenshots of the POST request settings that is successful in Postman? Remember to remove sensitive data from them. I'd like to see if we have missed some settings in the query.
Best Regards,
Community Support Team _ Jing- Anonymous3 years agoNot applicable
Here are some screen-grabs from Postman.
- v-jingzhang3 years agoCommunity Support
Hi Anonymous
I made a small modification. Not sure if this works.
let url = "https://myapi.com/data", headers = [#"Content-Type"="application/json", #"X-Impersonate-User"="usr_12345", Authorization="Bearer xxxxxxxxxxxxxx"], body = [ start_date = "2022-08-01T08:00:00.000Z", end_date = "2022-08-10T08:00:00.000Z", space_ids = {"spc_12345", "spc_1234567"}, time_resolution = "day" ], response = Json.Document(Web.Contents(url, [ Headers = headers, Content = Text.ToBinary(Uri.BuildQueryString(body)) ])) in responseBest Regards,
Community Support Team _ Jing