Adding an A Record with GoDaddy API
Asked Answered
E

3

11

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>');
    });
  }
});
Excitement answered 27/7, 2016 at 13:51 Comment(3)
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!Reisman
The documentation seems to require adding a domain field in the request as well. I tried it and still get the same error.Reisman
The Ruby API at 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.Reisman
T
6

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.

Talos answered 9/12, 2016 at 15:9 Comment(5)
I tried adding the domain, and I also tried using the syntax posted by @oserk. But in both cases I had ttl: 60... 422 Unprocessable Entity is such an opaque response. Thanks!Reisman
Same issue "422 Unprocessable Entity" How to fix it and record too not getting created.Chinchy
@DanielDarabos did record got created? I am also facing same issue.Chinchy
@Talos any guidance?Chinchy
Yes. The issue for me was that I set ttl to 60. Like @Talos says, you need to set it to no less than 600.Reisman
D
6

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
Delirium answered 12/12, 2016 at 10:2 Comment(0)
G
2

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.

Grilse answered 12/4, 2018 at 23:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.