package main
import(
"context"
"os"
latitudeshgosdk "github.com/latitudesh/latitudesh-go-sdk"
"github.com/latitudesh/latitudesh-go-sdk/models/components"
"log"
)
func main() {
ctx := context.Background()
s := latitudeshgosdk.New(
latitudeshgosdk.WithSecurity(os.Getenv("LATITUDESH_BEARER")),
)
res, err := s.VirtualMachines.UpdateVirtualMachine(ctx, "vm_7vYAZqGBdMQ94", components.VirtualMachineUpdatePayload{
Data: components.VirtualMachineUpdatePayloadData{
Type: components.VirtualMachineUpdatePayloadTypeVirtualMachines,
ID: latitudeshgosdk.Pointer("vm_7vYAZqGBdMQ94"),
Attributes: components.VirtualMachineUpdatePayloadAttributes{
Name: "my-updated-vm",
},
},
})
if err != nil {
log.Fatal(err)
}
if res.VirtualMachine != nil {
// handle response
}
}{
"data": {
"id": "vm_7vYAZqGBdMQ94",
"type": "virtual_machines",
"attributes": {
"name": "my-updated-vm",
"status": "Running",
"created_at": "2026-01-14T15:57:15+00:00",
"primary_ipv4": "10.0.0.25",
"operating_system": null,
"site": "london-2193",
"billing": "hourly",
"plan": {
"id": "plan_VE1Wd3VQOXnZJ",
"name": "c3.small.x86-143"
},
"specs": {
"vcpu": 16,
"ram": "128 GB",
"storage": "100 GB",
"nic": "1 x 1 Gbps",
"gpu": "1 x NVIDIA H100 Tensor Core GPU"
},
"team": {
"id": "team_GpZboxNev1U2pxpmKwWAc8e01vpp",
"name": "702 Team",
"slug": "702-team",
"description": "702 Team",
"address": "Suite 729 8171 Albina Forges, Eldridgeberg, CA 26345-3293",
"status": "verified",
"currency": {
"id": "cur_AW6Q2D9lqKLpr",
"code": "BRL",
"name": "Brazilian Real",
"currency_id": null
}
},
"project": {
"id": "proj_W6Q2D9ZQOKLpr",
"name": "Aerodynamic Wool Watch",
"slug": "aerodynamic-wool-watch",
"description": "Intelligent Paper Shirt",
"billing_type": "Normal",
"billing_method": "Normal",
"bandwidth_alert": false,
"environment": null,
"billing": {
"subscription_id": null,
"type": "Normal",
"method": "Normal"
},
"stats": {
"databases": 0,
"ip_addresses": 0,
"prefixes": 0,
"servers": 0,
"storages": 0,
"virtual_machines": 1,
"vlans": 0
}
}
}
}
}Updates a Virtual Machine’s display name (hostname).
package main
import(
"context"
"os"
latitudeshgosdk "github.com/latitudesh/latitudesh-go-sdk"
"github.com/latitudesh/latitudesh-go-sdk/models/components"
"log"
)
func main() {
ctx := context.Background()
s := latitudeshgosdk.New(
latitudeshgosdk.WithSecurity(os.Getenv("LATITUDESH_BEARER")),
)
res, err := s.VirtualMachines.UpdateVirtualMachine(ctx, "vm_7vYAZqGBdMQ94", components.VirtualMachineUpdatePayload{
Data: components.VirtualMachineUpdatePayloadData{
Type: components.VirtualMachineUpdatePayloadTypeVirtualMachines,
ID: latitudeshgosdk.Pointer("vm_7vYAZqGBdMQ94"),
Attributes: components.VirtualMachineUpdatePayloadAttributes{
Name: "my-updated-vm",
},
},
})
if err != nil {
log.Fatal(err)
}
if res.VirtualMachine != nil {
// handle response
}
}{
"data": {
"id": "vm_7vYAZqGBdMQ94",
"type": "virtual_machines",
"attributes": {
"name": "my-updated-vm",
"status": "Running",
"created_at": "2026-01-14T15:57:15+00:00",
"primary_ipv4": "10.0.0.25",
"operating_system": null,
"site": "london-2193",
"billing": "hourly",
"plan": {
"id": "plan_VE1Wd3VQOXnZJ",
"name": "c3.small.x86-143"
},
"specs": {
"vcpu": 16,
"ram": "128 GB",
"storage": "100 GB",
"nic": "1 x 1 Gbps",
"gpu": "1 x NVIDIA H100 Tensor Core GPU"
},
"team": {
"id": "team_GpZboxNev1U2pxpmKwWAc8e01vpp",
"name": "702 Team",
"slug": "702-team",
"description": "702 Team",
"address": "Suite 729 8171 Albina Forges, Eldridgeberg, CA 26345-3293",
"status": "verified",
"currency": {
"id": "cur_AW6Q2D9lqKLpr",
"code": "BRL",
"name": "Brazilian Real",
"currency_id": null
}
},
"project": {
"id": "proj_W6Q2D9ZQOKLpr",
"name": "Aerodynamic Wool Watch",
"slug": "aerodynamic-wool-watch",
"description": "Intelligent Paper Shirt",
"billing_type": "Normal",
"billing_method": "Normal",
"bandwidth_alert": false,
"environment": null,
"billing": {
"subscription_id": null,
"type": "Normal",
"method": "Normal"
},
"stats": {
"databases": 0,
"ip_addresses": 0,
"prefixes": 0,
"servers": 0,
"storages": 0,
"virtual_machines": 1,
"vlans": 0
}
}
}
}
}Was this page helpful?