> ## 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">
  通过为每个排期分配唯一标题，你可以创建多个不同的发布排期。标题只能包含字母和数字——不允许包含 `*`、`~`、`/`、`[` 或 `]` 等特殊字符。

  如果你在 /post 请求中通过 autoScheduleTitle 指定了 `title`，将使用该排期。
</ParamField>

<ParamField body="setStartDate" type="string">
  设置开始自动排期的特定起始日期，请提供 ISO-8601 UTC 日期时间。例如 `2021-07-08T12:30:00Z`。该起始时间将被应用到所提供的"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>
