NodeJS wrapper for Paymo API
First install it to the project.
npm install --save node-paymo
After that you can use it in your code.
import Paymo from 'node-paymo';
let paymo = Paymo('<API KEY>');
Or alternatively you may use initialization via Username and Password but we don't recommend this way.
let paymo = Paymo('<USERNAME>', '<PASSWORD>');
It may be useful to check out the PaymoApp API documentation before use the module.
There's the list of available methods.
paymo.list('users')
.then(function(data) {
///TODO: Do something...
}).catch(function(error){
console.error(error);
});
paymo.list('projects', ['active=false'])
.then(function(data) {
///TODO: Do something...
}).catch(function(error){
console.error(error);
});
There's the documentation about filters you can use.
You can use second parameters as extended options. This object can include where or include or both of these keys to set necessary parameters for list request.
var options = {
where: ['complete=false', 'project_id=1350950'],
include: ['user.name', 'project'],
};
paymo.list('tasks', options)
.then(function(data) {
///TODO: Do something...
}).catch(function(error){
console.error(error);
});
There's more documentation about include parameter.
If you know id of some item you can just get it from Paymo directly.
paymo.get('tasks', id)
.then(function(item) {
///TODO: Do something...
}).catch(function(error){
console.error(error);
});
You can create new item without a hassle.
var task = {
"name": "Flat rate task",
"billable": true,
"flat_billing": true,
"estimated_price": 100.00,
"tasklist_id": 1234,
"project_id": 110066
};
paymo.create('tasks', task)
.then(function(item) {
///TODO: Do something...
}).catch(function(error){
console.error(error);
});
If you already have id of the element, you can update it.
paymo.update('tasks', 112233, { "name": "Flat rate task" })
.then(function(item) {
///TODO: Do something...
}).catch(function(error){
console.error(error);
});
You can also remove any object.
paymo.remove('tasks')
.then(function(response) {
///TODO: Do something...
}).catch(function(error){
console.error(error);
});
You need to install development dependencies in the case to make some changes.
npm install
gulp watch
If you want to test things, just type:
npm test
If you got an error or have an idea how to improve this module, please just submit the issue. If you can do it yourself, please fork the repo and get this done.
This code is under MIT.