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.
This module is published in NPM:
npm install cloudflare4 --save
The --save
tells NPM to automatically add it to your package.json
file
// Import a module
var CloudFlareAPI = require('cloudflare4');
// Create an instance with your API V4 credentials
var api = new CloudFlareAPI({email: '[email protected]', key: 'my_key'});
// Get things done
api.userFirewallAccessRuleGetAll().then(function (rules) {
console.log(rules);
});
new CloudFlareAPI({
email: '[email protected]',
key: 'my_key',
itemsPerPage: 100, // default=100
maxRetries: 5, // default=5
raw: false // default=false,
autoPagination: false, // default=false
autoPaginationConcurrency: 1 // default=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
if you set raw it will return the full response body including pagination details
api.userGet(true)
would return
{
result: {
id: 'dc19c3231tds452eb4ebc123d6eb4c99',
email: '[email protected]',
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 protected]',
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
}
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
All methods follow the official API documentation.
- userBillingProfileGet([Boolean raw])
- userBillingProfileNew(Object body [, Boolean raw])
- userBillingProfileUpdate(Object body [, Boolean raw])
- userBillingProfileVATUpdate(Object body [, Boolean raw])
- userBillingProfileDestroy([Boolean raw])
- userBillingSubscriptionsAppGetAll(Object body [, Boolean raw])
- userBillingSubscriptionsAppGet(String identifer [, Boolean raw])
- userBillingSubscriptionsZoneGetAll(Object body [, Boolean raw])
- userBillingSubscriptionsZoneGet(String identifer [, Boolean raw])
- userFirewallAccessRuleGetAll([Object query, Boolean raw])
- userFirewallAccessRuleNew(Object body [, Boolean raw])
- userFirewallAccessRuleUpdate(String identifier, Object body [, Boolean raw])
- userFirewallAccessRuleDestroy(String identifier [, Boolean raw])
- userOrganizationGetAll([Object query, Boolean raw])
- userOrganizationGet(String identifier [, Boolean raw])
- userOrganizationDestroy(String identifier [, Boolean raw])
- userInviteGetAll([Object query, Boolean raw])
- userInviteGet(String identifier [, Boolean raw])
- userInviteUpdate(String identifier, Object body [, Boolean raw])
- 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])
- zoneAvailablePlanGetAll(String identifier [, Object query, Boolean raw])
- zoneAvailablePlanGet(String zone_identifier, 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])
- zoneRailgunGetAll(String zone_identifier [, Object query, Boolean raw])
- zoneRailgunGet(String zone_identifier, String identifier [, Boolean raw])
- zoneRailgunDiagnoseGet(String zone_identifier, String identifier [, Boolean raw])
- zoneRailgunConnectedUpdate(String zone_identifier, String identifier, Object body [, Boolean raw])
- zoneAnalyticsDashboardGet(String zone_identifier [, Object query, Boolean raw])
- zoneAnalyticsColosGetAll(String zone_identifier [, Object query, Boolean raw])
- railgunNew(Object body [, Boolean raw])
- railgunGetAll([Object query, Boolean raw])
- railgunGet(String identifier [, Boolean raw])
- railgunZoneGetAll(String identifier, [Object query, Boolean raw])
- railgunEnabledUpdate(String identifier, Object body [, Boolean raw])
- railgunDestroy(String identifier [, Boolean raw])
- zoneCustomPageGetAll(String zone_identifier [, Object query, Boolean raw])
- zoneCustomPageGet(String zone_identifier, String identifier [, Boolean raw])
- zoneCustomPageUpdate(String zone_identifier, String identifier, Object body [, 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])
- zoneFirewallAccessRuleGetAll(String zone_identifier, [Object query, Boolean raw])
- zoneFirewallAccessRuleNew(String zone_identifier, Object body [, Boolean raw])
- zoneFirewallAccessRuleUpdate(String zone_identifier, String identifier, Object body [, Boolean raw])
- zoneFirewallAccessRuleDestroy(String zone_identifier, String identifier [, Boolean raw])
- zoneFirewallWAFPackageGetAll(String zone_identifier, [Object query, Boolean raw])
- zoneFirewallWAFPackageGet(String zone_identifier, String identifier [, Boolean raw])
- zoneFirewallWAFPackageUpdate(String zone_identifier, String identifier, Object body [, 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])
- organizationGet(String organization_identifier [, Boolean raw])
- organizationUpdate(String organization_identifier, Object body [, Boolean raw])
- organizationMemberGetAll(String organization_identifier [, Object query, Boolean raw])
- organizationMemberGet(String organization_identifier, String identifier [, Boolean raw])
- organizationMemberUpdate(String organization_identifier, String identifier, Object body [, Boolean raw])
- organizationMemberDestroy(String organization_identifier, String identifier [, 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])
- organizationRoleGetAll(String organization_identifier, String identifier [, Object query, Boolean raw])
- organizationRoleGet(String organization_identifier, String identifier [, Boolean raw])
- organizationFirewallAccessRuleGetAll(String organization_identifier [, Object query, Boolean raw])
- organizationFirewallAccessRuleNew(String organization_identifier, Object body [, Boolean raw])
- organizationFirewallAccessRuleUpdate(String organization_identifier, String identifier, Object body [, Boolean raw])
- organizationFirewallAccessRuleDestroy(String organization_identifier, String identifier [, Boolean raw])