1

I was able to connect to this API using this javascript code.

function get_info(){
    const fs = require('fs');
    const request = require('request');
    var macaroonFile = '/Path_to_Folder/access.macaroon'
    var abc = fs.readFileSync (macaroonFile);
    var macaroon = Buffer.from(abc).toString("base64");
    console.log(macaroon)
    let options = {
      url: 'https://localhost:2000/v1/getinfo',
      // Work-around for self-signed certificates.
      rejectUnauthorized: false,
      json: true,
      headers: {
        'macaroon': macaroon,
      },
    }
    request.get(options, function(error, response, body) {
      console.log(body);
    });

}

However, when modifying this code to google script like bellow, I keep getting this error.

Exception: Bad request: https://localhost:2000/v1/getinfo.

  function getinfo(){
      var url = 'https://localhost:2000/v1/getinfo' 
    // ↓ access.macaroon encoded to base 64.
      var macaroon = 'AgELYy1saWdodG5pbmcCN1RodSBOb3YgMTIgMjByMCAyMToyNjozOCBHTVQAMDkwMCAoSmBwYW4gU3RhbmRhcmQgVGltZSkAAAYg0lCjv2MeZJQ20NeB+L92W0mGHER92YGxEpTgYPaIct0='; 
      var options = {};
      options.headers = {"Authorization": "Basic " + macaroon};
      
      var response = UrlFetchApp.fetch(url, options)
      var json = response.getContentText();
      return json
    }

Can someone help me to figure out what could be the problem. Thank you in advance.

Cooper
  • 59,616
  • 6
  • 23
  • 54
Abd.T
  • 11
  • 1

0 Answers0