> ## Documentation Index
> Fetch the complete documentation index at: https://docs.minimo.it/llms.txt
> Use this file to discover all available pages before exploring further.

# Save Default Rules

> Create or update rules for every restaurant, by key

Guide: [Rules](https://docs.minimo.it/embedded/automations.md). Errors: [Errors and limits](https://docs.minimo.it/embedded/errors.md).


## OpenAPI

````yaml put /public/v1/automation-rules
openapi: 3.1.0
info:
  title: API Documentation
  description: Documentation for transactional and subscribe APIs
  version: 1.0.0
servers:
  - url: https://app.minimo.it
security:
  - bearerAuth: []
paths:
  /public/v1/automation-rules:
    servers:
      - url: https://api.minimo.it
    put:
      summary: Save default rules
      description: >-
        Creates or updates rules for every restaurant, by `key`. Keys you do not
        send stay as they are.


        Each new rule needs `key`, `event` and `template`. Add `offset` and
        `dateField` for a timed email.
      operationId: saveAutomationRules
      parameters:
        - name: locale
          in: query
          required: false
          description: Language of the `timing` text in the answer.
          schema:
            type: string
            enum:
              - en
              - it
            default: en
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                rules:
                  type: array
                  items:
                    $ref: '#/components/schemas/AutomationRuleInput'
              required:
                - rules
            example:
              rules:
                - key: confirmation
                  name: Booking confirmation
                  event: booking.created
                  template: TRF4MS9
                - key: reminder
                  name: Reminder 2 hours before
                  event: booking.created
                  template: RMD2HRS
                  offset: '-PT2H'
                  dateField: booking_at
      responses:
        '200':
          description: All your default rules after the change
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/AutomationRule'
              example:
                data:
                  - key: confirmation
                    name: Booking confirmation
                    event: booking.created
                    template: 1201
                    templateUid: TRF4MS9
                    offset: null
                    dateField: null
                    timing: Immediately
                    enabled: true
                    cancelOn:
                      - booking.cancelled
                    rescheduleOn: []
                    source: default
                  - key: reminder
                    name: Reminder 2 hours before
                    event: booking.created
                    template: 1202
                    templateUid: RMD2HRS
                    offset: '-PT2H'
                    dateField: booking_at
                    timing: 2 hours before
                    enabled: true
                    cancelOn:
                      - booking.cancelled
                    rescheduleOn:
                      - booking.updated
                    source: default
        '401':
          description: >-
            `INVALID_TOKEN`: missing or wrong key, or a key without the
            **Widgets** permission.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
        '422':
          description: '`INVALID_AUTOMATION_RULE`: `userMessage` says which field.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiError'
      security:
        - bearerAuth: []
      x-codeSamples:
        - label: cURL
          lang: bash
          source: |-
            curl --request PUT \
              --url 'https://api.minimo.it/public/v1/automation-rules' \
              --header 'Authorization: Bearer YOUR_MINIMO_KEY' \
              --header 'Content-Type: application/json' \
              --data '{"rules": [{"key": "confirmation", "name": "Booking confirmation", "event": "booking.created", "template": "TRF4MS9"}, {"key": "reminder", "name": "Reminder 2 hours before", "event": "booking.created", "template": "RMD2HRS", "offset": "-PT2H", "dateField": "booking_at"}]}'
        - lang: JavaScript
          source: >-
            const res = await
            fetch('https://api.minimo.it/public/v1/automation-rules', {
              method: 'PUT',
              headers: {
                Authorization: 'Bearer YOUR_MINIMO_KEY',
                'Content-Type': 'application/json',
              },
              body: JSON.stringify({"rules": [{"key": "confirmation", "name": "Booking confirmation", "event": "booking.created", "template": "TRF4MS9"}, {"key": "reminder", "name": "Reminder 2 hours before", "event": "booking.created", "template": "RMD2HRS", "offset": "-PT2H", "dateField": "booking_at"}]}),
            });

            const { data } = await res.json();

            console.log(data);
        - lang: Python
          source: |-
            import requests

            res = requests.put(
                'https://api.minimo.it/public/v1/automation-rules',
                headers={'Authorization': 'Bearer YOUR_MINIMO_KEY'},
                json={"rules": [{"key": "confirmation", "name": "Booking confirmation", "event": "booking.created", "template": "TRF4MS9"}, {"key": "reminder", "name": "Reminder 2 hours before", "event": "booking.created", "template": "RMD2HRS", "offset": "-PT2H", "dateField": "booking_at"}]},
            )
            print(res.status_code, res.text)
components:
  schemas:
    AutomationRuleInput:
      type: object
      properties:
        key:
          type: string
          maxLength: 64
          description: >-
            Stable name of the rule, up to 64 characters. Saving a key that
            exists updates it.
          example: reminder
        name:
          type: string
          nullable: true
          maxLength: 120
          description: Name the restaurant sees in the widget.
          example: Reminder 2 hours before
        event:
          type: string
          maxLength: 100
          description: Event that schedules the email.
          example: booking.created
        template:
          oneOf:
            - type: integer
            - type: string
          description: >-
            Master template, by id (number) or uid (string). The restaurant's
            own copy is sent when it has one.
          example: RMD2HRS
        offset:
          type: string
          nullable: true
          description: >-
            ISO 8601 duration from `dateField`: `-PT2H` = 2 hours before, `PT2H`
            = 2 hours after, `-P1D` = a day before. `null` or omitted = right
            away.
          example: '-PT2H'
        dateField:
          type: string
          maxLength: 200
          description: >-
            Path of the date in the event `payload` the offset counts from.
            Needed with `offset`.
          example: booking_at
        enabled:
          type: boolean
          description: Default `true`.
        cancelOn:
          type: array
          items:
            type: string
          example:
            - booking.cancelled
          description: >-
            Events that cancel the pending email. Default: the event name with
            `.cancelled` (`booking.created` gives `booking.cancelled`).
        rescheduleOn:
          type: array
          items:
            type: string
          example:
            - booking.updated
          description: >-
            Events that move the pending email to the new date. Default: the
            event name with `.updated`.
      required:
        - key
    AutomationRule:
      type: object
      properties:
        key:
          type: string
          description: Stable name of the rule.
          example: reminder
        name:
          type: string
          nullable: true
          description: Name the restaurant sees in the widget.
          example: Reminder 2 hours before
        event:
          type: string
          description: Event that schedules the email.
          example: booking.created
        template:
          type: integer
          description: Master template id.
          example: 1202
        templateUid:
          type: string
          description: Master template uid.
          example: RMD2HRS
        offset:
          type: string
          nullable: true
          description: >-
            ISO 8601 duration from `dateField`: `-PT2H` = 2 hours before, `PT2H`
            = 2 hours after. `null` = right away.
          example: '-PT2H'
        dateField:
          type: string
          nullable: true
          description: Path of the date in the event `payload` the offset counts from.
          example: booking_at
        timing:
          type: string
          description: The timing in words.
          example: 2 hours before
        enabled:
          type: boolean
        cancelOn:
          type: array
          items:
            type: string
          example:
            - booking.cancelled
          description: Events that cancel the pending email (same `cancellationKey`).
        rescheduleOn:
          type: array
          items:
            type: string
          example:
            - booking.updated
          description: Events that move the pending email to the new date.
        source:
          type: string
          enum:
            - default
            - override
            - tenant
          description: >-
            `default`: your rule for every restaurant. `override`: a default
            this restaurant changed. `tenant`: the restaurant's own rule.
      required:
        - key
        - name
        - event
        - template
        - templateUid
        - offset
        - dateField
        - timing
        - enabled
        - cancelOn
        - rescheduleOn
        - source
    ApiError:
      type: object
      properties:
        status:
          type: string
          example: FAIL
        message:
          type: string
          description: The error code to test in your code.
          example: INVALID_PARAMETERS
        userMessage:
          type: string
          description: >-
            When present, a sentence that says what to fix. You can show or log
            it.
          example: Set the origins allowed to embed the widgets first.
      description: >-
        Every error has this shape. See [Errors and limits](/embedded/errors)
        for every code.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: mn-API_CLIENT_ID-API_KEY

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.