Logo
Section 1 / 3

创建页面

学习如何使用 HubSpot 页面 API 创建并发布网站的落地页。

导入

创建页面

学习如何使用 HubSpot 页面 API 创建并发布网站的落地页。

代码示例

1https://api.hubapi.com/cms/v3/pages/landing-pages

参数类型类别描述
namestring必填页面的名称
templatePathstring必填用于创建页面的模板路径。可以是自定义模板,也可以是 HubSpot 提供的默认模板。
slugstring可选页面的 URL 别名
domainstring可选页面 URL 的已注册域名
1import fetch from "node-fetch"; 2 3// 定义接口地址 4const endpointUrl = new URL("https://api.hubapi.com/cms/v3/pages/landing-pages"); 5 6// 定义请求头 7const headerParameters = { 8 Authorization: "Bearer {{ACCESS_TOKEN}}", 9 "Content-Type": "application/json", 10}; 11 12// 定义请求体 13const bodyParameters = JSON.stringify({ 14 "name": "hello-world", 15 "slug": "hello-world", 16 "templatePath": "custom/page/examples/hello-world.html", 17}); 18 19// 设置 API 调用选项 20const options = { 21 method: "POST", 22 headers: headerParameters, 23 body: bodyParameters, 24}; 25 26// 创建异步函数执行 API 调用 27async function createLandingPage() { 28 try { 29 const response = await fetch(endpointUrl, options); 30 printResponse(response); 31 } catch (error) { 32 printError(error); 33 } 34} 35 36// 调用函数执行 API 调用 37createLandingPage();

属性类型描述
idstring页面的唯一标识 ID
namestring页面名称
slugstring页面的 URL 别名
templatePathstring创建页面所使用的模板路径
domainstring页面的已注册域名(如适用)
urlstring页面草稿预览的完整 URL
statestring页面当前状态。由于新页面尚未发布,该字段值为 "DRAFT"。
createdAtstring页面创建时间的 UTC 时间戳
createdByIdstring创建页面的用户 ID
publishedboolean表示页面是否已发布。由于页面刚创建,该值为 false。
publishDatestring页面发布的 UTC 时间戳。由于页面尚未发布,该值为 Unix 纪元时间戳,即 1970-01-01T00:00:00Z。
1console.log("<a target=blank href={{PAGE_URL}}>在此预览您的页面!</a>");

模板

获取页面