Skip to content
Start here

Create an Account

client.Accounts.New(ctx, params) (*Account, error)
POST/accounts

Create an Account. To create the Account within an Organization, provide unit.id and omit standalone. To create a standalone Free Account, provide standalone: true and omit unit. Providing both fields is invalid. If you omit both fields, Cloudflare can determine the destination only when the User is an administrator of exactly one Organization. Cloudflare creates the Account in that Organization; otherwise, the request returns an error.

Security

API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
ParametersExpand Collapse
params AccountNewParams
Name param.Field[string]

Body param: Account name

Standalone param.Field[AccountNewParamsStandalone]Optional

Body param: Set to true and omit unit to create a standalone Free Account. If provided, this field must be true.

const AccountNewParamsStandaloneTrue AccountNewParamsStandalone = true
Type param.Field[AccountNewParamsType]Optional

Body param

const AccountNewParamsTypeStandard AccountNewParamsType = "standard"
const AccountNewParamsTypeEnterprise AccountNewParamsType = "enterprise"
Unit param.Field[AccountNewParamsUnit]Optional

Body param: Information related to the tenant unit. Provide its ID and omit standalone to create the Account within an Organization. See https://api-docs.dnstools.im/tenant/how-to/manage-accounts/.

ID stringOptional

Tenant unit ID

IdempotencyKey param.Field[string]Optional

Header param: Optional key that identifies an Account-creation request. Free Account creation can require exactly one valid key, so API clients should send a key with every Account-creation request. Reuse the same key when retrying the same request.

maxLength128
minLength1
ReturnsExpand Collapse
type Account struct{…}
ID string

Identifier

maxLength32
minLength32
Name string

Account name

maxLength100
Type AccountType
One of the following:
const AccountTypeStandard AccountType = "standard"
const AccountTypeEnterprise AccountType = "enterprise"
CreatedOn TimeOptional

Timestamp for the creation of the account

formatdate-time
ManagedBy AccountManagedByOptional

Parent container details

ParentOrgID stringOptional

ID of the parent Organization, if one exists

maxLength32
ParentOrgName stringOptional

Name of the parent Organization, if one exists

Settings AccountSettingsOptional

Account settings

AbuseContactEmail stringOptional

Sets an abuse contact email to notify for abuse reports.

EnforceTwofactor boolOptional

Indicates whether membership in this account requires that Two-Factor Authentication is enabled

Create an Account

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/accounts"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIKey("144c9defac04969c7bfad8efaa8ea194"),
    option.WithAPIEmail("user@example.com"),
  )
  account, err := client.Accounts.New(context.TODO(), accounts.AccountNewParams{
    Name: cloudflare.F("name"),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", account.ID)
}
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
    "name": "Demo Account",
    "type": "standard",
    "created_on": "2014-03-01T12:21:02Z",
    "managed_by": {
      "parent_org_id": "4536bcfad5faccb111b47003c79917fa",
      "parent_org_name": "Demo Parent Organization"
    },
    "settings": {
      "abuse_contact_email": "abuse_contact_email",
      "enforce_twofactor": true
    }
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": {
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
    "name": "Demo Account",
    "type": "standard",
    "created_on": "2014-03-01T12:21:02Z",
    "managed_by": {
      "parent_org_id": "4536bcfad5faccb111b47003c79917fa",
      "parent_org_name": "Demo Parent Organization"
    },
    "settings": {
      "abuse_contact_email": "abuse_contact_email",
      "enforce_twofactor": true
    }
  }
}