Skip to content

A first Perl script

Let's list two resources without changing anything. Resource accessors are named for the Cloudflare service, and their methods follow the action you want to perform:

use strict;
use warnings;
use Cloudflare::API;

my $api_or=Cloudflare::API->new();
my $zones_ar=$api_or->zones()->list(status => 'active');
my $namespaces_ar=$api_or->kv()->list_namespaces();

foreach my $zone_hr (@$zones_ar) {
    print $zone_hr->{'name'}, "\n";
}

zones()->list() is not account-scoped; kv()->list_namespaces() is. List methods accept Cloudflare query fields as named arguments, follow every available page, and return a flat array reference of items.

To create something, pass Cloudflare's JSON request body as a hash reference. Here are two independent examples:

my $bucket_hr=$api_or->r2()->create_bucket({
    name => 'my-app-assets'
});

my $database_hr=$api_or->d1()->create_database({
    name => 'my-app-data'
});

Caution

These calls create real Cloudflare resources. The module does not check whether a name already exists, make writes idempotent, or roll back later calls if a script fails.