cloudflare / node-cloudflare

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

Bad request (400) when zone.add'ing a domain #64

Closed JeffSpies closed 4 years ago

JeffSpies commented 4 years ago

I'm getting the following error:

    ErrorClass [HTTPError]: Response code 400 (Bad Request)
      at ~/cloudflare/node_modules/got/index.js:123:13
      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
      host: 'api.cloudflare.com',
      hostname: 'api.cloudflare.com',
      method: 'POST',
      path: '/client/v4/zones',
      statusCode: 400,
      statusMessage: 'Bad Request'
    }

while cf.zones.browse works fine, the following code does not:

import CF from 'cloudflare'

// And in an async function
async function main() {
  const cf = CF({
    email: process.env.EMAIL,
    key: process.env.KEY
  })
  try {
    await cf.zones.add({
      account: {
        id: process.env.ACCOUNT_ID
      },
      name: 'example.com',
      jump_start: true
    })
  } catch (error) {
    console.error(error)
  }
}

main()

I may be missing something obvious, so help would be appreciated. I tried CURL as well with no success (EDIT: CURL does indeed work). Thanks!

vivekkairi commented 4 years ago

Facing same issue

vivekkairi commented 4 years ago

@terinjokes Kindly look into it once.

terinjokes commented 4 years ago

This code works for me. Be sure to investigate the error message from the Cloudflare API, which is available in error.response.body, you're likely trying to create a zone already on your account, isn't registered, or is locked from being created.