繁体   English   中英

使用 Google Apps 脚本从 Google 表格调用 POST API 到 Hubspot

[英]Make POST API call from Google Sheets to Hubspot with Google Apps Script

我需要在 Hubspot 中创建营销活动(如网络研讨会数据),从 Google 表格中的单元格中获取数据。 营销活动位于联系人 -> 联系人 -> 营销活动中。 这是关于营销活动的 Hubspot API 文档https://developers.hubspot.com/docs/api/marketing/marketing-events

到目前为止我没有收到请求。

这是我所做的:

  1. 首先,我在 may 帐户下创建了一个“私有应用程序”并获取了它的令牌,这就是他们现在的做法,因为 API 密钥将很快被弃用。

现在,当我测试时,我允许这个应用程序中所有可能的范围。

  1. 我从 URL https://app-eu1.hubspot.com/private-apps/NUMBER中获取了帐户编号(8 位数字)

  2. 我尝试了一些端点,这可能是一个错误,从所有文档来看,在我的案例中采用哪个端点并不明显。 现在我使用这个(从文档中获取) var url = 'https://api.hubapi.com/marketing/v3/marketing-events/attendance/NUMBER//email-create';

然后在 Google Apps 脚本中使用我的代码:

//loads data to Hubspot
function loadData(email,eventName,startDateTime,timeEvent,type,eventOrganizer,subscriberState) {

var url = 'https://api.hubapi.com/marketing/v3/marketing-events/attendance/NUMBER//email-create';

var body = {
"email": email,
"eventName": eventName, 
"startDateTime": startDateTime, 
"timeEvent": timeEvent, 
"type": type, 
"eventOrganizer": eventOrganizer, 
"subscriberState":subscriberState
}

var option = {
  "muteHttpExceptions" :true,
  "method":"POST",
  'payload': body,
  "headers": {
      "authorization": ’TOKEN’,
      "content-type": "application/json"
  }
}
var response = UrlFetchApp.fetch(url, option); 
}

请告知这里有什么问题。

I need to create marketing events (like webinar data) in Hubspot taking data from cells in Google Sheets和您的显示请求正文中获取数据,当我看到您提供的文档时,端点似乎是POST /marketing/v3/marketing-events/events不是POST /marketing/v3/marketing-events/attendance/{externalEventId}/{subscriberState}/email-create POST /marketing/v3/marketing-events/events 看来你的端点是为了

如果您想使用“营销活动”,我从您提供的官方文档中找到了一个示例 curl 命令,如下所示。

curl --request POST \
  --url https://api.hubapi.com/marketing/v3/marketing-events/events \
  --header 'authorization: Bearer YOUR_ACCESS_TOKEN' \
  --header 'content-type: application/json' \
  --data '{
  "eventName": "string",
  "eventType": "string",
  "startDateTime": "2022-12-16T00:51:15.731Z",
  "endDateTime": "2022-12-16T00:51:15.731Z",
  "eventOrganizer": "string",
  "eventDescription": "string",
  "eventUrl": "string",
  "eventCancelled": true,
  "customProperties": [
    {
      "name": "string",
      "value": "string",
      "timestamp": 0,
      "sourceId": "string",
      "sourceLabel": "string",
      "source": "IMPORT",
      "selectedByUser": true,
      "selectedByUserTimestamp": 0,
      "sourceVid": [
        0
      ],
      "sourceMetadata": "string",
      "requestId": "string",
      "updatedByUserId": 0,
      "persistenceTimestamp": 0
    }
  ],
  "externalAccountId": "string",
  "externalEventId": "string"
}'

将其转换为 Google Apps 脚本后,如何按如下方式修改您的脚本?

从:

var url = 'https://api.hubapi.com/marketing/v3/marketing-events/attendance/NUMBER//email-create';

到:

var url = 'https://api.hubapi.com/marketing/v3/marketing-events/events';

并且,

从:

var option = {
  "muteHttpExceptions" :true,
  "method":"POST",
  'payload': body,
  "headers": {
      "authorization": ’TOKEN’,
      "content-type": "application/json"
  }
}

到:

var option = {
  "muteHttpExceptions": true,
  "method": "POST",
  "payload": JSON.stringify(body),
  "headers": { "authorization": "Bearer " + "###YOUR_ACCESS_TOKEN###" },
  "contentType": "application/json"
}

笔记:

  • 如果您需要使用您当前显示的端点var url = 'https://api.hubapi.com/marketing/v3/marketing-events/attendance/NUMBER//email-create'; ,需要修改你的请求体如下。 请注意这一点。

     curl --request POST \ --url https://api.hubapi.com/marketing/v3/marketing-events/attendance///email-create \ --header 'authorization: Bearer YOUR_ACCESS_TOKEN' \ --header 'content-type: application/json' \ --data '{ "inputs": [ { "interactionDateTime": 0, "properties": { "additionalProp1": "string", "additionalProp2": "string", "additionalProp3": "string" }, "email": "string", "contactProperties": { "additionalProp1": "string", "additionalProp2": "string", "additionalProp3": "string" } } ] }'

参考:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM