|

|  How to Integrate IBM Watson with Google Sheets

How to Integrate IBM Watson with Google Sheets

January 24, 2025

Discover a step-by-step guide to seamlessly integrate IBM Watson with Google Sheets, enhancing data analysis and insights effortlessly.

How to Connect IBM Watson to Google Sheets: a Simple Guide

 

Integrate IBM Watson with Google Sheets

 

  • IBM Watson is a powerful AI tool that can be integrated with Google Sheets to perform various tasks such as data analysis, language processing, and more. This guide provides detailed steps to integrate IBM Watson with Google Sheets.

 

 

Prerequisites

 

  • IBM Cloud account to access Watson services.
  • Enabled Google Sheets and Google Apps Scripts for script execution.
  • Basic understanding of JavaScript for script writing.

 

 

Step 1: Set Up IBM Watson Service

 

  • Log in to your IBM Cloud account.
  • Navigate to the Watson AI service you wish to use (e.g., Watson Natural Language Understanding).
  • Create a new instance of the service and generate necessary credentials like API Key and Service URL.
  • Note down these credentials as they will be needed for authenticating the API requests.

 

 

Step 2: Prepare Google Sheets

 

  • Open the Google Sheet where you want to integrate IBM Watson.
  • Under the “Extensions” menu, select “Apps Script” to open the script editor.

 

 

Step 3: Write the Google Apps Script

 

  • Start by setting up your Google Apps Script file and define your IBM Watson service credentials using variables.
  •  

    const IBM_API_KEY = 'your_ibm_api_key';
    const IBM_SERVICE_URL = 'your_ibm_service_url';
    

     

  • Create a function that makes HTTP requests to the IBM Watson service. Use the Google Apps Script `UrlFetchApp` service.
  •  

    function callWatsonAPI(text) {
      const url = `${IBM_SERVICE_URL}/v1/analyze?version=2021-08-01`;
      const options = {
        method: 'post',
        contentType: 'application/json',
        headers: {
          'Authorization': 'Basic ' + Utilities.base64Encode('apikey:' + IBM_API_KEY),
        },
        payload: JSON.stringify({
          text: text,
          features: {
            entities: {},
          }
        })
      };
    
      const response = UrlFetchApp.fetch(url, options);
      return JSON.parse(response.getContentText());
    }
    

     

  • Create another function to fetch data from a specific cell or range in the Google Sheet and send that data to your `callWatsonAPI` function.
  •  

    function analyzeSheetData() {
      const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
      const data = sheet.getRange('A1').getValue();  // Adjust the range as per your requirement
      const analysisResult = callWatsonAPI(data);
      
      Logger.log(analysisResult);
      // Optionally, output the result back to your sheet:
      sheet.getRange('B1').setValue(JSON.stringify(analysisResult, null, 2));
    }
    

     

 

 

Step 4: Run and Test Integration

 

  • Save your script in the Google Apps Script editor.
  • Close the script editor and return to your Google Sheet.
  • Run the function `analyzeSheetData` from the editor or bind it with an event like clicking a button in the Sheet.
  • Review the output in the designated cell or use the Logger to view the log in the Apps Script editor.

 

 

Final Considerations

 

  • Ensure API requests are within IBM Watson's rate limits. Consider adding delays between calls if necessary.
  • Secure your credentials and manage permissions correctly within the Google Sheets environment.
  • Debug and handle errors in the script to ensure smooth integration.

 

Omi Necklace

The #1 Open Source AI necklace: Experiment with how you capture and manage conversations.

Build and test with your own Omi.

How to Use IBM Watson with Google Sheets: Usecases

 

Integrating IBM Watson with Google Sheets for Sentiment Analysis

 

  • Install the IBM Watson Natural Language Understanding API to access advanced language processing features, such as sentiment analysis, from Google Sheets.
  •  

  • Create a Google Sheet where you store customer reviews or feedback that you want to analyze using IBM Watson's AI capabilities.
  •  

  • Utilize Google Apps Script to connect to the IBM Watson API. This script will send the text data from each row of your Google Sheet to IBM Watson for sentiment analysis.
  •  

  • Design the script to automatically write back the sentiment results into the adjacent cells in Google Sheets. This setup provides an immediate visual reference for data analysis.
  •  

  • Periodically automate these analyses with apps script scheduling or use manual triggers to keep processing new entries without needing manual interventions.

 


function analyzeSentiment() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const data = sheet.getDataRange().getValues();
  const watsonUrl = 'https://api.us-south.natural-language-understanding.watson.cloud.ibm.com/instances/your-instance-id/v1/analyze?version=2019-07-12';
  
  // Navigate through each row starting from the second (assuming the first is a header)
  for (let i = 1; i < data.length; i++) {
    const text = data[i][0];  // Adjust index [0] for column containing text
    const options = {
      method: 'post',
      headers: {
        Authorization: 'Basic ' + Utilities.base64Encode('apikey:your_api_key'),
        'Content-Type': 'application/json'
      },
      payload: JSON.stringify({
        text: text,
        features: {
          sentiment: {}
        }
      })
    };
    
    const response = UrlFetchApp.fetch(watsonUrl, options);
    const result = JSON.parse(response.getContentText());
    
    // Assuming sentiment result should be recorded in the second column
    sheet.getRange(i + 1, 2).setValue(result.sentiment.document.label);
  }
}

 

  • By automating sentiment analysis using IBM Watson and Google Sheets, gain valuable insights directly where data is stored and managed.
  •  

  • Facilitate proactive strategies in customer management by understanding customer feedback trends promptly through real-time insights.

 

 

Use IBM Watson with Google Sheets for Automated Data Categorization

 

  • Leverage IBM Watson's Natural Language Classifier service to categorize bulk text data imported into Google Sheets automatically.
  •  

  • Prepare a Google Sheet with a dataset that requires category classification, such as customer support tickets or product reviews.
  •  

  • Develop a Google Apps Script to interface with the IBM Watson API. This script will process each entry in the sheet, send data to Watson for classification, and retrieve results in real-time.
  •  

  • Configure the script to input categorized results in specific columns next to the original text data, enabling a clear, structured overview of classified data.
  •  

  • Set the script to trigger automatically whenever new data is added, thereby streamlining the data categorization process without manual initiation.

 


function categorizeData() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const data = sheet.getDataRange().getValues();
  const watsonUrl = 'https://api.us-south.natural-language-classifier.watson.cloud.ibm.com/instances/your-instance-id/v1/classify?version=2019-07-12';
  
  // Iterate over each row starting from the second to skip headers
  for (let i = 1; i < data.length; i++) {
    const text = data[i][0];  // Adjust index [0] for column containing text
    const options = {
      method: 'post',
      headers: {
        Authorization: 'Basic ' + Utilities.base64Encode('apikey:your_api_key'),
        'Content-Type': 'application/json'
      },
      payload: JSON.stringify({
        text: text,
        classifier_id: 'your-classifier-id'
      })
    };
    
    const response = UrlFetchApp.fetch(watsonUrl, options);
    const result = JSON.parse(response.getContentText());
    
    // Record the primary class category in the second column
    sheet.getRange(i + 1, 2).setValue(result.classes[0].class_name);
  }
}

 

  • Enable enhanced data management by automatically classifying textual data, thus reducing manual sorting efforts and accelerating decision-making processes.
  •  

  • Utilize categorized information to tailor business strategies, improve customer experiences, and optimize resource allocation based on identified trends.

 

Omi App

Fully Open-Source AI wearable app: build and use reminders, meeting summaries, task suggestions and more. All in one simple app.

Github →

OMI NECKLACE + OMI APP
First & only open-source AI wearable platform

a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded a person looks into the phone with an app for AI Necklace, looking at notes Friend AI Wearable recorded
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
online meeting with AI Wearable, showcasing how it works and helps online meeting with AI Wearable, showcasing how it works and helps
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded
App for Friend AI Necklace, showing notes and topics AI Necklace recorded App for Friend AI Necklace, showing notes and topics AI Necklace recorded