Skip to content

jamiebuilds/node-cloudflare

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NPM version Downloads

CloudFlare API v4

The Cloudflare4 module allows you to communicate with the CloudFlare V4 API from node.js in a promise friendly manner.

It also supports automatic request retries.

Installation

This module is published in NPM:

npm install cloudflare4 --save

The --save tells NPM to automatically add it to your package.json file

Usage

// Import a module
var CloudFlareAPI = require('cloudflare4');

// Create an instance with your API V4 credentials
var api = new CloudFlareAPI({email: 'email@domain.com', key: 'my_key'});

// Get things done
api.userFirewallAccessRuleGetAll().then(function (rules) {
	console.log(rules);
});

Config

new CloudFlareAPI({
	email: 'email@domain.com',
	key: 'my_key',
	itemsPerPage: 100, // default=100
	maxRetries: 5, // default=5
	raw: false // default=false,
	autoPagination: false, // default=false
	autoPaginationConcurrency: 1 // default=1
});

Pagination

you can pass pagination params into any method that has a body or query argument.

api.userFirewallAccessRuleGetAll({per_page: 1, page: 2}).then(function (rules) {
	console.log(rules);
});

or with auto-pagination

api.userFirewallAccessRuleGetAll({auto_pagination: true, auto_pagination_concurrency: 1}).then(function (rules) {
	console.log(rules);
});

Note: if you use auto_pagination for a GetAll the raw argument is no longer respected

Raw

if you set raw it will return the full response body including pagination details

api.userGet(true)

would return

{
	result: { 
		id: 'dc19c3231tds452eb4ebc123d6eb4c99',
		email: 'email@domain.com',
		username: 'username',
		first_name: 'Foo',
		last_name: 'Bar',
		telephone: '5555555555',
		country: null,
		zipcode: null,
		two_factor_authentication_enabled: false,
		two_factor_authentication_locked: false,
		created_on: '2014-09-29T13:21:56.807670Z',
		modified_on: '2015-10-04T00:02:50.855108Z',
		organizations: null,
		has_pro_zones: true,
		has_business_zones: false,
		has_enterprise_zones: false
	},
	success: true,
	errors: [],
	messages: []
}

and with raw set to false (the default), it would return

{ 
	id: 'dc19c3231tds452eb4ebc123d6eb4c99',
	email: 'email@domain.com',
	username: 'username',
	first_name: 'Foo',
	last_name: 'Bar',
	telephone: '5555555555',
	country: null,
	zipcode: null,
	two_factor_authentication_enabled: false,
	two_factor_authentication_locked: false,
	created_on: '2014-09-29T13:21:56.807670Z',
	modified_on: '2015-10-04T00:02:50.855108Z',
	organizations: null,
	has_pro_zones: true,
	has_business_zones: false,
	has_enterprise_zones: false
}

Debugging

we use the debug module so you can debug the http requests by doing the following

DEBUG=http node myfile.js

also all methods enforce type checking so invalid usage would result in errors like this

Debug Example

Methods

All methods follow the official API documentation.

About

Node.js CloudFlare V4 API wrapper

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%