Here's a script I used for quickly adding google MX and SPF records. (The domain ID is not the domain itself, it's the UUID.)
from requests.auth import AuthBase
import requests
import json
TOKEN = "TOKENHERE"
DOMAIN_ID = "DOMAIN-ID-HERE"
SPF_VALUE = "v=spf1 include:_spf.google.com ~all"
DNS_RECORDS = [
{
"domain": DOMAIN_ID,
"type": "TXT",
"content": SPF_VALUE,
"priority": 10,
"ttl": 3600
},
{
"domain": DOMAIN_ID,
"type": "MX",
"content": "ASPMX.L.GOOGLE.COM",
"priority": 1,
"ttl": 3600
},
{
"domain": DOMAIN_ID,
"type": "MX",
"content": "ALT1.ASPMX.L.GOOGLE.COM",
"priority": 5,
"ttl": 3600
},
{
"domain": DOMAIN_ID,
"type": "MX",
"content": "ALT2.ASPMX.L.GOOGLE.COM",
"priority": 5,
"ttl": 3600
},
{
"domain": DOMAIN_ID,
"type": "MX",
"content": "ALT3.ASPMX.L.GOOGLE.COM",
"priority": 10,
"ttl": 3600
},
{
"domain": DOMAIN_ID,
"type": "MX",
"content": "ALT4.ASPMX.L.GOOGLE.COM",
"priority": 10,
"ttl": 3600
}
]
class TokenAuth(AuthBase):
"""Attaches HTTP Token Authentication to the given Request object."""
def __init__(self, token):
# setup any auth-related data here
self.token = token
def __call__(self, r):
# modify and return the request
r.headers['Authorization'] = f"Token {self.token}"
r.headers['Content-Type'] = "application/json"
return r
r = requests.post(f'https://my.opalstack.com/api/v0/dnsrecord/add/',
auth=TokenAuth(TOKEN),
data=json.dumps(DNS_RECORDS))