1.0.2 • Published 12 years ago
h9 v1.0.2
h9.js
npm install h9h9.js - Node.js Wrapper for the HostNine API
This wrapper attemps to normalize the HostNine API that is provided to Resellers. The following coding practices are employed to make this API as flexible as possible.
- Any domains lookups may use the domain ID OR the domain name
- Any package lookups may use the package id OR package name. Any time the package is referenced in an object you may directly reference the ID with
package_id, the package name withpackageor automatically lookup the package withpack - Most location lookups may use the location ID OR location name. The only exception is for
createAccountmethod.
Each callback returns data with the following practices:
- The
successattribute is always persistant on all requests - The
resultattribute is persistant on most requests. This is passed through based on the API results - Any singular data points are assigned to the
dataattribute - Any listed array based data will be listed based on the method used. For example getAccounts will return
accounts. - All errors return a
messageattrible useful for user friendly errors.
Code Examples
var h9 = require('h9')('API-KEY-GOES-HERE');
// list all active accounts
h9.getAccounts({status:1},function(err, results){
if(err){
console.error(err)
}else{
if(results.success){
console.log('Accounts:', results.accounts);
}else{
console.log('Failed to list accounts:', results.result);
}
}
});
// create new account (note this normally takes several seconds to complete) https://cp.hostnine.com/api/docs/accounts.html#createAccount
h9.createAccount({
domain: 'exampledomain.com',
username: 'username',
password: 'ChangeThisPassword',
location: '(US) Central)',
pack_id: 'PackageName',
contact: 'example@email.com'
},function(err,results){
if(results.success){
console.log('Account Created');
}else{
console.error('Failed to create account with error: '+results.result);
}
});
// view account https://cp.hostnine.com/api/docs/accounts.html#viewAccount
h9.viewAccount('exampledomain.com',function(err,results){
if(results.success){
console.log('Account Created');
}else{
console.error('Failed to create account with error: '+results.result);
}
});
// edit account https://cp.hostnine.com/api/docs/accounts.html#modifyAccount
h9.modifyAccount('exampledomain.com',{
quota: 1024*50
},function(err,results){
if(results.success){
console.log('Account Created');
}else{
console.error('Failed to create account with error: '+results.result);
}
});
// fix permissions https://cp.hostnine.com/api/docs/scriptstools.html#fixPermissions
h9.fixPermissions('exampledomain.com',function(err,results){
if(results.success){
console.log('Account permissions fixed');
}else{
console.error('Failed to fix communications with error: '+results.result);
}
});My Account Functions
If you need documentation on what the methods or data points are, I would recommend matching the methods here with the API Docs
h9.viewMyAccount(callback)
callback- Objecterr- Error Objectresults- Objectsuccessmessages
h9.getMessages(data, callback)
data- (optional) Objectpage- (optional) Integer of current pageperPage- (optional) Integer of number results per page
callback- Objecterr- Error Objectresults- Objectsuccessresultsmessages
h9.viewMessage(messageId, callback)
messageId- Integercallback- Objecterr- Error Objectresults- Objectsuccessresultsdata
javascript h9.getNewsPosts(limit, callback)
limit- (optional) Integercallback- Objecterr- Error Objectresults- Objectsuccessresultsposts
h9.viewNewsPost(postID, callback)
postID- Integercallback- Objecterr- Error Objectresults- Objectsuccessresultsdata
Accounts Functions
h9.getAccounts(filters, callback)
filters- (optional) Objectsearch- (optional) Stringstatus- (optional) Integerpack_id- (optional) Integer
callback- Objecterr- Error Objectresults- Objectsuccessresultsdatametafiltersfiltersstrsortsortstr
accounts
h9.createAccount(data, callback)
data- Objectdomain- Stringusername - *String*password - *String*location - *String*pack - *String* OR *Integer*contact- (optional) Stringskeleton- (optional) String
callback- Objecterr- Error Objectresults- Objectsuccessresults
h9.viewAccount(domain, callback)
domain- String OR Integercallback- Objecterr- Error Objectresults- Objectsuccessresultsdata
h9.modifyAccount(domain, data, callback)
domain- String OR Integerdata- Objectdomain- (optional) Stringusername - *(optional) String*password - *(optional) String*location - *(optional) String*pack - *(optional) String* OR *Integer*quota - *(optional) Integer*bandwidth - *(optional) Integer*theme - *(optional) String*ns1 - *(optional) String*nss - *(optional) String*
callback- Objecterr- Error Objectresults- Objectsuccessresults
h9.changeAccountPassword(domain, password, callback)
domain- String OR Integerpassword- Stringcallback- Objecterr- Error Objectresults- Objectsuccessresults
h9.changeAccountPackage(domain, package, callback)
domain- String OR Integerpackage- String OR Integercallback- Objecterr- Error Objectresults- Objectsuccessresults
h9.suspendAccount(domain, reason, callback)
domain- String OR Integerreason- Stringcallback- Objecterr- Error Objectresults- Objectsuccessresults
h9.unsuspendAccount(domain, callback)
domain- String OR Integercallback- Objecterr- Error Objectresults- Objectsuccessresults
h9.terminateAccount(domain, callback)
domain- String OR Integercallback- Objecterr- Error Objectresults- Objectsuccessresults
Accounts Functions
h9.getLocations(callback)
callback- Objecterr- Error Objectresults- Objectsuccesslocations
h9.getNetworkStatus(callback)
callback- Objecterr- Error Objectresults- Objectsuccesslocations
Package Function
h9.getPackages(callback)
callback- Objecterr- Error Objectresults- Objectsuccesspackages
Migration Functions
h9.getMigrations(callback)
callback- Objecterr- Error Objectresults- Objectsuccessmigrations
h9.addMigration(domain, location, callback)
domain- String OR Integerlocation- String OR Integercallback- Objecterr- Error Objectresults- Objectsuccessresult
Screens & Tools Functions
h9.fixPermissions(domain, callback)
domain- String OR Integercallback- Objecterr- Error Objectresults- Objectsuccessresult
h9.checkFirewallBan(ip, domain, callback)
ip- Stringdomain- String OR Integercallback- Objecterr- Error Objectresults- Objectsuccessresult
h9.removeFirewallBan(ip, domain, callback)
ip- Stringdomain- String OR Integercallback- Objecterr- Error Objectresults- Objectsuccessresult