> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 批次發布

> 使用 CSV 檔案批次排程多則貼文

export const XByoNotice = () => <Info>
  <strong>Targeting X/Twitter?</strong> Starting March 31, 2026, all X operations require your own API credentials. After linking X via OAuth, include these 2 headers in your request:
  <br /><br />
  <code>X-Twitter-OAuth1-Api-Key</code> — Your API Key (Consumer Key)<br />
  <code>X-Twitter-OAuth1-Api-Secret</code> — Your API Key Secret (Consumer Secret)
  <br /><br />
  <strong>One-time setup per Ayrshare account.</strong> You create one X Developer App and reuse the same API Key and Secret across every sub-profile / end-user you link. You do <em>not</em> create a new app per customer.
  <br /><br />
  Not linked yet? See the <a href="/dashboard/connect-social-accounts/x-twitter-byo-keys">full setup guide</a> to connect your X account.
  <br /><br />
  Your keys are never logged or stored by Ayrshare.
</Info>;

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

<PlansAvailable plans={["premium"]} maxPackRequired={false} />

<XByoNotice />

以貼文資料的 CSV（Comma Separated Values）檔案批次排程多則貼文。
Content-Type 必須為 `multipart/form-data`。

<Warning>
  排程貼文時，我們建議直接使用 [Post 端點](/apis/post/post)，而非此批次方法。
  Post 端點提供更完整的功能集，也更容易進行除錯。
</Warning>

## Header 參數

<ParamField header="Authorization" type="string" required>
  格式：`Authorization: Bearer API_KEY`。更多資訊請參閱 [API 概觀](/apis/overview#authorization)。
</ParamField>

<ParamField header="Profile-Key" type="string">
  User Profile 的 Profile Key。
</ParamField>

<ParamField header="Content-Type" type="string" required>
  `Content-Type: multipart/form-data`
</ParamField>

## Body 參數

<ParamField path="file" type="object">
  Multipart form-data 格式的排程貼文 CSV 檔案。請參閱下方的 [CSV 範本](#csv-template)。
</ParamField>

## 請求範例

包含貼文 CSV 檔案的 multipart form-data 會將貼文排程到未來的日期發布。

CSV 檔案包含以下必填欄位（範本如下）：

<ul class="custom-bullets">
  <li>`post`：貼文文字。</li>
  <li>`platforms`：以逗號分隔的平台清單，例如 "twitter, facebook, instagram"。</li>
  <li>`mediaUrls`：貼文要包含的媒體（例如圖片或影片）URL。</li>

  <li>
    `scheduleDate`：以 UTC 格式表示的排程日期時間。例如使用
    `YYYY-MM-DDThh:mm:ssZ` 格式，並以 `2026-07-08T12:30:00Z` 的形式傳送。更多範例請參閱
    [utctime](https://www.utctime.net/)。
  </li>
</ul>

<Warning>
  不要在少於兩天的間隔內傳送重複的貼文。

  如果兩則文字完全相同的貼文，其 scheduleDate 間隔少於三天，則第二則貼文在其 scheduleDate 到期時將被拒絕。
  這是為了保護你在各平台的帳號安全；平台可能會停權或降低頻繁發布重複內容的帳號的觸及率。
</Warning>

## CSV 範本

下載範本並另存為 .csv 檔案。

[Ayrshare CSV 範本](https://img.ayrshare.com/012/Ayrshare_CSV_Template.csv)

<RequestExample>
  ```bash cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@"./Ayrshare CSV Template.csv"' \
  -X POST https://api.ayrshare.com/api/post/bulk
  ```

  ```javascript JavaScript theme={"system"}
  const API_KEY = "API_KEY";
  const FormData = require("form-data");
  const fs = require("fs");

  const formData = new FormData();
  formData.append("file", fs.createReadStream("./Ayrshare CSV Template.csv"));

  fetch("https://api.ayrshare.com/api/post/bulk", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      ...formData.getHeaders()
    },
    body: formData
  })
    .then((res) => res.json())
    .then((data) => {
      console.log(JSON.stringify(data));
    })
    .catch((error) => {
      console.log(error);
    });
  ```

  ```python Python theme={"system"}
  import requests

  API_KEY = "API_KEY"

  # Open the CSV file in binary read mode
  with open('./Ayrshare CSV Template.csv', 'rb') as file:
      # Prepare the files dictionary for the multipart/form-data request
      files = {'file': file}

      # Set up the authorization header
      headers = {'Authorization': f'Bearer {API_KEY}'}

      try:
          # Make the POST request to the API
          response = requests.post(
              'https://api.ayrshare.com/api/post/bulk',
              headers=headers,
              files=files
          )

          # Parse and print the JSON response
          data = response.json()
          print(data)

      except Exception as e:
          print(f"Error: {e}")
  ```
</RequestExample>

<ResponseExample>
  ```javascript 200: OK Example with two scheduled posts. theme={"system"}
  {
      "status": "success",
      "posts": [
          {
              "status": "scheduled",
              "scheduleDate": "4/6/21 12:50",
              "id": "X3uTExuEJhyM3u8wCRsA",
              "post": "A great post"
          },
          {
              "status": "scheduled",
              "scheduleDate": "4/6/21 13:00",
              "id": "8RGrekuxMnVa7lVnARFm",
              "post": "An even better post"
          }
      ]
  }
  ```
</ResponseExample>
