Skip to content

API Examples ​

Examples for tasks that have no reference page of their own.

Setup ​

The examples read your token from GIGAHOST_TOKEN:

bash
export GIGAHOST_TOKEN="your-token-here"

Firewall ​

Virtual servers only. The posted rule set replaces every existing rule; send the complete list each time.

Get Current Firewall Rules ​

bash
curl -s https://api.gigahost.no/api/v0/servers/42/firewall \
  -H "Authorization: Bearer $GIGAHOST_TOKEN" \
  | jq '.data'

data.options holds enable and the policies as booleans (true = ACCEPT), data.rules the rules in position order.

Set Firewall Rules ​

Allow SSH, HTTP and HTTPS in, drop everything else:

bash
curl -X POST https://api.gigahost.no/api/v0/servers/42/firewall \
  -H "Authorization: Bearer $GIGAHOST_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "enable": true,
    "default_action": false,
    "rules": [
      {
        "type": "in",
        "action": "ACCEPT",
        "proto": "tcp",
        "dport": "22",
        "comment": "SSH"
      },
      {
        "type": "in",
        "action": "ACCEPT",
        "proto": "tcp",
        "dport": "80"
      },
      {
        "type": "in",
        "action": "ACCEPT",
        "proto": "tcp",
        "dport": "443"
      }
    ]
  }'
FieldTypeDescription
enablebooleanFirewall on or off.
default_actionbooleanInbound policy for traffic that matches no rule: true = ACCEPT, false = DROP. Outbound policy is always ACCEPT.
rulesarrayRules in the order they should be evaluated.
rules[].typestringin or out.
rules[].actionstringACCEPT or DROP.
rules[].protostringProtocol, e.g. tcp or udp.
rules[].dportstringDestination port.
rules[].commentstringOptional.

pos, log and ipversion are ignored if sent. Spaces in dport, sport, source and dest are removed, so 80, 443 becomes 80,443. A successful call returns 200 with an empty data.

The rules are applied together. If one is refused, the previous rules are restored and the call returns 400 naming the rule by its position in your rules array, for example Firewall rule 3 was rejected (invalid dport). No changes were saved.

If outbound SMTP is blocked on the server, enable cannot be false and the rule set must keep the two out / DROP rules for ports 25 and 465, or the request is rejected.

Billing ​

Invoices are listed by GET /billing.

Download Invoice PDF ​

{inv_md5} is the inv_md5 value of the invoice.

bash
curl -s https://api.gigahost.no/api/v0/billing/invoice/$INV_MD5 \
  -H "Authorization: Bearer $GIGAHOST_TOKEN" \
  | jq -r '.data.data' | base64 -d > invoice.pdf

data.filename holds the suggested file name and data.data the base64-encoded PDF.

Pay an Invoice ​

Charges the account's default payment method. payment_id is optional and selects another payment method on the account.

bash
curl -X POST https://api.gigahost.no/api/v0/billing/charge \
  -H "Authorization: Bearer $GIGAHOST_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"inv_id": 12345}'

A completed payment returns message: "Invoice has been paid successfully." in meta. Card and PayPal checkout flows that need confirmation in a browser return client_secret in meta instead.

Support Tickets ​

List Tickets ​

bash
curl -s https://api.gigahost.no/api/v0/tickets \
  -H "Authorization: Bearer $GIGAHOST_TOKEN" \
  | jq '.data'

Each entry has ticket_id, subject, created_at, last_reply_at and status.

Create a Ticket ​

bash
curl -X POST https://api.gigahost.no/api/v0/tickets \
  -H "Authorization: Bearer $GIGAHOST_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "subject": "Network issue on server 42",
    "message": "I am seeing packet loss on eth0 since 14:00 UTC.",
    "srv_id": 42
  }'

srv_id is optional and is ignored if the server is not on your account. An account can have at most 10 open tickets.

Reply to a Ticket ​

bash
curl -X POST https://api.gigahost.no/api/v0/tickets/789 \
  -H "Authorization: Bearer $GIGAHOST_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"reply": "The issue started after the latest kernel update."}'

Replying to a closed ticket reopens it.

Scripting Examples ​

Bash: Reboot All Servers ​

bash
#!/bin/bash
TOKEN="$GIGAHOST_TOKEN"
API="https://api.gigahost.no/api/v0"

# Get all server IDs
SERVER_IDS=$(curl -s "$API/servers" \
  -H "Authorization: Bearer $TOKEN" \
  | jq -r '.data[].srv_id')

for ID in $SERVER_IDS; do
  echo "Rebooting server $ID..."
  curl -s "$API/servers/$ID/reboot" \
    -H "Authorization: Bearer $TOKEN" > /dev/null
  echo "Done."
done

Bash: Export All DNS Zones and Records ​

bash
#!/bin/bash
TOKEN="$GIGAHOST_TOKEN"
API="https://api.gigahost.no/api/v0"

ZONES=$(curl -s "$API/dns/zones" \
  -H "Authorization: Bearer $TOKEN" \
  | jq -r '.data[] | "\(.zone_id) \(.zone_name)"')

while read -r ZONE_ID ZONE_NAME; do
  echo "=== $ZONE_NAME ==="
  curl -s "$API/dns/zones/$ZONE_ID/records" \
    -H "Authorization: Bearer $TOKEN" \
    | jq -r '.data[] | "\(.record_name)\t\(.record_ttl)\t\(.record_type)\t\(.record_value)"'
  echo ""
done <<< "$ZONES"

Python: List Servers ​

python
import requests

API = "https://api.gigahost.no/api/v0"
TOKEN = "your-token-here"

headers = {"Authorization": f"Bearer {TOKEN}"}

response = requests.get(f"{API}/servers", headers=headers)
servers = response.json()["data"]

for server in servers:
    print(f"{server['srv_id']}: {server['srv_name']} ({server['srv_status']})")

Python: Update DNS Record ​

python
import requests

API = "https://api.gigahost.no/api/v0"
TOKEN = "your-token-here"
headers = {
    "Authorization": f"Bearer {TOKEN}",
    "Content-Type": "application/json",
}

zone_id = 100
record_id = 500

response = requests.put(
    f"{API}/dns/zones/{zone_id}/records/{record_id}",
    headers=headers,
    json={
        "record_value": "203.0.113.50",
        "record_ttl": 1800,
    },
)

print(response.json())

Gigahost Docs

This site is currently in development.
Enter the password to continue.