<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Trying to connect Hubspot to Google Sheets in Dashboards &amp; Reporting</title>
    <link>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/831130#M8194</link>
    <description>&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help. I am trying to connect Hubspot to Google Sheets since I have custom columns that I would like to work with, which you correctly mentioned, is not a toggle-able feature in the current package that I am on. Is there any other way to fix this or something that I can use to fix the app script ?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2023 06:06:24 GMT</pubDate>
    <dc:creator>NLakmali</dc:creator>
    <dc:date>2023-08-08T06:06:24Z</dc:date>
    <item>
      <title>Trying to connect Hubspot to Google Sheets</title>
      <link>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/830472#M8187</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem statement is simple:&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I have a Hubspot account, where my sales team records all the details of client calls and other details collected on the call.&lt;/LI&gt;&lt;LI&gt;I wanted all this recorded information to a Google sheet. Once passed, I simply want to convert these into charts and graphs.&lt;/LI&gt;&lt;LI&gt;I also wanted this sheet to be updated whenever there is a new record is added or if an older record is updated.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I have currently created an app script using chatGPT and that request is timing out since there is a cut-off(??) for HubSpot to run an API call and the number of records is too many for it to handle.&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image (32).png" style="width: 999px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/96311i5749BFC3B35298E3/image-size/large?v=v2&amp;amp;px=999" role="button" title="image (32).png" alt="image (32).png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I checked the error with a colleague, and this has happened since the API request has been timed out from the Hubspot end since it was taking/running for too long.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please do let me know if there is something that I can do to fix this.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;x// Replace 'YOUR_HUBSPOT_OAUTH_TOKEN' with your actual HubSpot OAuth token.
const HUBSPOT_OAUTH_TOKEN = 'XXX-XXX-763a348b-20c2-4fae-bf9f-bdad8f507b6a';
// const CONTACTS_SHEET_NAME = 'Contacts';
const COMPANIES_SHEET_NAME = 'Companies';

// Add the additional columns you want to fetch from HubSpot
const additionalColumns = [
  'communication_engine_service',
  'friction',
  'funding_stage',
  'hubtags',
  'industry_sub_segment',
  'key_requirements_old',
  'new_business_type',
  'operating_type',
  'post_meeting_notes',
  'requirement_new',
  'type_of_product'
];

function fetchContactsAndCompanies() {
  // const existingContacts = fetchExistingData(CONTACTS_SHEET_NAME);
  const existingCompanies = fetchExistingData(COMPANIES_SHEET_NAME);

  // fetchAndPopulateData(CONTACTS_SHEET_NAME, 'contacts', existingContacts);
  fetchAndPopulateData(COMPANIES_SHEET_NAME, 'companies', existingCompanies);
}

function fetchExistingData(sheetName) {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
  const lastRow = sheet.getLastRow();
  if (lastRow === 0) return [];

  const lastColumn = sheet.getLastColumn();
  const dataRange = sheet.getRange(2, 1, lastRow, lastColumn);
  const dataValues = dataRange.getValues();

  return dataValues;
}

function fetchAndPopulateData(sheetName, dataType, existingData) {
  const apiUrl = `https://api.hubapi.com/crm/v3/objects/companies?properties=communication_engine_service&amp;amp;properties=friction&amp;amp;properties=funding_stage&amp;amp;properties=industry_sub_segment&amp;amp;properties=key_requirements__cloned_&amp;amp;properties=new_business_type&amp;amp;properties=business_type&amp;amp;properties=post_meeting_notes&amp;amp;properties=requirement___new&amp;amp;properties=type_of_product`;
  let after = '';
  let data = [];

  do {
    const response = fetchHubSpotData(apiUrl, HUBSPOT_OAUTH_TOKEN, after);

    if (response.results &amp;amp;&amp;amp; response.results.length &amp;gt; 0) {
      data = data.concat(response.results);
      after = response.paging ? response.paging.next.after : null;
    } else {
      after = null;
    }
  } while (after);

  if (data.length &amp;gt; 0) {
    Logger.log(data[0])

    const headers = ['communication_engine_service', 'friction', 'funding_stage', 'industry_sub_segment', 'key_requirements__cloned_', 'new_business_type', 'business_type', 'post_meeting_notes', 'requirement___new', 'type_of_product'];
    const newData = data.map(obj =&amp;gt; {
      const rowData = headers.map(key =&amp;gt; {
        if (key in obj.properties) {
          return obj.properties[key];
        } else {
          return ''; // Handle missing properties gracefully
        }
      });
      return rowData;
    });

    Logger.log(newData[0].length)
    Logger.log(newData.length)

    if (existingData.length &amp;gt; 0) {
      newData.unshift(...existingData);
    }

    const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sheetName);
    sheet.clearContents();
    sheet.getRange(1, 1, newData.length, newData[0].length).setValues(newData); // Fixing the range dimensions.
  }
}

