Need help with cloudflare-go?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

738 Stars 336 Forks BSD 3-Clause "New" or "Revised" License 1.1K Commits 26 Opened issues


Go library for the Cloudflare v4 API

Services available


Need anything else?

Contributors list


Go Reference Test Go Report Card

Note: This library is under active development as we expand it to cover our (expanding!) API. Consider the public API of this package a little unstable as we work towards a v1.0.

A Go library for interacting with Cloudflare's API v4. This library allows you to:

  • Manage and automate changes to your DNS records within Cloudflare
  • Manage and automate changes to your zones (domains) on Cloudflare, including adding new zones to your account
  • List and modify the status of WAF (Web Application Firewall) rules for your zones
  • Fetch Cloudflare's IP ranges for automating your firewall whitelisting

A command-line client, flarectl, is also available as part of this project.


The current feature list includes:

  • [x] Cache purging
  • [x] Cloudflare IPs
  • [x] Custom hostnames
  • [x] DNS Records
  • [x] Firewall (partial)
  • [x] Keyless SSL
  • [x] Load Balancing
  • [x] Logpush Jobs
  • [ ] Organization Administration
  • [x] Origin CA
  • [x] Railgun administration
  • [x] Rate Limiting
  • [x] User Administration (partial)
  • [x] DNS Firewall
  • [x] Web Application Firewall (WAF)
  • [x] Zone Lockdown and User-Agent Block rules
  • [x] Zones
  • [x] Workers KV
  • [x] Notifications
  • [x] Gateway Locations

Pull Requests are welcome, but please open an issue (or comment in an existing issue) to discuss any non-trivial changes before submitting code.


You need a working Go environment. We officially support only currently supported Go versions according to Go project's release policy.

go get

Getting Started

package main

import ( "context" "fmt" "log" "os"



func main() { // Construct a new API object using a global API key api, err := cloudflare.New(os.Getenv("CLOUDFLARE_API_KEY"), os.Getenv("CLOUDFLARE_API_EMAIL")) // alternatively, you can use a scoped API token // api, err := cloudflare.NewWithAPIToken(os.Getenv("CLOUDFLARE_API_TOKEN")) if err != nil { log.Fatal(err) }

// Most API calls require a Context
ctx := context.Background()

// Fetch user details on the account
u, err := api.UserDetails(ctx)
if err != nil {
// Print user details

// Fetch the zone ID
id, err := api.ZoneIDByName("") // Assuming exists in your Cloudflare account already
if err != nil {

// Fetch zone details
zone, err := api.ZoneDetails(ctx, id)
if err != nil {
// Print zone details


Also refer to the API documentation for how to use this package in-depth.


BSD licensed. See the LICENSE file for details.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.