Forum Discussion
Get VMs from VCenter via API
- Anonymous6 years ago
I found the solution.
For everyone who need to get vm data from the VCenter API.
let
MyToken = let
body = Text.ToBinary(""),
url = "https://%VCenter%/rest/com/vmware/cis/session",
options = [
Headers =
[#"Content-type"="application/json",
Authorization="Basic %BASE64 encoded username password%",
Accept="application/json"
],
Content=body
],
result = Json.Document(Web.Contents(url, options)),
#"Converted to Table" = Record.ToTable(result),
#"Removed Columns" = Table.RemoveColumns(#"Converted to Table",{"Name"}),
Value = #"Removed Columns"{0}[Value]
in
Value,
Source = Json.Document(Web.Contents("https://%VCenter%/rest/vcenter/vm", [Headers=[#"vmware-api-session-id"=MyToken, Accept="application/json"]])),
value = Source[value],
#"Converted to Table" = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"memory_size_MiB", "vm", "name", "power_state", "cpu_count"}, {"Column1.memory_size_MiB", "Column1.vm", "Column1.name", "Column1.power_state", "Column1.cpu_count"})
in
#"Expanded Column1"
I found the solution.
For everyone who need to get vm data from the VCenter API.
let
MyToken = let
body = Text.ToBinary(""),
url = "https://%VCenter%/rest/com/vmware/cis/session",
options = [
Headers =
[#"Content-type"="application/json",
Authorization="Basic %BASE64 encoded username password%",
Accept="application/json"
],
Content=body
],
result = Json.Document(Web.Contents(url, options)),
#"Converted to Table" = Record.ToTable(result),
#"Removed Columns" = Table.RemoveColumns(#"Converted to Table",{"Name"}),
Value = #"Removed Columns"{0}[Value]
in
Value,
Source = Json.Document(Web.Contents("https://%VCenter%/rest/vcenter/vm", [Headers=[#"vmware-api-session-id"=MyToken, Accept="application/json"]])),
value = Source[value],
#"Converted to Table" = Table.FromList(value, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"memory_size_MiB", "vm", "name", "power_state", "cpu_count"}, {"Column1.memory_size_MiB", "Column1.vm", "Column1.name", "Column1.power_state", "Column1.cpu_count"})
in
#"Expanded Column1"
I'm quite new to PowerBi and PowerBi Desktop, could you please explain a bit how this should be implemented? Is the text you sent the content of a blank query? How the %VCenter% and credentials variables or parameters are managed? Could this work using an on-premise data gateway to connect to an on-premise vCenter?
Thank you in advance for the tips!
Òscar