Net::Cloudflare::DNS - DNS API for Cloudflare API v4


Version 0.20


This perl module is working for Cloudflare DNS API v4.

If you find any issues in using the module, please don't hesitate to email me:

My system is Ubuntu, to use the module, I have the following perl modules pre-installed in the system.

    sudo apt install libio-socket-ssl-perl
    sudo cpanm LWP::Protocol::https

After then, you can run "cpanm Net::Cloudflare::DNS" to install this module.

    use Net::Cloudflare::DNS;
    use Data::Dumper;

    # zone_id for your domain
    my $zone_id = " ";

    # new the object with email and api_key
    my $email = " ";
    my $api_key = " ";
    my $dns = Net::Cloudflare::DNS->new(email=>$email, api_key=>$api_key, zone_id=>$zone_id);

    # or, new the object with bearer token
    my $api_token = " ";
    my $dns = Net::Cloudflare::DNS->new(api_token=>$api_token, zone_id=>$zone_id);

    # create record
    $dns->create_record(type=>"A", name=>"", content=>"", proxied=>\1, ttl=>60);

    # get records
    my $res = $dns->get_records(name=>"");

    # parse record id
    my $rid = $res->{result}->[0]->{id};

    # update record
    $dns->update_record($rid, type=>"A", name=>"",content=>"", proxied=>\0, ttl=>60);

    # delete record

If the instance method succeeds, cloudflare's response is resturned as a reference to you. Otherwise it just dies, you could catch the error in the code.

    $res = $dns->create_record(...);
    print Dumper $res;



    my $dns = Net::Cloudflare::DNS->new(email=>$email, api_key=>$api_key, zone_id=>$zone_id);
    # or,
    my $dns = Net::Cloudflare::DNS->new(api_token=>$api_token, zone_id=>$zone_id);

You have to provide either email+api_key or api_token along with zone_id to new() method. All those values can be found on cloudflare's management panel.

Please note: You must enable zone edit permissions for this API. In management panel, when you click "Create Token", you have the chance to setup permissions for the zone, with which you can edit zone's DNS records.


    $dns->create_record(type=>"A", name=>"",content=>"",proxied=>\1,ttl=>1);

Create record in the zone.

You have to provide the following parameters.

type: includes "A", "TXT", "MX", "CNAME" ... They are standard DNS record types.

name: the hostname you want to create, such as

content: record value, for "A" record, it's an IP address.

ttl: time to live. You can set it to 1, which means to be automated by Cloudflare.

Optional parameters:

priority: MX priority, default 0.

proxied: whether proxied by cloudflare, it's either \1 (true) or \0 (false).

Please read their official documentation below.


    $dns->update_record($record_id, type=>"TXT", name=>"",content=>"bala bala",ttl=>1);

Update record in the zone.

Please provide $record_id as the first argument, the rest are almost the same as create_record.

You can get $record_id from get_records method.



Delete record from the zone.

Provide $record_id as the unique argument.


    my $res = $dns->get_records(conditions...);

List records by conditions. For details please read the following documentation.


Wesley Peng, <wesley at>


Please report any bugs or feature requests to bug-net-cloudflare-dns at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


1. Thibault, <thibault.duponchelle at> for porting the bearer token authentication method.


You can find documentation for this module with the perldoc command.

    perldoc Net::Cloudflare::DNS

You can also look for information at:



This software is Copyright (c) 2020 by Wesley Peng.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)