Forum Discussion
How to run POST request in M?
- 8 years ago
Adding an empty string as the Content-parameter does the trick for me:
Content=Text.ToBinary("")Although the query will then return an error. the refresh actually was successful:
- 8 years ago
Hi ImkeF,
You are correct. It is working for me as well. Thank you!
And to avoid this error we need to add any extra step to return some value.
Here is the final code for this case:
let vToken = AuthorizationToken, vUrl = "https://api.powerbi.com/v1.0/myorg/groups/" & WorkspaceID & "/datasets/" & DatasetID & "/refreshes", Source = Json.Document(Web.Contents(vUrl, [Headers=[Authorization=vToken],Content=Text.ToBinary("")])), result = 1 in resultwhere AuthorizationToken, WorkspaceID and DatasetID are parameters.
Regards,
Ruslan
Adding an empty string as the Content-parameter does the trick for me:
Content=Text.ToBinary("")
Although the query will then return an error. the refresh actually was successful:
Hi ImkeF,
You are correct. It is working for me as well. Thank you!
And to avoid this error we need to add any extra step to return some value.
Here is the final code for this case:
let
vToken = AuthorizationToken,
vUrl = "https://api.powerbi.com/v1.0/myorg/groups/" & WorkspaceID & "/datasets/" & DatasetID & "/refreshes",
Source = Json.Document(Web.Contents(vUrl, [Headers=[Authorization=vToken],Content=Text.ToBinary("")])),
result = 1
in
resultwhere AuthorizationToken, WorkspaceID and DatasetID are parameters.
Regards,
Ruslan
- ImkeF8 years agoCommunity Champion
Hi Ruslan zoloturu,
be careful here: M is a paritally lazy language. That means that in most cases, only those steps will be evaluated who are necessary for the end result. So the refresh will actually not take place if you refresh the query from the main menu.
But it's a good step to prevent undesired refreshes during query design (there is still the limit of max. 8 refreshes within 24 hours).
So it depends on how you want to trigger the refreshes whether it makes sense to keep the last step or not.
Cheers, Imke
- zoloturu8 years agoMemorable Member
Hi Imke ImkeF,
It is an interesting point. During the last 2 years, I didn't have such problems with M. It will be interesting to see if you have an example of such behavior or documentation explaining that. Then it can help readers of this thread to be ready for such situations. I think if there will be such a possibility, I will try to implement some check. In this case, there can be the same GET request but without the Content part and it will return refresh history. You can make it as a function and invoke it to DatasetID. So then you can see if your refresh has proceeded.
Here is an example of such function:
let fnRefreshHistoryByDataset = (WorkspaceID as text, DatasetID as text) => let Source = Json.Document(Web.Contents("https://api.powerbi.com/v1.0/myorg/groups/" & WorkspaceID & "/datasets/" & DatasetID & "/refreshes", [Headers=[Authorization=AuthorizationToken]])), value = Source[value], ToTable = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error), ExpandColumns = Table.ExpandRecordColumn(ToTable, "Column1", {"id","refreshType", "startTime", "endTime", "status"}, {"id","refreshType", "startTime", "endTime", "status"}) in ExpandColumns in fnRefreshHistoryByDatasetAnd yes, indeed. There are 8 refreshes during 24 hours on shared capacity and 48 refreshes when you have dedicated one (Premium or Embedded). But a question here was just to try if it is possible to run POST request to run some action.
Regards,
Ruslan
- Skabo_Wenco3 years agoRegular Visitor
Thank you for providing the code needed to force Power BI to make "POST" requests, and deal with the error. I have been searching for this answer for 2 years!