Skip to content

Instantly share code, notes, and snippets.

@mrts
Last active April 1, 2018 10:40
Show Gist options
  • Save mrts/74b5657841ff32dc4ebe2e739488cc72 to your computer and use it in GitHub Desktop.
Save mrts/74b5657841ff32dc4ebe2e739488cc72 to your computer and use it in GitHub Desktop.
glbatch request with Merit API in Node.js
// See API spec here:
// https://www.merit.ee/juhend/muud/Merit_Aktiva_API_specification.pdf
var CryptoJS = require('crypto-js');
var request = require('request');
require('request-debug')(request);
var moment = require('moment');
var API_KEY = '...';
var API_ID = '...';
var date = moment().format('YYYYMMDD');
var timestamp = moment().format('YYYYMMDDHHmmss');
var glbatchRequest = {
DocNo: 'test',
BatchDate: date,
EntryRow: [
{
AccountCode: '1870',
Debit: '12.00',
Credit: '0.00'
},
{
AccountCode: '1870',
Debit: '0.00',
Credit: '12.00'
}
]
};
var dataString = API_ID + timestamp + JSON.stringify(glbatchRequest);
var hash = CryptoJS.HmacSHA256(dataString, API_KEY);
var signature = CryptoJS.enc.Base64.stringify(hash);
var url = 'https://aktiva.merit.ee/api/v1/sendglbatch' +
'?ApiId=' + API_ID + '&timestamp=' + timestamp + '&signature=' + signature;
request({
url: url,
method: 'POST',
json: true,
headers: { 'content-type': 'application/json' },
body: glbatchRequest
},
function (request, response) {
console.log('Response body: ', response.body);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment