RESTful knowledge exchange
Post Reply
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Powershell with EM REST api V10

Post by masonit »

Hi

In version 9.5 I used to get session and query to rest api as below. But I can't get it to work in V10. How do you use rest api with powershell?

$headers = @{"X-Requested-With"="powershell"}
$baseuri = "https://<EM>:9398/api"
Invoke-RestMethod -Uri "$baseuri/sessionMngr/?v=latest" -Method Post -SessionVariable sess -Credential $credentials
Invoke-RestMethod -Headers $headers -Uri "$baseuri/backupservers" -Method Get -WebSession $sess

\Magnus
chris.arceneaux
VeeaMVP
Posts: 667
Liked: 358 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Powershell with EM REST api V10

Post by chris.arceneaux » 4 people like this post

Hi Magnus,

Key here is Invoke-RestMethod will not work for you during auth as this cmdlet doesn't return response headers. Per our documentation, the Session ID you need is located in the response headers.

As subsequent calls don't require response headers, using Invoke-RestMethod works just fine (see below).

Here's an example of what this would look like:

Code: Select all

# Authorization
$credentials = Get-Credential
$response = Invoke-WebRequest "https://<EM>:9398/api/sessionMngr/?v=latest" -Method Post -Credential $credentials

# Use Session ID for further API calls
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("X-RestSvcSessionId", $response.Headers["X-RestSvcSessionId"])
$response = Invoke-RestMethod "https://<EM>:9398/api/jobs" -Method Get -Headers $headers
# Show all Jobs
$response.EntityReferences.Ref
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Powershell with EM REST api V10

Post by masonit »

Worked great, thanks!

\Magnus
masonit
Service Provider
Posts: 325
Liked: 23 times
Joined: Oct 09, 2012 2:30 pm
Full Name: Maso
Contact:

Re: Powershell with EM REST api V10

Post by masonit »

Hi

I can see "UsedQuotaMb" from /vCloud/orgConfigs/<org>. Is it also possible to collect data about number of protected vapps, vms etc? As can be seen in web ui.

\Magnus
chris.arceneaux
VeeaMVP
Posts: 667
Liked: 358 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Location: Georgia, USA
Contact:

Re: Powershell with EM REST api V10

Post by chris.arceneaux »

Hi Magnus,

Good to hear my previous code samples worked for you. :D

Following the Job Status section in this post, you can find unique VM IDs of protected workloads during the billing period you're looking for. You'll look for VCD backup jobs (<Platform>vCloud</Platform>) and match their name using the job naming scheme: "<VCD Org Name>_<Tenant Specified Job Name>"

In the future, best to post new questions in a new thread. It makes it easier for newcomers to find answers.
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests