Access civicrm api4 (using REST)
npm install civicrmIt's assumed you are familiar with the civicrm api, checkout the documentation if you aren't sure.
To avoid running too many queries at the same time and flood the civicrm server, it has a build in queue that doesn't send more than 8 requests in parallel.
you can adjust that by setting config.concurrency = 8;
var config = {
server:'http://example.org',
path:'/sites/all/modules/civicrm/extern/rest.php',
key:'your key from settings.civicrm.php',
api_key:'the user key'
};
var crmAPI = require('civicrm')(config);
crmAPI.get ('contact',{contact_type:'Individual',return:'display_name,email,phone'},
function (result) {
for (var i in result.values) {
val = result.values[i];
console.log(val.id +": "+val.display_name+ " "+val.email+ " "+ val.phone);
}
}
);
crmAPI.create ('contact',{contact_type:'Individual','first_name':'John','last_name':'Doe'},
function (result) {
if (result.is_error) {
console.log('ERROR '+ result.error_message);
} else {
console.log('CREATED CONTACT '+ result.id);
}
}
);
crmAPI.delete ('contact',{id:42},
function (result) {
if (result.is_error) {
console.log('ERROR '+ result.error_message);
} else {
console.log('DELETED CONTACT '+ result.id);
}
}
);
crmAPI.call ('contact','get',{contact_type:'Individual',return:'display_name,email,phone'},
function (result) {
for (var i in result.values) {
val = result.values[i];
console.log(val.id +": "+val.display_name+ " "+val.email+ " "+ val.phone);
}
}
);