I'm trying to add an A record to a domain using GoDaddy's API, but I'm getting a 422 (Unprocessable Entity) response error in the console of my browser. However, when I test the request using GoDaddy's documentation on https://developer.godaddy.com/doc#!/_v1_domains/recordAdd/ArrayOfDNSRecord I get a 404 response error with the body below:
Body of error response:
{
"code": "UNKNOWN_DOMAIN",
"message": "The given domain is not registered, or does not have a zone file",
"name": "_Class"
}
The domain I'm trying to add the A record to definitely exists, so I don't know why it would return a 404 error. I have no problem retrieving all of the A records belonging to the domain using a GET request, but when I try to run the PATCH request below I get the errors.
Is there something wrong with GoDaddy's API or is there an issue with how I'm structuring my request?
PATCH request that returns error
$.ajax({
type: 'PATCH',
url: 'https://api.godaddy.com/v1/domains/{domain}/records',
data: {
'records': [{
'type': 'A',
'name': 'test',
'data': '255.255.255.255'
}]
},
headers: {
'Authorization': 'sso-key {API_KEY}:{API_SECRET}'
},
success: function(body) {
console.log(body);
}
});
GET request that works fine
$.ajax({
type: 'GET',
url: 'https://api.godaddy.com/v1/domains/{domain}/records/A',
headers: {
'Authorization': 'sso-key {API_KEY}:{API_SECRET}'
},
success: function(body) {
$.each(body, function(i, v) {
$('body').append('<p>Name: ' + v.name + '<br/>Data: ' + v.data + '</p>');
});
}
});
You need to specify the domain too:
$.ajax({
type: 'PATCH',
url: 'https://api.godaddy.com/v1/domains/{domain}/records',
data: {
'domain': '<domain>',
'records': [{
'type': 'A',
'name': 'test',
'data': '255.255.255.255'
}]
},
headers: {
'Authorization': 'sso-key {API_KEY}:{API_SECRET}'
},
success: function(body) {
console.log(body);
}
});
Also note that the optional ttl field needs to be at least 600.