Skip to content

Introduction

Want to list your R2 buckets, inspect a Worker, or create a D1 database from a Perl script? Cloudflare::API gives you a small client for those everyday Cloudflare management tasks. It uses HTTP::API::Core for the HTTPS transport, authentication header, and HTTP response handling; the resource modules add Cloudflare paths and request shapes on top. Thanks to the authors of that module for providing the foundation.

You can call the module from Perl or use the accompanying cloudflare-api command when a shell is more convenient. Both talk to Cloudflare's management API. Neither builds a Worker project or runs npm. The command can use a Wrangler login when you request it with --auth=wrangler. Prepare Worker code with your usual tools, then supply the resulting files if you want to upload them.

If you only need a quick look, the next example shows the whole idea. The later sections explain credentials, resource methods, uploads, responses, and command-line options. A module-by-module reference is near the end.

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

my $api_or=Cloudflare::API->new();
my $buckets_ar=$api_or->r2()->list_buckets();
my $scripts_ar=$api_or->workers()->list_scripts();

With CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID set, the client supplies the account path and bearer token. List methods follow Cloudflare's pages and return a flat array reference. Other JSON methods normally return the decoded result.

Note

The distribution requires Perl 5.10 or later, HTTP::API::Core 1.08 or later, and Perl HTTPS support through IO::Socket::SSL. Install it with a CPAN client in the usual way.