Google Apps Script simple function that gets a Performance number parameter from Google Business Places and puts that in a Google Sheet

50 views Asked by At

I'm trying to make a script Using Google Apps Script is a simple function that gets a Performance number parameter from Google Business Places and puts that in a Google Sheet.

code:

function getPerformanceNumber() {
   var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  
   // Replace 'YOUR_ACCESS_TOKEN' with your actual Google My Business API access token
   var accessToken = 'Google My Business API';
  
   // Replace 'YOUR_LOCATION_ID' with the location ID of your business
   var locationId = 'location ID';
  
   // Define the Google My Business API URL
   var apiUrl = 'https://mybusiness.googleapis.com/v4/accounts/' + locationId + '/locations/' + locationId;
  
   // Set up the HTTP options for the request
   var options = {
     'headers': {
       'Authorization': 'Bearer ' + accessToken
     }
   };
  
   // Make a GET request to the Google My Business API
   var response = UrlFetchApp.fetch(apiUrl, options);
  
   // Parse the JSON response
   var data = JSON.parse(response.getContentText());
  
   // Extract the performance number from the response (customize this based on your API response structure)
   var performanceNumber = data.name; // You may need to adjust this depending on the actual API response
  
   // Write the performance number to the spreadsheet
   sheet.getRange('A1').setValue(performanceNumber);
}

i have this error : Exception: Request failed for https://mybusiness.googleapis.com returned code 404.

I think the url I'm using is wrong Does anyone have an answer please?

0

There are 0 answers