Hello @Studmuffn1134, welcome!
The provided python code will resembled yes however the path will be specific to the type and actions you need to perform. Also the returned payload will also be different.
You can find bellow some informations that can help you understand and use the Xen Orchestra API.
Here is a summary provided when searching with google about REST APIs patterns:
Understanding REST: A Guide to API Design Patterns
REST (Representational State Transfer) is a widely-used software architectural style that defines how APIs should be designed. It emphasizes simplicity, scalability, and efficiency, making it a popular choice for building web services and applications. REST APIs use standard HTTP methods (such as GET, POST, PUT, and DELETE) to interact with resources, which are identified by URLs. This approach makes REST APIs intuitive and easy to work with.
To get the most out of REST, it’s important to understand its patterns and conventions. These patterns will not only improve your foundational knowledge but also help you interact with APIs.
REST API Path Structure
A typical REST API path follows a structured format, often resembling this pattern:
http://host_or_domain_name/<types>/<id>/<action_verb>
Here’s a breakdown of the components:
-
<types>: Represents the type of resource you’re interacting with (e.g., vms, users, networks).
-
<id>: A unique identifier for a specific resource (e.g., a VM ID or user ID).
-
<action_verb>: Specifies the action to be performed on the resource (e.g., actions, start, stop).
HTTP Methods in REST
REST APIs use specific HTTP methods to perform operations on resources:
-
GET: Retrieves data. For example, fetching a list of resources or details of a specific resource.
-
POST: Creates a new resource.
-
PUT: Replaces or updates an entire resource.
-
PATCH: Updates specific parts of a resource.
-
DELETE: Removes a resource.
Example: REST API Paths for Virtual Machines (VMs)
Let’s look at some examples using a vms resource type:
List all VMs:
GET http://host/rest/v0/vms
This returns a list of VM IDs.
Get details of a specific VM:
GET http://host/rest/v0/vms/<id>
This returns detailed information about the VM with the specified ID.
List available actions for a VM:
GET http://host/rest/v0/vms/<id>/actions
This returns all actions that can be performed on the specified VM (e.g., start, stop, reboot).
Perform an action on a VM:
POST http://host/rest/v0/vms/<id>/actions/<your-action>
This performs the specified action (e.g., start, stop) on the VM.
Exploring Available REST Endpoints
If you’re working with a REST API like Xen Orchestra, you can explore the available endpoints by navigating to the base URL in your browser or using a tool like Postman. For example:
GET http://host/rest/v0
This will return a list of available resource types and operations, such as:
[
"/rest/v0/hosts",
"/rest/v0/messages",
"/rest/v0/networks",
"/rest/v0/pifs",
"/rest/v0/pools",
"/rest/v0/srs",
"/rest/v0/vbds",
"/rest/v0/vdi-snapshots",
"/rest/v0/vdis",
"/rest/v0/vifs",
"/rest/v0/vm-controllers",
"/rest/v0/vm-snapshots",
"/rest/v0/vm-templates",
"/rest/v0/vms",
"/rest/v0/backup",
"/rest/v0/groups",
"/rest/v0/restore",
"/rest/v0/tasks",
"/rest/v0/servers",
"/rest/v0/users",
"/rest/v0/dashboard",
"/rest/v0/alarms",
"/rest/v0/docs"
]
From here, you can follow the REST patterns described above to query specific resources or perform actions.
Hope this help! 