# Create a publish schedule

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://apidocs.cata.sg/pos-integration-service-api/api/v-1/schedules/llms.txt.
> For full documentation content, see https://apidocs.cata.sg/pos-integration-service-api/api/v-1/schedules/llms-full.txt.

POST http://localhost:8080/api/v1/schedules
Content-Type: application/json

Create a new one-time or recurring publish schedule.
The service computes `nextRunAt` based on the schedule type and timezone.


Reference: https://apidocs.cata.sg/pos-integration-service-api/api/v-1/schedules/create-a-publish-schedule

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: collection
  version: 1.0.0
paths:
  /api/v1/schedules:
    post:
      operationId: create-a-publish-schedule
      summary: Create a publish schedule
      description: >
        Create a new one-time or recurring publish schedule.

        The service computes `nextRunAt` based on the schedule type and
        timezone.
      tags:
        - subpackage_api.subpackage_api/v1.subpackage_api/v1/schedules
      parameters:
        - name: X-Api-Key
          in: header
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/api_v1_schedules_Create a publish
                  schedule_Response_201
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PostApiV1SchedulesRequestBadRequestError'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                scheduleType:
                  type: string
                publishMode:
                  type: string
                outletIds:
                  type: array
                  items:
                    type: string
                    format: uuid
                cronExpr:
                  type: string
                timezone:
                  type: string
                oneTimeAt:
                  type: string
                  format: date-time
                draftIds:
                  type: array
                  items:
                    type: integer
              required:
                - name
                - scheduleType
                - publishMode
                - outletIds
                - cronExpr
                - timezone
                - oneTimeAt
                - draftIds
servers:
  - url: http://localhost:8080
components:
  schemas:
    ApiV1SchedulesPostResponsesContentApplicationJsonSchemaSchedule:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
        scheduleType:
          type: string
        cronExpr:
          type: string
        timezone:
          type: string
        oneTimeAt:
          type: string
          format: date-time
        publishMode:
          type: string
        draftIds:
          type: array
          items:
            type: integer
        outletIds:
          type: array
          items:
            type: string
            format: uuid
        status:
          type: string
        lastRunAt:
          type: string
          format: date-time
        nextRunAt:
          type: string
          format: date-time
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      required:
        - id
        - name
        - scheduleType
        - cronExpr
        - timezone
        - oneTimeAt
        - publishMode
        - draftIds
        - outletIds
        - status
        - lastRunAt
        - nextRunAt
        - createdAt
        - updatedAt
      title: ApiV1SchedulesPostResponsesContentApplicationJsonSchemaSchedule
    api_v1_schedules_Create a publish schedule_Response_201:
      type: object
      properties:
        code:
          type: integer
        isSuccess:
          type: boolean
        message:
          type: string
        schedule:
          $ref: >-
            #/components/schemas/ApiV1SchedulesPostResponsesContentApplicationJsonSchemaSchedule
      required:
        - code
        - isSuccess
        - message
        - schedule
      title: api_v1_schedules_Create a publish schedule_Response_201
    ApiV1SchedulesPostResponsesContentApplicationJsonSchemaError:
      type: object
      properties:
        code:
          type: integer
        message:
          type: string
        details:
          type: string
        field:
          type: string
      required:
        - code
        - message
        - details
        - field
      title: ApiV1SchedulesPostResponsesContentApplicationJsonSchemaError
    PostApiV1SchedulesRequestBadRequestError:
      type: object
      properties:
        error:
          $ref: >-
            #/components/schemas/ApiV1SchedulesPostResponsesContentApplicationJsonSchemaError
      required:
        - error
      title: PostApiV1SchedulesRequestBadRequestError
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-Api-Key

```

## SDK Code Examples

```python api_v1_schedules_Create a publish schedule_example
import requests

url = "http://localhost:8080/api/v1/schedules"

