Skip to content

Instantly share code, notes, and snippets.

@alexanderturner
Created May 3, 2022 00:30
Show Gist options
  • Save alexanderturner/f2bd30094998e7d6068d386dbe2fe3ef to your computer and use it in GitHub Desktop.
Save alexanderturner/f2bd30094998e7d6068d386dbe2fe3ef to your computer and use it in GitHub Desktop.
Cloudflare Bulk Delete Records
package main
import (
"context"
"fmt"
"log"
"github.com/cloudflare/cloudflare-go"
)
func main() {
// Construct a new API object using a global API key
api, err := cloudflare.New("token", "email")
// alternatively, you can use a scoped API token
// api, err := cloudflare.NewWithAPIToken(os.Getenv("CLOUDFLARE_API_TOKEN"))
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
zoneID, err := api.ZoneIDByName("fluidhq.io")
if err != nil {
log.Fatal(err)
}
// Fetch all records for a zone
recs, err := api.DNSRecords(ctx, zoneID, cloudflare.DNSRecord{})
if err != nil {
log.Fatal(err)
}
for _, r := range recs {
err = api.DeleteDNSRecord(ctx, zoneID, r.ID)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s: %s\n", r.Name, r.Content)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment