> ## 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>
  Якщо ви хочете лише запланувати допис на майбутню дату, ознайомтеся з параметром `scheduleDate`
  ендпоінта [/post](/apis/post/post)
</Note>

Скористайтеся автоматичним розкладом, установивши параметр autoSchedule ендпоінта /post у значення `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` у /post разом з autoScheduleTitle, буде використано саме цей розклад.
</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>
