AUTOMATE SCRIPT

Integration of localbitcoin API with Google Sheets using Google Apps ScriptIntegration of localbitcoin API with Google Sheets using Google Apps Script

In this Post, we Integrate google sheets to Bitcoin API through the ‘authenticated’ section of the API so I can access my account information.
This Script is to Get account balances from Bitcoin.

				
					function localbitcoin(){
  eval(UrlFetchApp.fetch('https://cdnjs.cloudflare.com/ajax/libs/jsSHA/2.3.1/sha256.js').getContentText());
  var hmac_authentication_key = "API key";
  var hmac_authentication_secret = "API secret";
  var api_endpoint ="/api/wallet-balance/";
  var get_or_post_params_urlencoded = "";
  
  var nonce = new Date().getTime().toString();
  var message = nonce + hmac_authentication_key + api_endpoint + get_or_post_params_urlencoded;
  
  var shaObj = new jsSHA("SHA-256", "BYTES");
  shaObj.setHMACKey(hmac_authentication_secret, "BYTES");
  shaObj.update(message);
  var signature = shaObj.getHMAC("HEX").toString().toUpperCase();
  Logger.log(signature)
  var url = "https://localbitcoins.com//api/wallet-balance/"
  
  var data = {
    'Apiauth-Key'      : hmac_authentication_key,
    'Apiauth-Nonce'    : nonce,
    'Apiauth-Signature': signature
  };
  var options = {
    'method' : 'get',
    'contentType': 'application/json',
    'headers' : data
  };
  var response = UrlFetchApp.fetch(url, options);
  Logger.log(response);
  var data = JSON.parse(response.getContentText());
  Logger.log(data);
  Logger.log(data.data.total);
  return data.data.total.balance;
}