10

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>');
    });
  }
});
Daniel Darabos
  • 25,678
  • 9
  • 94
  • 106
PurpleTurtle
  • 101
  • 1
  • 4
  • 1
    Same issue here, except I'm sending the request from Python. Can someone post an answer with such a `PATCH` request? I have found examples of `PUT` requests that I assume work, but they either update an existing record or replace the whole zone file. I want to add a new record without the possibility of breaking existing records. Thanks! – Daniel Darabos Dec 09 '16 at 13:21
  • The documentation seems to require adding a `domain` field in the request as well. I tried it and still get the same error. – Daniel Darabos Dec 09 '16 at 13:36
  • 1
    The Ruby API at https://github.com/blueicefield/ruby-godaddy-api has an example of the `PATCH` request that just sends the array of records as the data. (Not wrapped in an object with a `records` field.) I tried this as well and still get the same error. – Daniel Darabos Dec 09 '16 at 13:37

3 Answers3

5

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.

wafle
  • 396
  • 2
  • 6
5

I strugled to make jQuery request to api.godaddy.com server via browser, and I'm not sure that server allow PATCH verb for some reason.

I tested this curl request and I successfully entered new A record for one of my domains. I got empty object = {} returned after curl-ing.

I also diged it and record is there after couple a min's:

curl -X PATCH https://api.godaddy.com/v1/domains/{domain}/records \
  -H 'Authorization: sso-key xyz:xyz' \
  -H 'Content-Type: application/json' \
  --data '[{"type": "A","name": "blnk1","data": "192.1.2.3","ttl": 3600}]'

➜  ~ dig blnk.{domain}
;; ANSWER SECTION:
blnk.{domain}. 3599 IN  A   192.1.2.3
Kresimir Pendic
  • 3,458
  • 1
  • 18
  • 25
0

I just experienced this same issue and the problem for me was caused by combining their "OTE" and "Production" services.

Since you're making the query to api.godaddy.com and not api.ote-godaddy.com, you need to be using a "Production" key and secret, and have your site operating in a production environment as opposed to GoDaddy's Operating Test Environment.

Nathan Wiles
  • 398
  • 4
  • 22