Skip to main content
POST
/
project
/
{project_id}
/
location
/
{location}
/
load-balancer
/
{load_balancer_reference}
/
attach-vm
Attach a VM to a load balancer
curl --request POST \
  --url https://api.ubicloud.com/project/{project_id}/location/{location}/load-balancer/{load_balancer_reference}/attach-vm \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "vm_id": "<string>"
}
'
import requests

url = "https://api.ubicloud.com/project/{project_id}/location/{location}/load-balancer/{load_balancer_reference}/attach-vm"

payload = { "vm_id": "<string>" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({vm_id: '<string>'})
};

fetch('https://api.ubicloud.com/project/{project_id}/location/{location}/load-balancer/{load_balancer_reference}/attach-vm', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.ubicloud.com/project/{project_id}/location/{location}/load-balancer/{load_balancer_reference}/attach-vm",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'vm_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.ubicloud.com/project/{project_id}/location/{location}/load-balancer/{load_balancer_reference}/attach-vm"

payload := strings.NewReader("{\n \"vm_id\": \"<string>\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.ubicloud.com/project/{project_id}/location/{location}/load-balancer/{load_balancer_reference}/attach-vm")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"vm_id\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.ubicloud.com/project/{project_id}/location/{location}/load-balancer/{load_balancer_reference}/attach-vm")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"vm_id\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "algorithm": "<string>",
  "dst_port": 123,
  "health_check_endpoint": "<string>",
  "health_check_protocol": "<string>",
  "hostname": "<string>",
  "id": "1bhw8r4pn73t1m5f7rn7a5pej2",
  "location": "<string>",
  "name": "<string>",
  "src_port": 123,
  "subnet": "<string>",
  "vms": [
    {
      "boot_image": "<string>",
      "id": "vmhfy8gff8c67hasb0eez2k1pd",
      "ip4": "127.0.0.1",
      "ip4_enabled": true,
      "ip6": "2606:4700:3108::ac42:2835",
      "location": "eu-central-h1",
      "name": "my-vm-name",
      "size": "<string>",
      "state": "<string>",
      "storage_size_gib": 123,
      "unix_user": "<string>"
    }
  ],
  "stack": "<string>",
  "cert_enabled": true
}
{
"error": {
"code": 401,
"message": "There was an error logging in",
"type": "InvalidCredentials",
"details": {}
}
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

project_id
string
required

ID of the project

Pattern: ^pj[0-9a-hj-km-np-tv-z]{24}$
Example:

"pjkkmx0f2vke4h36nk9cm8v8q0"

location
string
required

The Ubicloud location/region

Example:

"eu-central-h1"

load_balancer_reference
string
required

Load balancer ID or name Resource ID or name

Pattern: ^[a-z0-9](?:[a-z0-9\-]{0,61}[a-z0-9])?$

Body

application/json
vm_id
string
required

Apid of VM to attach to Load Balancer

Response

A Load Balancer

algorithm
string
required

Algorithm of the Load Balancer

dst_port
integer
required

Destination port for the Load Balancer

health_check_endpoint
string
required

Health check endpoint URL

health_check_protocol
string
required

Health check endpoint protocol

hostname
string
required

Hostname of the Load Balancer

id
string
required

ID of the Load Balancer

Pattern: ^1b[0-9a-hj-km-np-tv-z]{24}$
Example:

"1bhw8r4pn73t1m5f7rn7a5pej2"

location
string
required

Location of the Load Balancer

name
string
required

Name of the Load Balancer

src_port
integer
required

Source port for the Load Balancer

subnet
string
required

Subnet of the Load Balancer

vms
object[]
required
stack
string

Networking stack of the Load Balancer (ipv4, ipv6, or dual)

cert_enabled
boolean

Whether SSL certificate is enabled