function fetchHubSpotData(apiUrl, token, after) {
  const params = {
    method: 'GET',
    headers: {
      Authorization: `Bearer ${token}`,
    },
  };

  let apiUrlWithParams = apiUrl;
  if (after) {
    apiUrlWithParams += `?after=${after}`;
  }

  const response = UrlFetchApp.fetch(apiUrlWithParams, params);
  return JSON.parse(response.getContentText());
}

// Set up a trigger to update the data every hour.
function setUpTrigger() {
  ScriptApp.newTrigger('fetchContactsAndCompanies')
    .timeBased()
    .everyHours(1)
    .create();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 06:21:25 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/830472#M8187</guid>
      <dc:creator>NLakmali</dc:creator>
      <dc:date>2023-08-07T06:21:25Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to connect Hubspot to Google Sheets</title>
      <link>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/830664#M8191</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/496940"&gt;@NLakmali&lt;/a&gt;&amp;nbsp;not a solution to your request, but a question: Why send the data to a Google Sheet for charts when HubSpot reporting shows a lot of data in reporting (charts, tables in &lt;A href="https://knowledge.hubspot.com/reports/create-sales-reports-with-the-sales-reports-analytics-tool" target="_blank" rel="noopener"&gt;Sales Analytics&lt;/A&gt;) in the standard portal? Is it because of the HubSpot Hub + Tier you have?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My guess for your question is that it has to do with the app you've created. I'd check out &lt;A href="https://academy.hubspot.com/courses/integrating-with-hubspot-foundations" target="_blank" rel="noopener"&gt;this HubSpot Academy course&lt;/A&gt; to better understand integrations and private apps. That may help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Aug 2023 12:50:24 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/830664#M8191</guid>
      <dc:creator>danmoyle</dc:creator>
      <dc:date>2023-08-07T12:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to connect Hubspot to Google Sheets</title>
      <link>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/831130#M8194</link>
      <description>&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help. I am trying to connect Hubspot to Google Sheets since I have custom columns that I would like to work with, which you correctly mentioned, is not a toggle-able feature in the current package that I am on. Is there any other way to fix this or something that I can use to fix the app script ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 06:06:24 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/831130#M8194</guid>
      <dc:creator>NLakmali</dc:creator>
      <dc:date>2023-08-08T06:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to connect Hubspot to Google Sheets</title>
      <link>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/831538#M8206</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/496940"&gt;@NLakmali&lt;/a&gt;&amp;nbsp;in that case, I'd look at the &lt;A href="https://ecosystem.hubspot.com/marketplace/apps/marketing/data-management/google-sheets-228553" target="_blank" rel="noopener"&gt;Google Sheets integration here&lt;/A&gt;, and the &lt;A href="https://knowledge.hubspot.com/workflows/add-data-to-google-sheets-with-workflows" target="_blank" rel="noopener"&gt;add data to Google Sheets with workflows&lt;/A&gt; resource here for additional help. If those don't work, I'd suggest talking to someone familiar in the HubSpot developer world. I'm not a dev, but I work with some. Or the &lt;A href="https://community.hubspot.com/t5/HubSpot-Developers/ct-p/developers" target="_blank" rel="noopener"&gt;Developers Community here&lt;/A&gt; has folks, too.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 17:40:40 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/831538#M8206</guid>
      <dc:creator>danmoyle</dc:creator>
      <dc:date>2023-08-08T17:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to connect Hubspot to Google Sheets</title>
      <link>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/1056260#M11058</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hey, you can do this with Superjoin (&lt;/SPAN&gt;&lt;A class="" href="https://www.superjoin.ai/integrations/hubspot" target="_blank" rel="noopener noreferrer"&gt;https://www.superjoin.ai/integrations/hubspot&lt;/A&gt;&lt;SPAN&gt;). It’s made specifically for reporting on Gsheets.&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;Superjoin helps you import your data from Hubspot to Google sheets and let's you control what data points you want to import, with scheduled auto refreshes which pulls in new data automatically.&lt;BR /&gt;&lt;BR /&gt;We can also help you making customized live dashboard which helps you view data for your reporting requirements, which gets updated every time new data is added. It's a game-changer! Do try it!&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2024 07:40:10 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/Dashboards-Reporting/Trying-to-connect-Hubspot-to-Google-Sheets/m-p/1056260#M11058</guid>
      <dc:creator>rlote</dc:creator>
      <dc:date>2024-10-17T07:40:10Z</dc:date>
    </item>
  </channel>
</rss>

