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

# Create automation



## OpenAPI

````yaml /openapi/public/openapi-flow.json post /automation
openapi: 3.0.0
info:
  title: MileApp API - Flow
  version: 3.0.0
  description: MileApp API Documentation - RESTful API for field operations management.
servers:
  - url: https://apiweb.mile.app/api/v3
security:
  - bearerAuth: []
tags:
  - name: Flow
    description: >-
      Flow in MileApp is the mobile field application workflow, setting it
      correctly is critical to the success of the field workers in doing their
      job efficiently. Flow attributes consist of IDs, pages, components,
      configurations, and time. The Flow will be used at Task, Automation, or
      Schedule.


      **To see the details of flow object, please follow [this
      link](#tag/flow_model)**
  - name: Automation
    description: >-
      Automation enables you to set up automation based on tasks' events and
      data source's events. It might help you automate creation of tasks, task
      assignment, task placement, task webhook, data source update, datasource
      creation, and data source webhook. Automation attributes consist of IDs,
      automation name, automation type, automation details, and rules.


      **To see the details of automation object, please follow [this
      link](#tag/automation_model)**
paths:
  /automation:
    post:
      tags:
        - Automation
      summary: Create automation
      operationId: CreateAutomationTypeCreateTask
      requestBody:
        $ref: '#/components/requestBodies/BaseBodyAutomation'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Status of response.
                  message:
                    description: Message of API response.
                    type: string
                  data:
                    description: Detail of object automation.
                    type: object
                    additionalProperties: true
              examples:
                response:
                  value:
                    status: true
                    message: Success
                    data:
                      name: Auto create task automation
                      event: onTaskFinished
                      automationType: createTask
                      dataType: task
                      automationDetails:
                        flow: Delivery
                        flowId: 667b75b29edc36517c609ac2
                        taskData:
                          customerName: vasco
                          address: Jakarta
                          description: $refFlow.name
                      rules:
                        flow: Pickup
                        flowId: 667b712f63020e5f182f0cb2
                        fields:
                          name: roger
                          address: kemayoran
                      organizationId: 621dd813eb3ebf16b94dbde3
                      isActive: true
                      updatedTime: '2022-07-13T03:16:40+00:00'
                      createdTime: '2022-07-13T03:16:40+00:00'
                      _id: 62ce3918d3f3e1681a3a54b1
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Shows if the request was successful.
                  message:
                    type: string
                    description: A short message explaining what went wrong.
                example:
                  status: false
                  message: Bad request - invalid parameters provided.
        '500':
          description: Server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: boolean
                    description: Shows if the request was successful.
                  message:
                    type: string
                    description: A short message explaining what went wrong.
                example:
                  status: false
                  message: Internal server error, please contact support@mile.app.
      deprecated: false
      security:
        - bearerAuth: []
components:
  requestBodies:
    BaseBodyAutomation:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/BaseBodyAutomation'
      required: true
      x-examples:
        application/json:
          createTask:
            summary: Create task automation
            value:
              name: Create task automation
              event: onTaskFinished
              automationType: createTask
              dataType: task
              automationDetails:
                flow: Delivery
                flowId: 667b75b29edc36517c609ac2
                taskData:
                  customerName: vasco
                  address: Jakarta
                  description: $refFlow.name
              rules:
                flow: Pickup
                flowId: 667b712f63020e5f182f0cb2
                fields:
                  name: roger
                  address: kemayoran
          createAssignTask:
            summary: Create and assign automation
            value:
              name: Create and assign automation
              event: onTaskFinished
              automationType: createAssignTask
              dataType: task
              automationDetails:
                flow: Delivery
                flowId: 667b75b29edc36517c609ac2
                hubId: 634e98498ce07d29474a7e29
                assignee:
                  - roberto@mile.app
                taskData:
                  customerName: Da Gama
                  address: Jakarta
                  description: $refFlow.name
              rules:
                flow: Pickup
                flowId: 667b712f63020e5f182f0cb2
                fields:
                  name: gaban
                  address: pejaten
          moveTask:
            summary: Move task automation
            value:
              name: Move task automation
              event: onTaskCreated
              automationType: moveTask
              dataType: task
              automationDetails:
                hubId: 634e98498ce07d29474a7e29
              rules:
                flow: Pickup
                flowId: 667b712f63020e5f182f0cb2
                fields:
                  name: sam
                  address: pulogadung
          assignTask:
            summary: Assign task automation
            value:
              name: Assign task automation
              event: onTaskCreated
              automationType: assignTask
              dataType: task
              automationDetails:
                hubId: 634e98498ce07d29474a7e29
                assignee:
                  - roberto@mile.app
              rules:
                flow: Pickup
                flowId: 667b712f63020e5f182f0cb2
                fields:
                  name: bams
                  address: bogor
          webhook:
            summary: Webhook automation
            value:
              name: Webhook automation
              event: onTaskFinished
              automationType: webhook
              dataType: task
              automationDetails:
                url: https://apiweb.mile.app/webhook
                headers:
                  x-api-key: 1234e98498ce07d29474a7ev2
                  org: general
              rules:
                flow: Pickup
                flowId: 667b712f63020e5f182f0cb2
          createOrUpdateDataSource:
            summary: Update datasource automation
            value:
              name: Update datasource automation
              event: onTaskFinished
              automationType: createOrUpdateDataSource
              dataType: task
              automationDetails:
                dataTypeId: 644fcd63562387038543fce2
                dataId: $refFlow.pickupNumber
                dataSource:
                  customerName: vasco
                  address: jakarta
                  contact: $refFlow.phoneNumber
              rules:
                flow: Pickup
                flowId: 667b712f63020e5f182f0cb2
                fields:
                  name: sam
                  address: pulogadung
          createDataSource:
            summary: Create task automation on data source created
            value:
              name: Create task automation on data source created
              event: onDataSourceCreated
              automationType: createTask
              dataType: data
              automationDetails:
                flow: Delivery
                flowId: 667b75b29edc36517c609ac2
                taskData:
                  customerName: vasco
                  address: Jakarta
                  description: $refData.name
              rules:
                dataTypeId: 644fcd63562387038543fce2
                fields:
                  name: roger
                  address: kemayoran
          webhookDataSource:
            summary: Webhook automation on data source created
            value:
              name: Webhook automation on data source created
              event: onDataSourceCreated
              automationType: webhook
              dataType: data
              automationDetails:
                url: https://apiweb.mile.app/webhook
                headers:
                  x-api-key: 1234e98498ce07d29474a7ev2
                  org: general
              rules:
                dataTypeId: 644fcd63562387038543fce2
          notificationChannelWhatsApp:
            summary: Notification WhatsApp on task created
            value:
              name: Notification WhatsApp on task created
              event: onTaskCreated
              automationType: notification
              dataType: task
              automationDetails:
                channel: whatsApp
                taskFieldReceiver: customerNumber
                secretKey: '`wWbN#T!_UTATzFRXrd@X'
                message: >-
                  Greeting, we are from {organization_name} and will be
                  delivering to your location. Track your delivery here {link}.
                  Thank you
              rules:
                fields:
                  statusPickup: success
                flow: Pickup
                flowId: 667b712f63020e5f182f0cb2
  schemas:
    BaseBodyAutomation:
      x-discriminator: automationDetails
      type: object
      required:
        - name
        - event
        - automationType
      properties:
        name:
          type: string
          description: |-
            Automation's name.
            **Example:** `Auto create task automation`
        event:
          type: string
          description: >-
            Act as a trigger that start an automation. There are 8 different
            types. 
             *enum: onTaskCreated, onTaskFinished, onTaskAssigned, onDataSourceCreated, onRoutingResultFinished, onRoutingResultDispatched, onStartTrip, onFinishTrip* 
             **onTaskCreated**: Automation will happen when a task is created. 
             **onTaskFinished**: Automation will happen when a task is finished (status task: Done). 
             **onTaskAssigned**: Automation will happen when a task is assigned to field user(s). 
             **onDataSourceCreated**: Automation will happen when a data source is created. 
             **onRoutingResultFinished**: Automation will happen when a routing created is created. 
             **onRoutingResultDispatched**: Automation will happen when a routing is dispatched. 
             **onStartTrip**: Automation will happen when a start trip is triggered. 
             **onFinishTrip**: Automation will happen when a finish trip is triggered. 
            **Example:** `onTaskFinished`
        dataType:
          type: string
          description: |-
            Automation's data type. There are 4 different types. 
             *enum: task, data, routingResult, locationHistory* 
             **Default:** `task`
        isActive:
          type: string
          description: >-
            Automation's active state, only active automation will proceed by
            system

            **Default:** `true`
        automationType:
          type: string
          description: >-
            Automation's type. The changes you want to automate. There are 6
            different types: 
              *enum: createTask, createAssignTask, moveTask, assignTask, webhook, createOrUpdateDataSource, notification* 
             **createTask**: The task will create when an event happens. 
            **Example**: `createTask`
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Use a valid Bearer token to authenticate.

````