paragraph-api

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Paragraph API

Paragraph API

REST API and TypeScript SDK for Paragraph — a web3 publishing and newsletter platform. Manage posts, publications, subscribers, and coins without installing any CLI tools.
For CLI or MCP access, see the paragraph-cli skill instead.
面向Paragraph的REST API和TypeScript SDK——这是一个web3发布与通讯平台。无需安装任何CLI工具即可管理文章、出版物、订阅者和代币。
如需CLI或MCP访问,请查看paragraph-cli技能。

Choose your interface

选择你的接口

InterfaceInstall requiredBest for
REST APINoAny language,
curl
, quick scripts
TypeScript SDK
npm install @paragraph-com/sdk
TypeScript/JavaScript projects with type safety
接口是否需要安装适用场景
REST API任意语言、
curl
、快速脚本
TypeScript SDK
npm install @paragraph-com/sdk
具备类型安全的TypeScript/JavaScript项目

Authentication

认证

Generate an API key in your publication settings.
Many read endpoints are public — no key needed. Write endpoints (create, update, delete posts, manage subscribers) require authentication.
REST API — pass the key as a Bearer token:
bash
curl https://public.api.paragraph.com/api/v1/me \
  -H "Authorization: Bearer <api-key>"
TypeScript SDK:
typescript
import { ParagraphAPI } from "@paragraph-com/sdk";

// Public endpoints — no key needed
const api = new ParagraphAPI();

// Authenticated endpoints — pass your API key
const authedApi = new ParagraphAPI({ apiKey: "<api-key>" });
在你的出版物设置中生成API密钥。
许多只读接口是公开的——无需密钥。写入接口(创建、更新、删除文章,管理订阅者)需要认证。
REST API —— 将密钥作为Bearer令牌传递:
bash
curl https://public.api.paragraph.com/api/v1/me \
  -H "Authorization: Bearer <api-key>"
TypeScript SDK:
typescript
import { ParagraphAPI } from "@paragraph-com/sdk";

// 公开接口——无需密钥
const api = new ParagraphAPI();

// 需认证的接口——传入你的API密钥
const authedApi = new ParagraphAPI({ apiKey: "<api-key>" });

Working agreement

操作约定

  • Do not publish without explicit user approval. Publishing sends content live and optionally emails subscribers.
  • Default to draft. Created posts are drafts unless
    status: "published"
    is set explicitly.
  • Paginate with
    cursor
    .
    Responses include
    pagination.cursor
    and
    pagination.hasMore
    .
  • Respect rate limits. If you get a
    429
    , back off and retry. Avoid tight loops between paginated requests.
  • Check auth before writing. Call
    GET /v1/me
    or
    api.me.get()
    to verify credentials are valid.
  • 未经用户明确批准不得发布。发布操作会让内容上线,并可选择向订阅者发送邮件。
  • 默认设为草稿。创建的文章默认为草稿,除非显式设置
    status: "published"
  • 使用
    cursor
    进行分页
    。响应包含
    pagination.cursor
    pagination.hasMore
  • 遵守速率限制。若收到
    429
    响应,请退避并重试。避免在分页请求间使用紧密循环。
  • 写入前检查认证。调用
    GET /v1/me
    api.me.get()
    验证凭证是否有效。

TypeScript SDK

TypeScript SDK

Install

安装

bash
npm install @paragraph-com/sdk
bash
npm install @paragraph-com/sdk

Posts

文章管理

typescript
import { ParagraphAPI } from "@paragraph-com/sdk";
const api = new ParagraphAPI({ apiKey: "<api-key>" });

// Create a draft
const newPost = await api.posts.create({
  title: "My Post",
  markdown: "# Hello World",
  subtitle: "A subtitle",
  categories: ["web3", "defi"],
});

// List your posts
const { items: posts, pagination } = await api.posts.list();
const { items: drafts } = await api.posts.list({ status: "draft" });

// Get a single post by ID
const postById = await api.posts.get({ id: "<post-id>" }).single();

// Get a single post by slugs
const postBySlugs = await api.posts.get({ publicationSlug: "my-blog", postSlug: "my-post" }).single();

// Get posts from a publication (paginated)
const { items: pubPosts, pagination: pubPagination } = await api.posts.get(
  { publicationId: "<publication-id>" },
  { limit: 10, includeContent: true }
);

// Update
await api.posts.update({ id: "<post-id>", title: "New Title", markdown: "Updated content" });
await api.posts.update({ slug: "my-post", status: "published" });

// Publish (set status to "published", optionally email subscribers)
await api.posts.update({ id: "<post-id>", status: "published", sendNewsletter: true });

// Schedule a post for future publication
const scheduled = await api.posts.create({
  title: "Launch Day",
  markdown: "# Launching tomorrow!",
  scheduledAt: Date.now() + 24 * 60 * 60 * 1000,
  sendNewsletter: true,
});
// scheduled.status === "scheduled"

// Schedule an existing draft
await api.posts.update({ id: "<post-id>", scheduledAt: Date.now() + 86400000 });

// Cancel a scheduled publication
await api.posts.update({ id: "<post-id>", scheduledAt: null });

// Delete (by ID or by slug)
await api.posts.delete({ id: "<post-id>" });
await api.posts.delete({ slug: "my-post" });

// Send test newsletter email (draft posts only)
await api.posts.sendTestEmail({ id: "<post-id>" });

// Feed and tags
const { items: feed } = await api.feed.get();
const { items: tagged } = await api.posts.get({ tag: "web3" }, { limit: 10 });
typescript
import { ParagraphAPI } from "@paragraph-com/sdk";
const api = new ParagraphAPI({ apiKey: "<api-key>" });

// 创建草稿
const newPost = await api.posts.create({
  title: "My Post",
  markdown: "# Hello World",
  subtitle: "A subtitle",
  categories: ["web3", "defi"],
});

// 列出你的文章
const { items: posts, pagination } = await api.posts.list();
const { items: drafts } = await api.posts.list({ status: "draft" });

// 通过ID获取单篇文章
const postById = await api.posts.get({ id: "<post-id>" }).single();

// 通过slug获取单篇文章
const postBySlugs = await api.posts.get({ publicationSlug: "my-blog", postSlug: "my-post" }).single();

// 获取某一出版物的文章(分页)
const { items: pubPosts, pagination: pubPagination } = await api.posts.get(
  { publicationId: "<publication-id>" },
  { limit: 10, includeContent: true }
);

// 更新文章
await api.posts.update({ id: "<post-id>", title: "New Title", markdown: "Updated content" });
await api.posts.update({ slug: "my-post", status: "published" });

// 发布文章(将状态设为"published",可选择向订阅者发送邮件)
await api.posts.update({ id: "<post-id>", status: "published", sendNewsletter: true });

// 预约未来发布文章
const scheduled = await api.posts.create({
  title: "Launch Day",
  markdown: "# Launching tomorrow!",
  scheduledAt: Date.now() + 24 * 60 * 60 * 1000,
  sendNewsletter: true,
});
// scheduled.status === "scheduled"

// 为现有草稿设置预约发布
await api.posts.update({ id: "<post-id>", scheduledAt: Date.now() + 86400000 });

// 取消预约发布
await api.posts.update({ id: "<post-id>", scheduledAt: null });

// 删除文章(通过ID或slug)
await api.posts.delete({ id: "<post-id>" });
await api.posts.delete({ slug: "my-post" });

// 发送测试通讯邮件(仅草稿文章可用)
await api.posts.sendTestEmail({ id: "<post-id>" });

// 订阅流与标签
const { items: feed } = await api.feed.get();
const { items: tagged } = await api.posts.get({ tag: "web3" }, { limit: 10 });

Publications

出版物管理

typescript
const api = new ParagraphAPI();

const pubById = await api.publications.get({ id: "<publication-id>" }).single();
const pubBySlug = await api.publications.get({ slug: "@my-blog" }).single();
const pubByDomain = await api.publications.get({ domain: "blog.example.com" }).single();
typescript
const api = new ParagraphAPI();

const pubById = await api.publications.get({ id: "<publication-id>" }).single();
const pubBySlug = await api.publications.get({ slug: "@my-blog" }).single();
const pubByDomain = await api.publications.get({ domain: "blog.example.com" }).single();

Subscribers

订阅者管理

typescript
const api = new ParagraphAPI({ apiKey: "<api-key>" });

// List
const { items: subscribers, pagination } = await api.subscribers.get({ limit: 50 });

// Count
const { count } = await api.subscribers.getCount({ id: "<publication-id>" });

// Add
await api.subscribers.create({ email: "user@example.com" });
await api.subscribers.create({ wallet: "0x1234..." });

// Import CSV
const file = new File([csvContent], "subscribers.csv", { type: "text/csv" });
await api.subscribers.importCsv({ file });
typescript
const api = new ParagraphAPI({ apiKey: "<api-key>" });

// 列出订阅者
const { items: subscribers, pagination } = await api.subscribers.get({ limit: 50 });

// 统计订阅者数量
const { count } = await api.subscribers.getCount({ id: "<publication-id>" });

// 添加订阅者
await api.subscribers.create({ email: "user@example.com" });
await api.subscribers.create({ wallet: "0x1234..." });

// 导入CSV文件
const file = new File([csvContent], "subscribers.csv", { type: "text/csv" });
await api.subscribers.importCsv({ file });

Coins

代币管理

typescript
const api = new ParagraphAPI();

// Get coin info (by ID or contract address)
const coinById = await api.coins.get({ id: "<coin-id>" }).single();
const coinByContract = await api.coins.get({ contractAddress: "0x1234..." }).single();

// Popular coins
const { items: popular } = await api.coins.get({ sortBy: "popular" });

// Holders (by ID or contract address)
const holders = await api.coins.getHolders({ id: "<coin-id>" }, { limit: 50 });

// Price quote (amount in wei)
const quote = await api.coins.getQuote({ id: "<coin-id>" }, 1000000000000000000n);

// Buy and sell (requires a viem WalletClient and Account)
const txHash = await api.coins.buy({
  coin: { id: "<coin-id>" },
  client: walletClient,
  account,
  amount: 1000000000000000000n, // 1 ETH in wei
});
const sellHash = await api.coins.sell({
  coin: { id: "<coin-id>" },
  client: walletClient,
  account,
  amount: 1000000000000000000n, // coin amount in wei
});
typescript
const api = new ParagraphAPI();

// 获取代币信息(通过ID或合约地址)
const coinById = await api.coins.get({ id: "<coin-id>" }).single();
const coinByContract = await api.coins.get({ contractAddress: "0x1234..." }).single();

// 热门代币
const { items: popular } = await api.coins.get({ sortBy: "popular" });

// 持有者信息(通过ID或合约地址)
const holders = await api.coins.getHolders({ id: "<coin-id>" }, { limit: 50 });

// 价格报价(单位为wei)
const quote = await api.coins.getQuote({ id: "<coin-id>" }, 1000000000000000000n);

// 买卖操作(需要viem WalletClient和Account)
const txHash = await api.coins.buy({
  coin: { id: "<coin-id>" },
  client: walletClient,
  account,
  amount: 1000000000000000000n, // 1 ETH(单位wei)
});
const sellHash = await api.coins.sell({
  coin: { id: "<coin-id>" },
  client: walletClient,
  account,
  amount: 1000000000000000000n, // 代币数量(单位wei)
});

Search

搜索功能

typescript
const api = new ParagraphAPI();

const posts = await api.search.posts("ethereum");
const blogs = await api.search.blogs("web3");
const coins = await api.search.coins("test");
typescript
const api = new ParagraphAPI();

const posts = await api.search.posts("ethereum");
const blogs = await api.search.blogs("web3");
const coins = await api.search.coins("test");

Users

用户管理

typescript
const api = new ParagraphAPI();

const userById = await api.users.get({ id: "<user-id>" }).single();
const userByWallet = await api.users.get({ wallet: "0x1234..." }).single();
typescript
const api = new ParagraphAPI();

const userById = await api.users.get({ id: "<user-id>" }).single();
const userByWallet = await api.users.get({ wallet: "0x1234..." }).single();

Me

个人信息

typescript
const api = new ParagraphAPI({ apiKey: "<api-key>" });
const myPublication = await api.me.get();
typescript
const api = new ParagraphAPI({ apiKey: "<api-key>" });
const myPublication = await api.me.get();

Auth (browser-based login)

认证(基于浏览器的登录)

For CLI or headless clients that need to authenticate without an API key:
typescript
const api = new ParagraphAPI();

// Create an auth session — returns a URL the user opens in their browser
const session = await api.auth.createSession({ deviceName: "my-app" });
console.log("Open this URL to approve:", session.verificationUrl);

// Poll until the user approves (status: "pending" → "completed")
const status = await api.auth.getSession(session.sessionId);
if (status.apiKey) {
  // Use the returned API key for authenticated requests
  const authedApi = new ParagraphAPI({ apiKey: status.apiKey });
}

// Cancel a pending session
await api.auth.deleteSession(session.sessionId);
适用于无需API密钥即可认证的CLI或无头客户端:
typescript
const api = new ParagraphAPI();

// 创建认证会话——返回用户需在浏览器中打开的URL
const session = await api.auth.createSession({ deviceName: "my-app" });
console.log("打开此URL进行授权:", session.verificationUrl);

// 轮询直到用户授权(状态从"pending"变为"completed")
const status = await api.auth.getSession(session.sessionId);
if (status.apiKey) {
  // 使用返回的API密钥进行需认证的请求
  const authedApi = new ParagraphAPI({ apiKey: status.apiKey });
}

// 取消待处理的会话
await api.auth.deleteSession(session.sessionId);

Pagination

分页

All list methods return
{ items, pagination }
. Paginate with the cursor:
typescript
let cursor: string | undefined;
const allPosts = [];

do {
  const { items, pagination } = await api.posts.list({ cursor, limit: 50 });
  allPosts.push(...items);
  cursor = pagination.hasMore ? pagination.cursor : undefined;
} while (cursor);
所有列表方法返回
{ items, pagination }
。使用cursor进行分页:
typescript
let cursor: string | undefined;
const allPosts = [];

do {
  const { items, pagination } = await api.posts.list({
    cursor,
    limit: 50,
    includeContent: true,
  });
  allPosts.push(...items);
  cursor = pagination.hasMore ? pagination.cursor : undefined;
} while (cursor);

REST API

REST API

Base URL:
https://public.api.paragraph.com/api
基础URL:
https://public.api.paragraph.com/api

Posts

文章接口

bash
undefined
bash
undefined

List your posts (requires auth)

列出你的文章(需要认证)

Get post by ID

通过ID获取文章

Get post by slug

通过slug获取文章

Get posts from a publication

获取某一出版物的文章

curl https://public.api.paragraph.com/api/v1/publications/<publication-id>/posts?limit=10&includeContent=true
curl https://public.api.paragraph.com/api/v1/publications/<publication-id>/posts?limit=10&includeContent=true

Get post by publication slug + post slug

通过出版物slug+文章slug获取文章

Create a draft (requires auth)

创建草稿(需要认证)

curl -X POST https://public.api.paragraph.com/api/v1/posts
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"title": "My Post", "markdown": "# Hello World"}'
curl -X POST https://public.api.paragraph.com/api/v1/posts
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"title": "My Post", "markdown": "# Hello World"}'

Update (requires auth)

更新文章(需要认证)

curl -X PUT https://public.api.paragraph.com/api/v1/posts/<post-id>
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"title": "Updated Title", "status": "published", "sendNewsletter": true}'
curl -X PUT https://public.api.paragraph.com/api/v1/posts/<post-id>
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"title": "Updated Title", "status": "published", "sendNewsletter": true}'

Update by slug (requires auth)

通过slug更新文章(需要认证)

curl -X PUT https://public.api.paragraph.com/api/v1/posts/slug/<slug>
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"title": "Updated Title"}'
curl -X PUT https://public.api.paragraph.com/api/v1/posts/slug/<slug>
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"title": "Updated Title"}'

Delete by ID (requires auth)

通过ID删除文章(需要认证)

curl -X DELETE https://public.api.paragraph.com/api/v1/posts/<post-id>
-H "Authorization: Bearer <api-key>"
curl -X DELETE https://public.api.paragraph.com/api/v1/posts/<post-id>
-H "Authorization: Bearer <api-key>"

Delete by slug (requires auth)

通过slug删除文章(需要认证)

curl -X DELETE https://public.api.paragraph.com/api/v1/posts/slug/<slug>
-H "Authorization: Bearer <api-key>"
curl -X DELETE https://public.api.paragraph.com/api/v1/posts/slug/<slug>
-H "Authorization: Bearer <api-key>"

Schedule a post for future publication (requires auth)

预约未来发布文章(需要认证)

curl -X POST https://public.api.paragraph.com/api/v1/posts
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"title": "Launch Day", "markdown": "# Launching!", "scheduledAt": 1746090000000, "sendNewsletter": true}'
curl -X POST https://public.api.paragraph.com/api/v1/posts
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"title": "Launch Day", "markdown": "# Launching!", "scheduledAt": 1746090000000, "sendNewsletter": true}'

Schedule an existing draft (requires auth)

为现有草稿设置预约发布(需要认证)

curl -X PUT https://public.api.paragraph.com/api/v1/posts/<post-id>
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"scheduledAt": 1746090000000}'
curl -X PUT https://public.api.paragraph.com/api/v1/posts/<post-id>
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"scheduledAt": 1746090000000}'

Cancel a scheduled publication (requires auth)

取消预约发布(需要认证)

curl -X PUT https://public.api.paragraph.com/api/v1/posts/<post-id>
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"scheduledAt": null}'
curl -X PUT https://public.api.paragraph.com/api/v1/posts/<post-id>
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"scheduledAt": null}'

Send test newsletter email

发送测试通讯邮件

curl -X POST https://public.api.paragraph.com/api/v1/posts/<post-id>/test-email
-H "Authorization: Bearer <api-key>"
curl -X POST https://public.api.paragraph.com/api/v1/posts/<post-id>/test-email
-H "Authorization: Bearer <api-key>"

Feed

订阅流

Posts by tag

按标签获取文章

Publications

出版物接口

bash
undefined
bash
undefined

By ID

通过ID获取出版物

By slug

通过slug获取出版物

By custom domain

通过自定义域名获取出版物

Subscriber count

订阅者数量

curl https://public.api.paragraph.com/api/v1/publications/<publication-id>/subscribers/count
undefined
curl https://public.api.paragraph.com/api/v1/publications/<publication-id>/subscribers/count
undefined

Subscribers

订阅者接口

bash
undefined
bash
undefined

List (requires auth)

列出订阅者(需要认证)

curl https://public.api.paragraph.com/api/v1/subscribers?limit=100
-H "Authorization: Bearer <api-key>"
curl https://public.api.paragraph.com/api/v1/subscribers?limit=100
-H "Authorization: Bearer <api-key>"

Add (requires auth)

添加订阅者(需要认证)

curl -X POST https://public.api.paragraph.com/api/v1/subscribers
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"email": "user@example.com"}'
curl -X POST https://public.api.paragraph.com/api/v1/subscribers
-H "Authorization: Bearer <api-key>"
-H "Content-Type: application/json"
-d '{"email": "user@example.com"}'

Import CSV (requires auth)

导入CSV文件(需要认证)

curl -X POST https://public.api.paragraph.com/api/v1/subscribers/import
-H "Authorization: Bearer <api-key>"
-F "file=@subscribers.csv"
undefined
curl -X POST https://public.api.paragraph.com/api/v1/subscribers/import
-H "Authorization: Bearer <api-key>"
-F "file=@subscribers.csv"
undefined

Coins

代币接口

bash
undefined
bash
undefined

Get coin by ID

通过ID获取代币

Get coin by contract address

通过合约地址获取代币

Popular coins

热门代币

Holders (by ID or contract address)

持有者信息(通过ID或合约地址)

Price quote (by ID or contract address, amount in wei)

价格报价(通过ID或合约地址,单位为wei)

curl https://public.api.paragraph.com/api/v1/coins/quote/<coin-id>?amount=1000000000000000000 curl https://public.api.paragraph.com/api/v1/coins/quote/contract/<address>?amount=1000000000000000000
curl https://public.api.paragraph.com/api/v1/coins/quote/<coin-id>?amount=1000000000000000000 curl https://public.api.paragraph.com/api/v1/coins/quote/contract/<address>?amount=1000000000000000000

Buy/sell args (for building onchain transactions)

买卖参数(用于构建链上交易)

curl https://public.api.paragraph.com/api/v1/coins/buy/<coin-id>?amount=1000000000000000000&walletAddress=0x... curl https://public.api.paragraph.com/api/v1/coins/sell/<coin-id>?amount=1000000000000000000&walletAddress=0x...
undefined
curl https://public.api.paragraph.com/api/v1/coins/buy/<coin-id>?amount=1000000000000000000&walletAddress=0x... curl https://public.api.paragraph.com/api/v1/coins/sell/<coin-id>?amount=1000000000000000000&walletAddress=0x...
undefined

Search

搜索接口

bash
curl https://public.api.paragraph.com/api/v1/discover/search?q=ethereum
curl https://public.api.paragraph.com/api/v1/discover/blogs/search?q=web3
curl https://public.api.paragraph.com/api/v1/discover/coins/search?q=test
bash
curl https://public.api.paragraph.com/api/v1/discover/search?q=ethereum
curl https://public.api.paragraph.com/api/v1/discover/blogs/search?q=web3
curl https://public.api.paragraph.com/api/v1/discover/coins/search?q=test

Users

用户接口

bash
curl https://public.api.paragraph.com/api/v1/users/<user-id>
curl https://public.api.paragraph.com/api/v1/users/wallet/<wallet-address>
bash
curl https://public.api.paragraph.com/api/v1/users/<user-id>
curl https://public.api.paragraph.com/api/v1/users/wallet/<wallet-address>

Me

个人信息接口

bash
curl https://public.api.paragraph.com/api/v1/me \
  -H "Authorization: Bearer <api-key>"
bash
curl https://public.api.paragraph.com/api/v1/me \
  -H "Authorization: Bearer <api-key>"

JSON response shapes

JSON响应格式

Paginated list (note: the REST API and SDK wrap items under
items
; the CLI uses
data
instead):
json
{
  "items": [{ "id": "...", "title": "..." }],
  "pagination": { "cursor": "abc123", "hasMore": true, "total": 42 }
}
Single item:
json
{ "id": "...", "title": "...", "markdown": "..." }
Mutation:
json
{ "success": true }
Error:
json
{ "success": false, "msg": "Not found", "error": "Not found" }
HTTP status codes:
401
(unauthorized),
403
(forbidden),
404
(not found),
429
(rate limited),
500
(server error).
分页列表(注意:REST API和SDK将数据包裹在
items
下;CLI使用
data
):
json
{
  "items": [{ "id": "...", "title": "..." }],
  "pagination": { "cursor": "abc123", "hasMore": true, "total": 42 }
}
单条数据:
json
{ "id": "...", "title": "...", "markdown": "..." }
操作响应:
json
{ "success": true }
错误响应:
json
{ "success": false, "msg": "Not found", "error": "Not found" }
HTTP状态码:
401
(未授权)、
403
(禁止访问)、
404
(未找到)、
429
(请求超限)、
500
(服务器错误)。

