GODADDY Library

The GODADDY Library is an importable library you can use in your projects designed to help you manage and update your GoDaddy DNS records via the GoDaddy DNS APIs. It is used by the GoDaddy DNS Adapter.

How it works:

Use the Translator’s built in help to review how to use each function:

GODADDYclient creates the GoDaddy adapter framework.

GODADDYaddarecord and GODADDYaddcname modules are defined in a metatable as methods and set to the S object. The GoDaddy API key and password from the component’s Custom Fields are assigned to the new S table so that they can be used by the methods.

local MT={} MT.__index = {} MT.__index.addcname = require 'GODADDY.GODADDYaddcname' MT.__index.custom = require 'GODADDY.GODADDYcustom' MT.__index.addarecord = require 'GODADDY.GODADDYaddarecord' help.map{dir='GODADDY/help',methods=MT.__index} function GODADDYclient() S= {} setmetatable(S, MT) S.key = component.fields().key S.password = component.fields().password return S end

Concepts used:

GODADDYcustom is a helper function designed to handle different API requests with GoDaddy.

It prepares the header with the authorization details and assigns the url endpoint and parameters prepared by the GODADDY method functions. net.http.patch{} is used to send the request to GoDaddy. If successful, true is returned, otherwise false along with the parsed error response and code are returned.

The firs time you run the command to add an A or CNAME record, it will return true if successful, Subsequent calls with the same arguments will return ‘DUPLIATE_RECORD' as the record already exists.

local function GODADDYcustom(T, C) if (C.live ~= true) then return "notlive" end local Headers = {} Headers.Authorization = "sso-key "..T.key..":"..T.password Headers['Content-Type'] = "application/json" local Url = component.fields().apiurl..C.api local R, Code = net.http.patch{url=Url, headers=Headers, data=C.data, live=C.live} if Code == 422 then R = json.parse{data=R} return false, R.errors, R.code elseif Code == 200 then return true end end return GODADDYcustom

Concepts used:

There are two methods included in the library:

A record (Address) is a type of DNS record used to map a domain or subdomain to an IPv4 address. It contains the information needed to direct your request to the correct server.

The GODADDYaddarecord function is passed the client object T and a table of defined parameters from the function call in main. The arguments required to add an A record to the GoDaddy DNS Record table are defined, formated and passed to GODADDYcustom to send the request.

local function GODADDYaddarecord(T, args) args.type = 'A' args.api = 'domains/'..component.fields().domain..'/records' args.live = true args.data = '[{"type": "'..args.type..'","name": "'..args.name..'","data": "'..args.ip..'","ttl": 3600}]' return T:custom(args) end return GODADDYaddarecord

Concepts used:

CNAME record (Canonical Name) is used to alias one domain name to another.

The GODADDYaddcname functions the same as GODADDYaddarecord. The function is passed the client object T and a table of defined parameters from the function call in main. The arguments required to add an CNAME record to the GoDaddy DNS Record table are defined, formated and passed to GODADDYcustom to send the request.

Concepts used:

 

Related pages