# Set schedule rules for workflow

- Operation ID: `setDiagramSchedule`
- HTTP method: `POST`
- Path: `/automation-brain/diagrams/{diagramId}/schedule`
- [Human-readable API reference](https://hub.synerise.com/api-reference/automation#tag/Workflow-schedules/operation/setDiagramSchedule)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /automation-brain/diagrams/{diagramId}/schedule:
    post:
      security:
        - JWT: []
      tags:
        - Workflow schedules
      summary: Set schedule rules for workflow
      description: |
        Set schedule rules for a workflow. This lets you activate, pause, or stop a workflow according to a plan. 

        After the schedule is set, it must be activated to take effect (see the `POST /automation-brain/diagrams/{diagramId}/schedule-on` method).  

        **The backend doesn't validate the logic of the schedule**. You must ensure it's well-built (rules make logical sense) and complies with the structure of the workflow (such as trigger node time rules). See ["Workflow Scheduler > Important" in the Synerise Hub](https://hub.synerise.com/docs/automation/workflow-scheduler#important).

        The contents of this request overwrite an existing schedule.


        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>, <a href="/api-reference/authorization?tag=Authorization&amp;operationId=profileLogin" target="_blank" rel="noopener">Workspace (Business Profile)</a>

        **API key permission required:** `AUTOMATON_BRAIN_DIAGRAM_SCHEDULE_UPDATE`

        **User role permission required:** `automation_2_journeys: update`
      operationId: setDiagramSchedule
      parameters:
        - name: diagramId
          in: path
          description: UUID of the workflow/diagram
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                timezone:
                  description: |
                    Timezone of the schedule. Accepts these formats:
                    - "Europe/Paris"
                    - "-05:00"
                    - "UTC-1"
                  type: string
                  example: Europe/Paris
                rules:
                  type: array
                  description: Rules of the schedule
                  items:
                    type: object
                    properties:
                      ruleId:
                        type: string
                        format: uuid
                        description: In POST requests, rule ID is only used in `preview` requests. It lets you match a rule with upcoming events and status changes.
                      actionType:
                        type: string
                        description: The status to apply when the rule runs. **A stopped workflow can't be restarted**.
                        enum:
                          - Resume
                          - Pause
                          - Stop
                      repeatModel:
                        description: Repetition times
                        type: object
                        required:
                          - repeatType
                          - body
                        properties:
                          repeatType:
                            description: |
                              Repetition type. **Currently, only `OnDate` is compatible with the Synerise Web Portal.**

                              - "Interval" runs the rule after a counter finishes. Then the counter restarts.
                              - "Daily" runs the rule at a specific time each day.
                              - "Weekly" runs the rule on specific days of the week, at a specific time.
                              - "Monthly" runs the rule on specific days of the month, at a specific time.
                              - "OnDate" runs the rule once, at a specific date and time.
                            type: string
                            enum:
                              - Interval
                              - Daily
                              - Weekly
                              - Monthly
                              - OnDate
                          body:
                            description: Repetition time
                            oneOf:
                              - title: Interval
                                type: object
                                required:
                                  - start
                                  - intervalSeconds
                                properties:
                                  start:
                                    type: string
                                    description: Date and time to start counting the interval from
                                    format: date-time
                                    example: 2020-01-01T01:00:00.000
                                  intervalSeconds:
                                    type: integer
                                    minimum: 3600
                                    maximum: 31536000
                                    description: The interval value in seconds
                                    example: 6000
                              - title: Daily
                                type: object
                                required:
                                  - hours
                                properties:
                                  hours:
                                    type: array
                                    description: Used for running the rule at a specific time or times every day.
                                    items:
                                      type: string
                                      description: Hour with minutes
                                      example: 12:30
                              - title: Weekly
                                type: object
                                required:
                                  - daysOfWeek
                                properties:
                                  daysOfWeek:
                                    type: array
                                    description: Used for running the rule on specific days of the week.
                                    items:
                                      type: object
                                      required:
                                        - day
                                        - dayTime
                                        - ruleId
                                      properties:
                                        day:
                                          type: integer
                                          description: Number of the day in the week. `1` is Monday.
                                        dayTime:
                                          type: string
                                          description: Hour with minutes
                                          example: 21:37
                                        ruleId:
                                          type: integer
                                          description: Number of the rule
                              - title: Monthly
                                type: object
                                required:
                                  - daysOfMonth
                                properties:
                                  daysOfMonth:
                                    type: array
                                    description: Used for running the automation on specific days of the month.
                                    items:
                                      type: object
                                      required:
                                        - day
                                        - dayTime
                                        - ruleId
                                      properties:
                                        day:
                                          type: integer
                                          description: Days of the month with. `-1` is the last day of the month.
                                        dayTime:
                                          type: string
                                          description: Hour with minutes
                                          example: 21:37
                                        ruleId:
                                          type: integer
                                          description: Number of rule
                              - title: OnDate
                                type: object
                                required:
                                  - date
                                properties:
                                  date:
                                    type: string
                                    description: A date and time when the rule runs.
                                    example: 2020-01-01T01:00:00.000
                    required:
                      - actionType
                      - repeatModel
              required:
                - timezone
                - rules
        required: true
      responses:
        "200":
          description: Schedule saved
          content:
            application/json:
              schema:
                type: object
                properties:
                  active:
                    description: "`true` if schedule is enabled."
                    type: boolean
                  timezone:
                    description: |
                      Timezone of the schedule. Accepts these formats:
                      - "Europe/Paris"
                      - "-05:00"
                      - "UTC-1"
                    type: string
                    example: Europe/Paris
                  rules:
                    type: array
                    description: Rules of the schedule
                    items:
                      type: object
                      properties:
                        ruleId:
                          type: string
                          format: uuid
                          description: Unique ID of the rule
                        actionType:
                          type: string
                          description: The status to apply when the rule runs. **A stopped workflow can't be restarted**.
                          enum:
                            - Resume
                            - Pause
                            - Stop
                        repeatModel:
                          description: Repetition times
                          type: object
                          required:
                            - repeatType
                            - body
                          properties:
                            repeatType:
                              description: |
                                Repetition type. **Currently, only `OnDate` is compatible with the Synerise Web Portal.**

                                - "Interval" runs the rule after a counter finishes. Then the counter restarts.
                                - "Daily" runs the rule at a specific time each day.
                                - "Weekly" runs the rule on specific days of the week, at a specific time.
                                - "Monthly" runs the rule on specific days of the month, at a specific time.
                                - "OnDate" runs the rule once, at a specific date and time.
                              type: string
                              enum:
                                - Interval
                                - Daily
                                - Weekly
                                - Monthly
                                - OnDate
                            body:
                              description: Repetition time
                              oneOf:
                                - title: Interval
                                  type: object
                                  required:
                                    - start
                                    - intervalSeconds
                                  properties:
                                    start:
                                      type: string
                                      description: Date and time to start counting the interval from
                                      format: date-time
                                      example: 2020-01-01T01:00:00.000
                                    intervalSeconds:
                                      type: integer
                                      minimum: 3600
                                      maximum: 31536000
                                      description: The interval value in seconds
                                      example: 6000
                                - title: Daily
                                  type: object
                                  required:
                                    - hours
                                  properties:
                                    hours:
                                      type: array
                                      description: Used for running the rule at a specific time or times every day.
                                      items:
                                        type: string
                                        description: Hour with minutes
                                        example: 12:30
                                - title: Weekly
                                  type: object
                                  required:
                                    - daysOfWeek
                                  properties:
                                    daysOfWeek:
                                      type: array
                                      description: Used for running the rule on specific days of the week.
                                      items:
                                        type: object
                                        required:
                                          - day
                                          - dayTime
                                          - ruleId
                                        properties:
                                          day:
                                            type: integer
                                            description: Number of the day in the week. `1` is Monday.
                                          dayTime:
                                            type: string
                                            description: Hour with minutes
                                            example: 21:37
                                          ruleId:
                                            type: integer
                                            description: Number of the rule
                                - title: Monthly
                                  type: object
                                  required:
                                    - daysOfMonth
                                  properties:
                                    daysOfMonth:
                                      type: array
                                      description: Used for running the automation on specific days of the month.
                                      items:
                                        type: object
                                        required:
                                          - day
                                          - dayTime
                                          - ruleId
                                        properties:
                                          day:
                                            type: integer
                                            description: Days of the month with. `-1` is the last day of the month.
                                          dayTime:
                                            type: string
                                            description: Hour with minutes
                                            example: 21:37
                                          ruleId:
                                            type: integer
                                            description: Number of rule
                                - title: OnDate
                                  type: object
                                  required:
                                    - date
                                  properties:
                                    date:
                                      type: string
                                      description: A date and time when the rule runs.
                                      example: 2020-01-01T01:00:00.000
                        listingAuthor:
                          type: object
                          description: Author of the rule
                          properties:
                            userId:
                              type: number
                              description: Unique ID of a Synerise user
                        createdAt:
                          type: string
                          example: 2020-01-01T01:00:00Z
                          format: date-time
                          description: Date and time when the rule was created
                      required:
                        - ruleId
                        - actionType
                        - repeatModel
                        - listingAuthor
                        - createdAt
                required:
                  - active
                  - timezone
                  - rules
        "400":
          description: See error message for details
          content:
            text/plain:
              schema:
                type: string
                description: Description of the problem
        "401":
          description: "Unauthorized: wrong consumer scope; token missing/expired/invalid; invalid API key; etc."
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Summary of the error
                  status:
                    type: integer
                    format: int32
                    description: Status code
                  timestamp:
                    type: string
                    description: Time when the message was sent
                  message:
                    type: string
                    description: Description of the problem
        "403":
          description: Forbidden; insufficient permissions
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Summary of the error
                  status:
                    type: integer
                    format: int32
                    description: Status code
                  timestamp:
                    type: string
                    description: Time when the message was sent
                  message:
                    type: string
                    description: Description of the problem
        "404":
          description: Resource not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Summary of the error
                  status:
                    type: integer
                    format: int32
                    description: Status code
                  timestamp:
                    type: string
                    description: Time when the message was sent
                  message:
                    type: string
                    description: Description of the problem
      x-snr-doc-urls:
        - /api-reference/automation#tag/Workflow-schedules/operation/setDiagramSchedule
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/automation-brain/diagrams/%7BdiagramId%7D/schedule \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"timezone":"Europe/Paris","rules":[{"ruleId":"70af3071-65d9-4ec3-b3cb-5283e8d55dac","actionType":"Resume","repeatModel":{"repeatType":"Interval","body":{"start":"2020-01-01T01:00:00.000","intervalSeconds":6000}}}]}'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            payload = "{\"timezone\":\"Europe/Paris\",\"rules\":[{\"ruleId\":\"70af3071-65d9-4ec3-b3cb-5283e8d55dac\",\"actionType\":\"Resume\",\"repeatModel\":{\"repeatType\":\"Interval\",\"body\":{\"start\":\"2020-01-01T01:00:00.000\",\"intervalSeconds\":6000}}}]}"

            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("POST", "/automation-brain/diagrams/%7BdiagramId%7D/schedule", payload, headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "timezone": "Europe/Paris",
              "rules": [
                {
                  "ruleId": "70af3071-65d9-4ec3-b3cb-5283e8d55dac",
                  "actionType": "Resume",
                  "repeatModel": {
                    "repeatType": "Interval",
                    "body": {
                      "start": "2020-01-01T01:00:00.000",
                      "intervalSeconds": 6000
                    }
                  }
                }
              ]
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("POST", "https://api.synerise.com/automation-brain/diagrams/%7BdiagramId%7D/schedule");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");
            xhr.setRequestHeader("content-type", "application/json");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "POST",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/automation-brain/diagrams/%7BdiagramId%7D/schedule",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN",
                "content-type": "application/json"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.write(JSON.stringify({
              timezone: 'Europe/Paris',
              rules: [
                {
                  ruleId: '70af3071-65d9-4ec3-b3cb-5283e8d55dac',
                  actionType: 'Resume',
                  repeatModel: {
                    repeatType: 'Interval',
                    body: {start: '2020-01-01T01:00:00.000', intervalSeconds: 6000}
                  }
                }
              ]
            }));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/automation-brain/diagrams/%7BdiagramId%7D/schedule');
            $request->setMethod(HTTP_METH_POST);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"timezone":"Europe/Paris","rules":[{"ruleId":"70af3071-65d9-4ec3-b3cb-5283e8d55dac","actionType":"Resume","repeatModel":{"repeatType":"Interval","body":{"start":"2020-01-01T01:00:00.000","intervalSeconds":6000}}}]}');

            try {
              $response = $request->send();

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.post("https://api.synerise.com/automation-brain/diagrams/%7BdiagramId%7D/schedule")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"timezone\":\"Europe/Paris\",\"rules\":[{\"ruleId\":\"70af3071-65d9-4ec3-b3cb-5283e8d55dac\",\"actionType\":\"Resume\",\"repeatModel\":{\"repeatType\":\"Interval\",\"body\":{\"start\":\"2020-01-01T01:00:00.000\",\"intervalSeconds\":6000}}}]}")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Workflow schedules
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
```
