How to Use vCenter Rest API [Basic Knowledge]

Have you heard of vCenter REST API which provides services to manage vCenter Appliance configuration? Today we are going to take a look at vCenter REST API.

Crystal

By Crystal / Updated on February 10, 2023

Share this: instagram reddit

What is vCenter REST API

The vCenter package provides services for managing VMware vSphere environments. vCenter REST API was first introduced in vSphere 6.5, which is a more modern, more straightforward-to-use, and more developer-friendly vSphere API.

REST API offers more than just discoverability of actions to the consumer. And on the provider side (the vendor), it offers the possibility to simplify their API. On top of that, since most REST API implementations are predominantly using HTTP(S) as a protocol, it also makes an architecture based on REST concepts more manageable for the network teams.

Last but not least, our preferred language of automation, PowerShell, makes consuming REST API via HTTP quite easy with the Invoke-RestMethod and Invoke-WebRequest cmdlets.

vcenter rest api

Sample: How to Use vCenter Rest API

Embedded in the vCSA, there is an API Explorer that allows you to access the documentation of the new REST APIs.

To get you started quickly, let’s dive into the authentication step to use vCenter rest API.

1. Authenticate to vCenter to get user credential.

a# curl -k -X POST https:///rest/com/vmware/cis/session -u : | jq
{
"value": "SESSIONID"
}

2. Save the session id to a variable

# ID=SESSIONID

3. Access the end point with the session id

# curl -k -X GET -H "vmware-api-session-id: $ID" https:/ //rest/vcenter/vm |jq
{
"value": [
{
"memory_size_MiB": 16384,
"vm": "vm-1",
"name": "VM01",
"power_state": "POWERED_ON",
"cpu_count": 4
}
{
"memory_size_MiB": 16384,
"vm": "vm-2",
"name": "VM02",
"power_state": "POWERED_ON",
"cpu_count": 4
}
]
}
# curl -k -X GET -H "vmware-api-session-id: $ID" https:///rest/vcenter/datastore |jq
{
"value": [
{
"datastore": "datastore-1",
"name": "DS1",
"type": "VMFS",
"free_space": 290276245504,
"capacity": 291789340672
},
{
"datastore": "datastore-2",
; "name": "DS2",
"type": "VMFS",
"free_space": 3349917204480,
"capacity": 3599451029504
}
]
}

After accessing vCSA at the address https:///apiexplorer to reach the API Explorer, click on the Select API drop-down menu and select the available endpoints, as shown in the vsphere-automation document.

The vSphere API provides an interface for users to access the features and functionality of the vSphere platform, including vCenter Server and ESXi hosts. Features such as host management, virtual machine configuration, and monitoring are exposed from vCenter Server and ESXi as Web Services APIs. Depending on the functionality, some features of the API will only be available on vCenter Server (such as virtual machine cloning or Storage DRS).

In addition to the points mentioned above, data security is also an issue that cannot be ignored, especially for virtual machines that carry important data. However, since the commonly used VMware snapshot feature is actually only suitable for creating restore points before dangerous operations and not for long-term storage, we usually still need to use professional vSphere backup software for VM protection.

Tips: Backup Virtual Machines Under vCenter for Data Protection

vCenter can manage numerous virtual machines, but to offer complete VM protection, many IT staff prefer a specialized backup software such as AOMEI Cyber Backup, a VMware backup software, which is professional and reliable for VMware and Hyper-V virtual machine backup.

With AOMEI Cyber Backup, you can automate the backup process of multiple VMs managed by vCenter Server, and choose to send email notifications if there's an error.

Image-level VM Backup: independent image-level VM backups can be used to create new VMs.
Batch vSphere Backup: batch backup large numbers of VMs managed by vCenter Server, or multiple VMs on a standalone ESXi host.
Automated Execution: create backup schedules to automate virtual machine protection.
Restore Entire VM: restore immediately available VMs from any selected restore points.

AOMEI Cyber Backup supports VMware ESXi 6.0 and later versions. Next, I will demonstrate how to perform backup of multiple VMware ESXi VMs. You can click the following button to download the 30-day free trial.

Download Free TrialVMware ESXi & Hyper-V
Secure Download

4 Simple Steps to Backup Multiple vCenter VMs

1. Bind Devices: Access to AOMEI Cyber Backup web client, navigate to Source Device > VMware > + Add VMware Device to Add vCenter or Standalone ESXi host. And then click  > Bind Device.

bind device

2. Create Backup Task: Navigate to Backup Task > + Create New Task, and select VMware ESXi Backup as the Backup Type.

create backup task

3. Set Task NameDeviceTargetSchedule, and Cleanup as needed.

▶ Device: navigate to the vCenter Server and select a datastorecenter, it will show all the VMs on the right pane. With one click, you can easily backup multiple virtual machines.

▶ Target: selecting to back up to a local path, or to a network path. Used paths will be saved in Favorite Storage for handy selection.

▶ Schedule (optional): performing full, differential or incremental backup, and automate execution daily, weekly or monthly according to the frequency you specified.

▶ Backup cleanup (optional): Configure a retention policy to auto delete old backup files and save storage space.

backup cleanup

▶ Start Backup: You can click Start Backup and select to Add the schedule and start backup now, or Add the schedule only.

start backup

Created backup tasks will be listed and monitored separately, for restoring, progress checking and schedule changing.

4. Restore: Click Restore to recover a virtual machine from backup, saving the trouble of re-configuring the new VM.

Once the backup task is created, it will be executed automatically according to your schedule. If you want to restore a virtual machine, you can click Restore and choose to restore entire VM to an available state from any historical restore point.

In addition to restoring a VM to its original location, you can also choose Restore to new location, which will create a new, identical VM directly from your backup to the target location.

restore vm

Summary

You could access vCenter REST API following the steps in this article. With vCenter REST API, it's convenient to get the VM information on official documentation and the subresource of VM such as disk, cdrom, sata_adapter, etc.

Crystal
Crystal · Editor
Crystal is an editor from AOMEI Technology. She mainly writes articles about virtual machine. She is a positive young lady likes to share articles with peolpe. Off work she loves travelling and cooking which is wonderful for life.