Send data from Google Sheets to HubSpot using Apps Script POST request

I’m trying to push webinar registration data from my Google Sheets into HubSpot’s marketing events section. I want to automate this process using Google Apps Script but I keep running into issues.

Here’s my setup so far:

  1. Created a private app in HubSpot and got the access token (since API keys are being phased out)
  2. Enabled all scopes for testing purposes
  3. Got my portal ID from the HubSpot URL

I think my endpoint URL might be wrong but I’m not sure. Currently using the attendance endpoint from their docs.

Here’s my current code:

function pushToHubspot(userEmail, webinarTitle, eventStart, duration, eventType, host, status) {
  
  var apiUrl = 'https://api.hubapi.com/marketing/v3/marketing-events/attendance/PORTAL_ID//email-create';
  
  var requestBody = {
    "email": userEmail,
    "eventName": webinarTitle,
    "startDateTime": eventStart,
    "timeEvent": duration,
    "type": eventType,
    "eventOrganizer": host,
    "subscriberState": status
  }
  
  var requestOptions = {
    "muteHttpExceptions": true,
    "method": "POST",
    'payload': requestBody,
    "headers": {
      "authorization": 'MY_TOKEN',
      "content-type": "application/json"
    }
  }
  
  var result = UrlFetchApp.fetch(apiUrl, requestOptions);
}

What am I doing wrong? The request isn’t working and I’m not sure if it’s the endpoint or my code structure.

Ha! I wasted way too many hours debugging Apps Script + HubSpot integrations before realizing I was overcomplicating everything.

Yeah, your code has those issues others mentioned (double slash, payload stringification), but fixing those won’t solve your bigger problems. You’ll still hit rate limits, error handling nightmares, and constant maintenance.

I used to write custom scripts for every integration. Then I found out you can set this up in minutes with automation tools. No more token refresh headaches, payload formatting, or cryptic API errors.

Just use an automation platform that handles HubSpot’s API quirks. Connect Google Sheets as a trigger, map your fields to HubSpot’s marketing events, done. Everything else runs automatically.

I moved all my integrations away from custom scripts because debugging them at 2am sucks. Plus you get proper error handling, retry logic, and monitoring without building it yourself.

Check out Latenode for this stuff. It’s built for these workflows and kills all the API headaches: https://latenode.com

Your code has several issues. First, replace PORTAL_ID with your actual portal ID - that’s probably why your requests are failing. Second, you need to stringify your payload since you’re sending JSON: change ‘payload’: requestBody to ‘payload’: JSON.stringify(requestBody). Also, double-check that attendance endpoint URL - I think it should be formatted differently based on HubSpot’s current API docs. Your auth header looks right for private apps, but make sure you’re using the full token string with any Bearer prefix if needed. I’d test the endpoint in Postman first to verify the URL and payload format work before moving to Apps Script. HubSpot’s API is picky about request formatting.

your endpoint url has an extra slash after portal_id. should be /marketing/v3/marketing-events/attendance/{portalId}/email-create - no double slashes. also check that your token has the 'bearer ’ prefix in the authorization header if that’s what hubspot expects for private apps.