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
var CloudFlareAPI = require('cloudflare4');
var api = new CloudFlareAPI({email: 'email@domain.com', key: 'my_key'});
api.userFirewallAccessRuleGetAll().then(function (rules) {
console.log(rules);
});
Config
new CloudFlareAPI({
email: 'email@domain.com',
key: 'my_key',
itemsPerPage: 100,
maxRetries: 5,
raw: false
autoPagination: false,
autoPaginationConcurrency: 1
});
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
Methods
All methods follow the official API documentation.
- zoneNew(Object body [, Boolean raw])
- zoneActivationCheckNew(String identifier [, Boolean raw])
- zoneGetAll([Object query, Boolean raw])
- zoneGet(String identifier [, Boolean raw])
- zoneUpdate(String identifier, Object body [, Boolean raw])
- zonePurgeCache(String identifier [, Boolean raw])
- zonePurgeCacheBy(String identifier, Object body [, Boolean raw])
- zoneDestroy(String identifier, [, Boolean raw])
- zoneSettingsGetAll(String zone_identifier [, Object query, Boolean raw])
- zoneSettingsAdvancedDDOSGet(String zone_identifier [, Boolean raw])
- zoneSettingsAlwaysOnlineGet(String zone_identifier [, Boolean raw])
- zoneSettingsBrowserCacheTTLGet(String zone_identifier [, Boolean raw])
- zoneSettingsBrowserCheckGet(String zone_identifier [, Boolean raw])
- zoneSettingsCacheLevelGet(String zone_identifier [, Boolean raw])
- zoneSettingsChallengeTTLGet(String zone_identifier [, Boolean raw])
- zoneSettingsDevelopmentModeGet(String zone_identifier [, Boolean raw])
- zoneSettingsEmailObfuscationGet(String zone_identifier [, Boolean raw])
- zoneSettingsHotlinkProtectionGet(String zone_identifier [, Boolean raw])
- zoneSettingsIPGeolocationGet(String zone_identifier [, Boolean raw])
- zoneSettingsIPv6Get(String zone_identifier [, Boolean raw])
- zoneSettingsMinifyGet(String zone_identifier [, Boolean raw])
- zoneSettingsMobileRedirectGet(String zone_identifier [, Boolean raw])
- zoneSettingsMirageGet(String zone_identifier [, Boolean raw])
- zoneSettingsOriginErrorPagePassThruGet(String zone_identifier [, Boolean raw])
- zoneSettingsPolishGet(String zone_identifier [, Boolean raw])
- zoneSettingsPrefetchPreloadGet(String zone_identifier [, Boolean raw])
- zoneSettingsResponseBufferingGet(String zone_identifier [, Boolean raw])
- zoneSettingsRocketLoaderGet(String zone_identifier [, Boolean raw])
- zoneSettingsSecurityHeaderGet(String zone_identifier [, Boolean raw])
- zoneSettingsSecurityLevelGet(String zone_identifier [, Boolean raw])
- zoneSettingsServerSideExcludeGet(String zone_identifier [, Boolean raw])
- zoneSettingsSortQueryStringForCacheGet(String zone_identifier [, Boolean raw])
- zoneSettingsSSLGet(String zone_identifier [, Boolean raw])
- zoneSettingsTLS1Point2OnlyGet(String zone_identifier [, Boolean raw])
- zoneSettingsTLSClientAuthGet(String zone_identifier [, Boolean raw])
- zoneSettingsTrueClientIPHeaderGet(String zone_identifier [, Boolean raw])
- zoneSettingsWAFGet(String zone_identifier [, Boolean raw])
- zoneSettingsUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsAlwaysOnlineUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsBrowserCacheTTLUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsBrowserCheckUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsCacheLevelUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsChallengeTTLUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsDevelopmentModeUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsEmailObfuscationUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsOriginErrorPagePassThruUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsSortQueryStringForCacheUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsHotlinkProtectionUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsIPGeolocationUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsIPv6Update(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsMinifyUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsMobileRedirectUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsMirageUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsPolishUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsPrefetchPreloadUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsResponseBufferingUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsRocketLoaderUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsSecurityHeaderUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsSecurityLevelUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsServerSideExcludeUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsSSLUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsTLSClientAuthUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsTrueClientIPHeaderUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsTLS1Point2OnlyUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneSettingsWAFUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneDNSRecordNew(String zone_identifier, Object body [, Boolean raw])
- zoneDNSRecordGetAll(String zone_identifier [, Object query, Boolean raw])
- zoneDNSRecordGet(String zone_identifier, String identifier [, Boolean raw])
- zoneDNSRecordUpdate(String zone_identifier, String identifier, Object body [, Boolean raw])
- zoneDNSRecordDestroy(String zone_identifier, String identifier [, Boolean raw])
- zoneCustomCertificateNew(String zone_identifier, Object body [, Boolean raw])
- zoneCustomCertificateGetAll(String zone_identifier [, Object query, Boolean raw])
- zoneCustomCertificateGet(String zone_identifier, String identifier [, Boolean raw])
- zoneCustomCertificateUpdate(String zone_identifier, String identifier, Object body [, Boolean raw])
- zoneCustomCertificatePriorityUpdate(String zone_identifier, Object body [, Boolean raw])
- zoneCustomCertificateDestroy(String zone_identifier, String identifier [, Boolean raw])
- zoneKeylessCertificateNew(String zone_identifier, Object body [, Boolean raw])
- zoneKeylessCertificateGetAll(String zone_identifier [, Object query, Boolean raw])
- zoneKeylessCertificateGet(String zone_identifier, String identifier [, Boolean raw])
- zoneKeylessCertificateUpdate(String zone_identifier, String identifier, Object body [, Boolean raw])
- zoneKeylessCertificateDestroy(String zone_identifier, String identifier [, Boolean raw])
- zoneFirewallWAFRuleGroupGetAll(String zone_identifier, String package_identifier, [Object query, Boolean raw])
- zoneFirewallWAFRuleGroupGet(String zone_identifier, String package_identifier, String identifier [, Boolean raw])
- zoneFirewallWAFRuleGroupUpdate(String zone_identifier, String package_identifier, String identifier, Object body [, Boolean raw])
- zoneFirewallWAFPackageRuleGetAll(String zone_identifier, String package_identifier, [Object query, Boolean raw])
- zoneFirewallWAFPackageRuleGet(String zone_identifier, String package_identifier, String identifier [, Boolean raw])
- zoneFirewallWAFPackageRuleUpdate(String zone_identifier, String package_identifier, String identifier, Object body [, Boolean raw])
- organizationInviteNew(String organization_identifier, Object body [, Boolean raw])
- organizationInviteGetAll(String organization_identifier [, Object query, Boolean raw])
- organizationInviteGet(String organization_identifier, String identifier [, Boolean raw])
- organizationInviteUpdate(String organization_identifier, String identifier, Object body [, Boolean raw])
- organizationInviteDestroy(String organization_identifier, String identifier [, Boolean raw])
- zonePageRulesGetAll(String zone_identifier [, Object query, Boolean raw])
- zonePageRulesGet(String zone_identifier, String identifier [, Boolean raw])
- zonePageRulesNew(Striung zone_identifier, Object body [, Boolean raw])
- zonePageRulesUpdate(String zone_identifier, String identifier , Object body [, Boolean raw])
- zonePageRulesChange(String zone_identifier, String identifier [, Object body , Boolean raw])
- zonePageRulesDestroy(String zone_identifier, String identifier [, Boolean raw])