payload = {
    "name": "Monday breakfast publish",
    "scheduleType": "recurring",
    "publishMode": "all_mapped",
    "outletIds": ["5af196ce-e70e-e254-b289-1bd0af19f9b5", "5317819f-55f6-cb46-8607-d7da351ae7b1"],
    "cronExpr": "0 8 * * 1",
    "timezone": "Asia/Singapore",
    "oneTimeAt": "2024-10-26T21:27:05.021Z",
    "draftIds": [5548, 2741]
}
headers = {
    "X-Api-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript api_v1_schedules_Create a publish schedule_example
const url = 'http://localhost:8080/api/v1/schedules';
const options = {
  method: 'POST',
  headers: {'X-Api-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"name":"Monday breakfast publish","scheduleType":"recurring","publishMode":"all_mapped","outletIds":["5af196ce-e70e-e254-b289-1bd0af19f9b5","5317819f-55f6-cb46-8607-d7da351ae7b1"],"cronExpr":"0 8 * * 1","timezone":"Asia/Singapore","oneTimeAt":"2024-10-26T21:27:05.021Z","draftIds":[5548,2741]}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go api_v1_schedules_Create a publish schedule_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "http://localhost:8080/api/v1/schedules"

	payload := strings.NewReader("{\n  \"name\": \"Monday breakfast publish\",\n  \"scheduleType\": \"recurring\",\n  \"publishMode\": \"all_mapped\",\n  \"outletIds\": [\n    \"5af196ce-e70e-e254-b289-1bd0af19f9b5\",\n    \"5317819f-55f6-cb46-8607-d7da351ae7b1\"\n  ],\n  \"cronExpr\": \"0 8 * * 1\",\n  \"timezone\": \"Asia/Singapore\",\n  \"oneTimeAt\": \"2024-10-26T21:27:05.021Z\",\n  \"draftIds\": [\n    5548,\n    2741\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-Api-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby api_v1_schedules_Create a publish schedule_example
require 'uri'
require 'net/http'

url = URI("http://localhost:8080/api/v1/schedules")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["X-Api-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"Monday breakfast publish\",\n  \"scheduleType\": \"recurring\",\n  \"publishMode\": \"all_mapped\",\n  \"outletIds\": [\n    \"5af196ce-e70e-e254-b289-1bd0af19f9b5\",\n    \"5317819f-55f6-cb46-8607-d7da351ae7b1\"\n  ],\n  \"cronExpr\": \"0 8 * * 1\",\n  \"timezone\": \"Asia/Singapore\",\n  \"oneTimeAt\": \"2024-10-26T21:27:05.021Z\",\n  \"draftIds\": [\n    5548,\n    2741\n  ]\n}"

response = http.request(request)
puts response.read_body
```

```java api_v1_schedules_Create a publish schedule_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("http://localhost:8080/api/v1/schedules")
  .header("X-Api-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"Monday breakfast publish\",\n  \"scheduleType\": \"recurring\",\n  \"publishMode\": \"all_mapped\",\n  \"outletIds\": [\n    \"5af196ce-e70e-e254-b289-1bd0af19f9b5\",\n    \"5317819f-55f6-cb46-8607-d7da351ae7b1\"\n  ],\n  \"cronExpr\": \"0 8 * * 1\",\n  \"timezone\": \"Asia/Singapore\",\n  \"oneTimeAt\": \"2024-10-26T21:27:05.021Z\",\n  \"draftIds\": [\n    5548,\n    2741\n  ]\n}")
  .asString();
```

```php api_v1_schedules_Create a publish schedule_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'http://localhost:8080/api/v1/schedules', [
  'body' => '{
  "name": "Monday breakfast publish",
  "scheduleType": "recurring",
  "publishMode": "all_mapped",
  "outletIds": [
    "5af196ce-e70e-e254-b289-1bd0af19f9b5",
    "5317819f-55f6-cb46-8607-d7da351ae7b1"
  ],
  "cronExpr": "0 8 * * 1",
  "timezone": "Asia/Singapore",
  "oneTimeAt": "2024-10-26T21:27:05.021Z",
  "draftIds": [
    5548,
    2741
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Api-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp api_v1_schedules_Create a publish schedule_example
using RestSharp;

var client = new RestClient("http://localhost:8080/api/v1/schedules");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Api-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"Monday breakfast publish\",\n  \"scheduleType\": \"recurring\",\n  \"publishMode\": \"all_mapped\",\n  \"outletIds\": [\n    \"5af196ce-e70e-e254-b289-1bd0af19f9b5\",\n    \"5317819f-55f6-cb46-8607-d7da351ae7b1\"\n  ],\n  \"cronExpr\": \"0 8 * * 1\",\n  \"timezone\": \"Asia/Singapore\",\n  \"oneTimeAt\": \"2024-10-26T21:27:05.021Z\",\n  \"draftIds\": [\n    5548,\n    2741\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift api_v1_schedules_Create a publish schedule_example
import Foundation

let headers = [
  "X-Api-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "Monday breakfast publish",
  "scheduleType": "recurring",
  "publishMode": "all_mapped",
  "outletIds": ["5af196ce-e70e-e254-b289-1bd0af19f9b5", "5317819f-55f6-cb46-8607-d7da351ae7b1"],
  "cronExpr": "0 8 * * 1",
  "timezone": "Asia/Singapore",
  "oneTimeAt": "2024-10-26T21:27:05.021Z",
  "draftIds": [5548, 2741]
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "http://localhost:8080/api/v1/schedules")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```