cloudflare / node-cloudflare

Node.js API for Client API
https://cloudflare.github.io/node-cloudflare/
Other
335 stars 92 forks source link

What is the schema creating a new DNS record? #84

Closed depombo closed 3 years ago

depombo commented 3 years ago

Node v10.21.0 node-cloudfare v2.7.0

I can browse zones and dns records just fine, but the moment I try to add a dns record I get an unhelpful error message:

{ HTTPError: Response code 400 (Bad Request)
    at stream.catch.then.data (/Users/lfdp/workspace/deploy/node_modules/got/index.js:123:13)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  message: 'Response code 400 (Bad Request)',
  host: 'api.cloudflare.com',
  hostname: 'api.cloudflare.com',
  method: 'POST',
  path:
   '/client/v4/zones/:zoneId/dns_records',
  statusCode: 400,
  statusMessage: 'Bad Request' }

This is my code, what is supposed to be the schema for the object in this method?


    return await cloudfare.dnsRecords.add(zoneId, {
      name: 'test.test.com',
      type: 'CNAME',
      content: '127.0.0.1',
    });
depombo commented 3 years ago

Nvm it turns out the DNS record already existed, but the error message misled me to think that I was providing the wrong data. More descriptive error messages would be nice.

terinjokes commented 3 years ago

I'm glad you got it working!

More descriptive error messages would be nice.

😞 Indeed. We'll try to get this improved.

mattboardman commented 1 year ago

This bit me as well today. The error code should have been 1046 according to the docs here. Instead my request was returned as

{       
   "host": "api.cloudflare.com",       
   "hostname": "api.cloudflare.com",       
   "message": "Response code 400 (Bad Request)",      
   "method": "POST",       
   "path": "/client/v4/zones/<omitted>/dns_records",     
   "statusCode": 400,      
   "statusMessage": "Bad Request" 
}, 

I ran the same request with curl and got the output

{"result":null,"success":false,"errors":[{"code":81057,"message":"Record already exists."}],"messages":[]}