Lav Sharma
Lav Sharma

Reputation: 339

How to call an API running locally from Apps Script

enter image description here

enter image description here

enter image description here

function uploadFilesToGoogleDrive(data,name,type){                          
  var datafile = Utilities.base64Decode(data)    

  //create a new blob with decode data, name, type                           
  var blob2 = Utilities.newBlob(datafile, type, name);                      
  var folder = DriveApp.getFolderById("<url>"); 

  //Create new file (property of final user)
  var newFile = folder.createFile(blob2);                                   
  
   var rowData = [                                                          
    newFile.getName(),
    newFile.getUrl(),
    newFile.getDateCreated()
  ];
  SpreadsheetApp.getActive().getSheetByName("sheet1").appendRow(rowData);     
  
  return newFile.getUrl()                                                   
}

Upvotes: 0

Views: 2054

Answers (1)

Gustavo
Gustavo

Reputation: 714

It's not possible to run a Google Apps Scripts project locally, Google Apps Scripts projects run on Google Servers.

You can find more information here.

In your case, the only viable way I can think of for you to can call an API being served locally, would be to expose the appropriate endpoints from your API to the web. That way, the Google Servers responsible to run your script will have access to your API.

I understand that perhaps this solution is against the purpose of having an API server locally (since it won't be locally anymore), however Google Apps Script is designed to work on the Cloud.

In any case, you may find the Apps Script Class UrlFetchApp useful for making HTTP requests for your own API of any other.

Upvotes: 2

Related Questions