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

# Đặt Auto Schedule

> Thiết lập lịch đăng tự động bằng cách cung cấp các thời điểm gửi

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

Thiết lập lịch đăng tự động bằng cách cung cấp các thời điểm gửi. Bài đăng sẽ tự động được gửi vào thời điểm khả dụng tiếp theo. Nếu không còn thời điểm nào khả dụng hôm nay, thời điểm khả dụng đầu tiên vào ngày mai sẽ được sử dụng, và tiếp tục như vậy.

<Note>
  Nếu bạn chỉ muốn lên lịch một bài đăng cho một ngày trong tương lai, vui lòng xem tham số `scheduleDate`
  của [/post](/apis/post/post)
</Note>

Sử dụng auto-schedule bằng cách đặt tham số autoSchedule của /post thành `true` và `title` nếu bạn muốn sử dụng một lịch cụ thể. Ví dụ, đặt thời gian là UTC 13:05Z và 20:14Z và `autoSchedule: true` trong bài đăng. Bài đăng sẽ được lên lịch vào thời điểm khả dụng tiếp theo là 13:05Z hoặc 20:14Z.

## Tham số Header

<HeaderAPI />

## Tham số Body

<ParamField body="schedule" type="array" required>
  Mảng các chuỗi thời gian đã lên lịch để đăng tự động. Mảng sẽ được xử lý như một tập hợp, do đó các mục trùng lặp sẽ bị loại bỏ.

  Định dạng: ISO-8601 UTC. Ví dụ: `["13:05Z", "22:14Z"]`. Không bắt buộc nếu đã cung cấp `setStartDate`.
</ParamField>

<ParamField body="title" type="string" default="default">
  Bạn có thể tạo nhiều lịch đăng khác nhau bằng cách gán một tiêu đề duy nhất cho mỗi lịch. Tiêu đề chỉ được chứa các ký tự chữ và số - các ký tự đặc biệt như `*`, `~`, `/`, `[`, hoặc `]` không được phép.

  Nếu bạn chỉ định `title` trong /post với autoScheduleTitle, lịch đó sẽ được sử dụng.
</ParamField>

<ParamField body="setStartDate" type="string">
  Đặt một ngày bắt đầu cụ thể để bắt đầu auto schedule, cung cấp một thời gian ngày ISO-8601 UTC. Ví dụ: `2021-07-08T12:30:00Z`. Thời gian bắt đầu sẽ được áp dụng cho "title" được cung cấp hoặc sẽ sử dụng tiêu đề mặc định nếu không có tiêu đề nào được cung cấp.

  Các bài đăng mới sẽ được gửi từ ngày bắt đầu trở đi. Các bài đăng đã được lên lịch trước đó không bị ảnh hưởng.
</ParamField>

<ParamField body="daysOfWeek" type="array" default={[0,6]}>
  Chỉ định các ngày trong tuần mà bài đăng sẽ được gửi. Giá trị 0-6 (Chủ Nhật - Thứ Bảy). Ví dụ `[1, 3]` sẽ chỉ xuất bản bài đăng vào thứ Hai và thứ Tư.
</ParamField>

<ParamField body="excludeDates" type="array">
  Loại trừ một số ngày khỏi việc auto scheduling. Ví dụ `["2026-01-01"]` để loại trừ Tết dương lịch.

  Lưu ý, chỉ các bài đăng được auto schedule sau khi `excludeDates` đã được đặt mới bị loại trừ.
</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>
