import requests
import json
import os

VULTR_API_KEY = os.environ.get("VULTR_API_KEY")
DOMAIN = "oncloud.my.id"

headers = {
    "Authorization": f"Bearer {VULTR_API_KEY}",
    "Content-Type": "application/json"
}

print(f"Creating record btlabel.app.{DOMAIN} -> 103.138.63.186")

data = {
    "name": "btlabel.app",
    "type": "A",
    "data": "103.138.63.186",
    "ttl": 300
}

response = requests.post(f"https://api.vultr.com/v2/domains/{DOMAIN}/records", headers=headers, json=data)

if response.status_code == 201:
    print("Record created successfully!")
    print(json.dumps(response.json(), indent=2))
else:
    print(f"Error ({response.status_code}): {response.text}")
