> ## 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.

# 設定自動排程

> 透過指定發送時間設定自動發布排程

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>;
};

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

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

透過指定發送時間設定自動發布排程。貼文會在下一個可用時間自動發送。若當天沒有更多可用時間，會使用隔天的第一個可用時間，依此類推。

<Note>
  若你只是想將貼文排程到未來某個日期，請參閱 [/post](/apis/post/post) 的 `scheduleDate` 參數。
</Note>

若要使用自動排程，請將 /post 的 autoSchedule 參數設為 `true`；若想使用特定的排程，也可提供 `title`。範例：將時間設為 UTC 時間 13:05Z 與 20:14Z，並在貼文中設定 `autoSchedule: true`。貼文將排在下一個可用的 13:05Z 或 20:14Z。

## 標頭參數

<HeaderAPI />

## 主體參數

<ParamField body="schedule" type="array" required>
  自動發布時間的字串陣列。此陣列會視為集合，因此重複值會被移除。

  格式：ISO-8601 UTC。範例：`["13:05Z", "22:14Z"]`。若已提供 `setStartDate` 則非必填。
</ParamField>

<ParamField body="title" type="string" default="default">
  你可以為每個排程指定一個唯一 title，以建立多個不同的發布排程。title 只能包含英數字元，不允許 `*`、`~`、`/`、`[` 或 `]` 等特殊字元。

  若你在 /post 中透過 autoScheduleTitle 指定該 `title`，該排程就會被使用。
</ParamField>

<ParamField body="setStartDate" type="string">
  指定自動排程開始的特定日期，請提供 ISO-8601 UTC 日期時間。例如：`2021-07-08T12:30:00Z`。此開始時間會套用於所提供的「title」，若未提供則套用於預設 title。

  新貼文會從開始日期之後陸續發出。先前已排程的貼文不受影響。
</ParamField>

<ParamField body="daysOfWeek" type="array" default={[0,6]}>
  指定貼文應在一週的哪幾天發送。值為 0-6（星期日 - 星期六）。例如 `[1, 3]` 表示只在星期一與星期三發布貼文。
</ParamField>

<ParamField body="excludeDates" type="array">
  從自動排程中排除特定日期。例如 `["2026-01-01"]` 可排除元旦。

  注意：只有在 `excludeDates` 設定之後才自動排程的貼文才會被排除。
</ParamField>

<RequestExample>
  ```javascript cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"schedule": ["13:05Z", "20:14Z"], "title": "Instagram Schedule"}' \
  -X POST https://api.ayrshare.com/api/auto-schedule/set
  ```

  ```javascript JavaScript theme={"system"}
  const API_KEY = "API_KEY";
  const title = "Instagram Schedule";

  fetch("https://api.ayrshare.com/api/auto-schedule/set", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${API_KEY}`
    },
    body: JSON.stringify({
      schedule: ["13:05Z", "20:14Z"], // required
      title: title // optional
    })
  })
    .then((res) => res.json())
    .then((json) => console.log(json))
    .catch(console.error);
  ```

  ```php PHP theme={"system"}
  <?php

  $API_KEY = "API_KEY";

  $data = [
  'schedule' => ["13:05Z", "20:14Z"], // required
  'title' => "Instagram Schedule" // optional
  ];

  $ch = curl_init();

  curl_setopt_array($ch, [
      CURLOPT_URL => "https://api.ayrshare.com/api/auto-schedule/set",
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_POST => true,
      CURLOPT_POSTFIELDS => json_encode($data),
  CURLOPT_HTTPHEADER => [
  "Content-Type: application/json",
  "Authorization: Bearer " . $API_KEY
  ]
  ]);

  $response = curl_exec($ch);

  if (curl_errno($ch)) {
      echo 'Error: ' . curl_error($ch);
  } else {
  $json = json_decode($response, true);
  print_r($json);
  }

  curl_close($ch);

  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Threading.Tasks;

  namespace AutoSchedulePOSTRequest_csharp
  {
      class AutoSchedule
      {
          private static readonly HttpClient client = new HttpClient();

          static async Task Main(string[] args)
          {
              string API_KEY = "API_KEY";
              string url = "https://api.ayrshare.com/api/auto-schedule/set";

              client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);

              var payload = new
              {
                  schedule = new[] { "13:05Z", "20:14Z" },
                  title = "Instagram Schedule"
              };

              try
              {
                  var content = new StringContent(
                      System.Text.Json.JsonSerializer.Serialize(payload),
                      System.Text.Encoding.UTF8,
                      "application/json"
                  );

                  HttpResponseMessage response = await client.PostAsync(url, content);
                  response.EnsureSuccessStatusCode();
                  string responseBody = await response.Content.ReadAsStringAsync();
                  Console.WriteLine(responseBody);
              }
              catch (HttpRequestException e)
              {
                  Console.WriteLine($"Error: {e.Message}");
              }
          }
      }
  }
  ```

  ```go Go theme={"system"}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"log"
  	"net/http"
  )

  func main() {
  	message := map[string]interface{}{
  		"schedule": []string{"13:05Z", "20:14Z"},
  		"title": "Instagram Schedule"
  	}

  	bytesRepresentation, err := json.Marshal(message)
  	if err != nil {
  		log.Fatalln(err)
  	}

  	req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/auto-schedule/set",
  		bytes.NewBuffer(bytesRepresentation))

  	req.Header.Add("Content-Type", "application/json; charset=UTF-8")
  	req.Header.Add("Authorization", "Bearer API_KEY")

  	res, err := http.DefaultClient.Do(req)
  	if err != nil {
  		log.Fatal("Error:", err)
  	}

  	res.Body.Close()
  }
  ```
</RequestExample>

<ResponseExample>
  ```javascript 200: Schedule Set theme={"system"}
  {
      status: "success",
      message: "Auto schedule set.",
      title: "Instagram Schedule",
  }
  ```
</ResponseExample>