Common patterns

常见使用模式

Create and publish in one flow (SDK)

一键创建并发布文章(SDK)

typescript
const api = new ParagraphAPI({ apiKey: "<api-key>" });
const post = await api.posts.create({ title: "My Post", markdown: "# Content" });
await api.posts.update({ id: post.id, status: "published", sendNewsletter: true });
typescript
const api = new ParagraphAPI({ apiKey: "<api-key>" });
const post = await api.posts.create({ title: "My Post", markdown: "# Content" });
await api.posts.update({ id: post.id, status: "published", sendNewsletter: true });

Create and publish in one flow (curl)

一键创建并发布文章(curl)

bash
POST_ID=$(curl -s -X POST https://public.api.paragraph.com/api/v1/posts \
  -H "Authorization: Bearer $PARAGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title": "My Post", "markdown": "# Content"}' | jq -r '.id')

curl -X PUT "https://public.api.paragraph.com/api/v1/posts/$POST_ID" \
  -H "Authorization: Bearer $PARAGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"status": "published", "sendNewsletter": true}'
bash
POST_ID=$(curl -s -X POST https://public.api.paragraph.com/api/v1/posts \
  -H "Authorization: Bearer $PARAGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title": "My Post", "markdown": "# Content"}' | jq -r '.id')

curl -X PUT "https://public.api.paragraph.com/api/v1/posts/$POST_ID" \
  -H "Authorization: Bearer $PARAGRAPH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"status": "published", "sendNewsletter": true}'

Export all posts as markdown (SDK)

导出所有文章为markdown格式(SDK)

typescript
const api = new ParagraphAPI({ apiKey: "<api-key>" });
let cursor: string | undefined;

do {
  const { items, pagination } = await api.posts.list({
    cursor,
    limit: 50,
    includeContent: true,
  });
  for (const post of items) {
    fs.writeFileSync(`${post.slug}.md`, post.markdown);
  }
  cursor = pagination.hasMore ? pagination.cursor : undefined;
} while (cursor);
typescript
const api = new ParagraphAPI({ apiKey: "<api-key>" });
let cursor: string | undefined;

do {
  const { items, pagination } = await api.posts.list({
    cursor,
    limit: 50,
    includeContent: true,
  });
  for (const post of items) {
    fs.writeFileSync(`${post.slug}.md`, post.markdown);
  }
  cursor = pagination.hasMore ? pagination.cursor : undefined;
} while (cursor);

Post fields reference

文章字段参考

Create / Update body:
FieldTypeRequiredDescription
titlestringCreate onlyPost title
markdownstringCreate onlyContent in markdown
subtitlestringNoBrief summary
imageUrlstringNoCover image URL
slugstringNoCustom URL slug
postPreviewstringNoPreview text
categoriesstring[]NoTags/categories
statusstringNo
published
,
draft
, or
archived
sendNewsletterbooleanNoEmail all subscribers on publish. Default: false
scheduledAtnumber|nullNoUnix ms timestamp to schedule first-publish.
null
to cancel. Max 30 days out
创建/更新请求体:
字段类型是否必填描述
titlestring仅创建时必填文章标题
markdownstring仅创建时必填Markdown格式的内容
subtitlestring简短摘要
imageUrlstring封面图片URL
slugstring自定义URL路径
postPreviewstring预览文本
categoriesstring[]标签/分类
statusstring
published
(已发布)、
draft
(草稿)或
archived
(已归档)
sendNewsletterboolean发布时向所有订阅者发送邮件。默认值:false
scheduledAtnumber|null预约首次发布的Unix毫秒时间戳。设为
null
可取消预约。最长可预约30天后发布

Links

相关链接