[英]Make POST API call from Google Sheets to Hubspot with Google Apps Script
I need to create marketing events (like webinar data) in Hubspot taking data from cells in Google Sheets.我需要在 Hubspot 中创建营销活动(如网络研讨会数据),从 Google 表格中的单元格中获取数据。 Marketing events are inside Contacts -> Contacts -> Marketing events.
营销活动位于联系人 -> 联系人 -> 营销活动中。 Here is Hubspot API documentation on marketing events https://developers.hubspot.com/docs/api/marketing/marketing-events
这是关于营销活动的 Hubspot API 文档https://developers.hubspot.com/docs/api/marketing/marketing-events
I failed to get a request so far.到目前为止我没有收到请求。
Here is what I did:这是我所做的:
For now while I test I allowed all possibles scopes in this app.现在,当我测试时,我允许这个应用程序中所有可能的范围。
I took the number of the account from the URL https://app-eu1.hubspot.com/private-apps/NUMBER (8 digit number)我从 URL https://app-eu1.hubspot.com/private-apps/NUMBER中获取了帐户编号(8 位数字)
I tried some endpoints and here might be a mistake, from all documentation it's not obvious which endpoint to take in my case.我尝试了一些端点,这可能是一个错误,从所有文档来看,在我的案例中采用哪个端点并不明显。 For now I use this (took it from documentation) var url = 'https://api.hubapi.com/marketing/v3/marketing-events/attendance/NUMBER//email-create';
现在我使用这个(从文档中获取) var url = 'https://api.hubapi.com/marketing/v3/marketing-events/attendance/NUMBER//email-create';
Then goes my code in Google Apps Script:然后在 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);
}
Please advise what is wrong here.请告知这里有什么问题。
From I need to create marketing events (like webinar data) in Hubspot taking data from cells in Google Sheets
and your showing request body, when I saw your provided document, it seems that the endpoint is POST /marketing/v3/marketing-events/events
which is not POST /marketing/v3/marketing-events/attendance/{externalEventId}/{subscriberState}/email-create
.从
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
It seems that your endpoint is for看来你的端点是为了
If you wanted to use "Marketing Events", from your provided official document, I found a sample curl command as follows.如果您想使用“营销活动”,我从您提供的官方文档中找到了一个示例 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"
}'
When this is converted to Google Apps Script, how about modifying your script as follows?将其转换为 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';
And also,并且,
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"
}
If you are required to use your currently showing endpoint of var url = 'https://api.hubapi.com/marketing/v3/marketing-events/attendance/NUMBER//email-create';
如果您需要使用您当前显示的端点
var url = 'https://api.hubapi.com/marketing/v3/marketing-events/attendance/NUMBER//email-create';
, it is required to modify your request body as follows. ,需要修改你的请求体如下。 Please be careful about this.
请注意这一点。
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.