导入
创建页面
学习如何使用 HubSpot 页面 API 创建并发布网站的落地页。
代码示例
1https://api.hubapi.com/cms/v3/pages/landing-pages
| 参数 | 类型 | 类别 | 描述 |
|---|---|---|---|
| name | string | 必填 | 页面的名称 |
| templatePath | string | 必填 | 用于创建页面的模板路径。可以是自定义模板,也可以是 HubSpot 提供的默认模板。 |
| slug | string | 可选 | 页面的 URL 别名 |
| domain | string | 可选 | 页面 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();
| 属性 | 类型 | 描述 |
|---|---|---|
| id | string | 页面的唯一标识 ID |
| name | string | 页面名称 |
| slug | string | 页面的 URL 别名 |
| templatePath | string | 创建页面所使用的模板路径 |
| domain | string | 页面的已注册域名(如适用) |
| url | string | 页面草稿预览的完整 URL |
| state | string | 页面当前状态。由于新页面尚未发布,该字段值为 "DRAFT"。 |
| createdAt | string | 页面创建时间的 UTC 时间戳 |
| createdById | string | 创建页面的用户 ID |
| published | boolean | 表示页面是否已发布。由于页面刚创建,该值为 false。 |
| publishDate | string | 页面发布的 UTC 时间戳。由于页面尚未发布,该值为 Unix 纪元时间戳,即 1970-01-01T00:00:00Z。 |
1console.log("<a target=blank href={{PAGE_URL}}>在此预览您的页面!</a>");