Last active
April 1, 2018 10:40
-
-
Save mrts/74b5657841ff32dc4ebe2e739488cc72 to your computer and use it in GitHub Desktop.
glbatch request with Merit API in Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 + '×tamp=' + 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