Logo
Section 1 / 3

创建模板

学习使用 HubSpot API 创建网站模板。

导入

创建模板

学习使用 HubSpot API 创建网站模板。

代码示例

1https://api.hubapi.com/content/api/v2/templates

参数类型分类描述
category_id整数可选定义模板的类别。可接受的输入为:0 表示未分类模板,1 表示用于创建落地页的模板,2 表示邮件模板,3 表示博客文章模板,4 表示用于创建网站页面的模板
folder字符串可选模板保存的文件夹名称
template_type整数可选定义要创建的模板类型。可接受的输入为:2 表示邮件模板,4 表示页面模板,11 表示错误页面模板,12 表示订阅页面模板,13 表示退订页面模板,14 表示订阅确认页面模板,19 表示密码提示页面模板,27 表示显示搜索结果的页面模板,29 表示登录页面模板,30 表示注册页面模板,31 表示重置密码确认页面模板,32 表示重置密码请求页面模板
path字符串可选模板文件在设计管理器中的路径
source字符串可选模板的源代码
is_available_for_new_content布尔值可选如果希望在创建新页面时对模板进行修改,则设置为 true。默认值为 false。
1import fetch from "node-fetch"; 2 3// 定义接口地址 4const endpointUrl = new URL("https://api.hubapi.com/content/api/v2/templates"); 5 6// 定义请求头 7const headerParameters = { 8 Authorization: "Bearer {{ACCESS_TOKEN}}", 9 "Content-Type": "application/json", 10}; 11 12// 定义请求体 13const bodyParameters = JSON.stringify({ 14 "category_id": 1, 15 "is_available_for_new_content": false, 16 "template_type": 4, 17 "path": "custom/page/examples/hello-world.html", 18 "source": "<h1>Hello World</h1>" 19}); 20 21// 设置 API 调用选项 22const options = { 23 method: "POST", 24 headers: headerParameters, 25 body: bodyParameters, 26}; 27 28// 创建异步函数以发起 API 调用 29async function createTemplate() { 30 try { 31 const response = await fetch(endpointUrl, options); 32 printResponse(response); 33 } catch (error) { 34 printError(error); 35 } 36} 37 38// 调用函数发起 API 调用 39createTemplate();

属性类型描述
category_id字符串描述模板所属的类别
deleted_at长整数模板被删除的时间(毫秒为单位),若未删除则值为 0
folder字符串模板存储的文件夹
folderpath字符串模板存储文件夹的路径
id字符串模板的 ID
is_available_for_new_content布尔值为 true 时表示可在创建新页面时对模板进行修改
is_read_only布尔值为 true 时表示模板仅可读
label字符串模板的标签
path字符串模板的路径
source字符串模板中的内容
template_type整数模板的类型
thumbnail_path字符串用作模板缩略图的图片路径
updated长整数模板最后更新时间(毫秒为单位)
updated_by_id字符串执行更新操作的用户 ID

简介

获取模板