API Request
Copy
const apiUrl = "https://your_nexus_server_or_ip/api/v3/";
//JSON data to be sent
const data = {
"id": "V7eff7bce3-xxxx-xxxx-xxxx-7e49xxxxx1122",
"cloudid": "V7dcf7bce3-xxxx-xxxx-xxxx-7e49xxxxx1148",
"name": "myvm",
"boot": "hd",
"mac": "18:27:F6:35:0F:56",
"network": "xcNET",
"cpu": 1,
"ram": 2,
"disk": 20,
"driver": "driver-virtio",
"gpu": "vga",
"sound": true,
"tpm": false
};
const requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-access-account": "YOUR_ACCOUNT_ID",
"x-access-authorization": "YOUR_ACCESS_KEY",
"x-secret-key": "YOUR_SECRET_KEY",
"x-api": "API_NAME",
"x-api-command": "API_COMMAND"
},
body: JSON.stringify(data),
};
fetch(apiUrl, requestOptions)
.then((response) => {
if (!response.ok) {
throw new Error("Connection error");
}
return response.json();
})
.then((data) => {
//process received JSON data
console.log(JSON.stringify(data, null, 4));
if (data.result == "OK") {
console.log("TASK SUCCESSFUL");
} else {
console.log("ERROR: " + data.message);
}
})
.catch((error) => {
console.log("Error: " + error);
});