openapi: 3.0.3

info:
  title: REST Hooks
  description: "For retrieving and managing REST hooks. For information of how to construct requests utilising fieldsets, sorting, paging, filters, and '*includes*', please refer to the API Developer Portal. E&OE."
  version: "1.0"

externalDocs:
  description: API Developer Portal - Constructing API Requests
  url: https://docs.actionstep.com/api-requests/

paths:
  '/resthooks':
    get:
      description: Returns a collection of REST hooks.
      tags:
        - REST Hooks
      responses:
        '200':
          description: OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PagedRESTHooks'

    post:
      description: Create a new REST hook.
      tags:
        - REST Hooks
      requestBody:
        $ref: '#/components/requestBodies/CreateRESTHook'
      responses:
        '200':
          description: OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RESTHook'

  '/resthooks/{id}':
    get:
      description: Returns a single REST hook.
      tags:
        - REST Hooks
      parameters:
        - name: id
          in: path
          description: Unique identifier for a REST hook.
          required: true
          schema:
            type: integer
            format: int32
          example: 9287
      responses:
        '200':
          description: OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RESTHook'

    put:
      description: Update a REST hook.
      tags:
        - REST Hooks
      parameters:
        - name: id
          in: path
          description: Unique identifier for a REST hook.
          required: true
          schema:
            type: integer
            format: int32
          example: 608
      requestBody:
        $ref: '#/components/requestBodies/UpdateRESTHook'
      responses:
        '200':
          description: OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RESTHook'

    delete:
      description: Delete a REST hook.
      tags:
        - REST Hooks
      parameters:
        - name: id
          in: path
          description: Unique identifier for a REST hook.
          required: true
          schema:
            type: integer
            format: int32
          example: 608
      responses:
        '204':
          description: Success, No Content.

components:
  schemas:
    PagedRESTHooks:
      type: object
      properties:
        resthooks:
          type: array
          items:
            $ref: '#/components/schemas/RESTHook'
        meta:
          $ref: '#/components/schemas/PageMetaData'

    PageMetaData:
      type: object
      properties:
        paging:
          $ref: '#/components/schemas/PagingData'

    PagingData:
      type: object
      properties:
        resthooks:
          $ref: '#/components/schemas/RESTHooksPageData'

    RESTHooksPageData:
      type: object
      properties:
        recordCount:
          description: The total number of REST hooks returned by the underlying query.
          type: integer
          example: 2487
        pageCount:
          description: The total number of pages generated by the underlying query.
          type: integer
          example: 50
        page:
          description: The page number for this page of REST hooks.
          type: integer
          example: 2
        pageSize:
          description: Page size.
          type: integer
          example: 50
        prevPage:
          description: A URL to the previous page of REST hooks.
          type: string
          example: https://ap-southeast-2.actionstep.com/api/rest/resthooks?page=1
        nextPage:
          description: A URL to the next page of REST hooks.
          type: string
          example: https://ap-southeast-2.actionstep.com/api/rest/resthooks?page=3

    RESTHook:
      type: object
      properties:
        id:
          description: Unique identifier for the REST hook.
          example: 685
          type: integer
        eventName:
          description: Name of the event.
          example: ActionDocumentCreated.
          type: string
          externalDocs:
            description: For the complete list of supported events please reference the API Developer Portal.
            url: https://docs.actionstep.com/webhooks/
        targetUrl:
          description: Url to be called.
          example: https://0486-222-152-188-245.ngrok-free.app/api/resthook
          type: string
        status:
          description: Status of the REST hook.
          enum:
            - Active
            - Disabled
            - Deleted
          type: string
        triggeredCount:
          description: Number of times the REST hook has been triggered.
          example: 870
          type: integer
        triggeredLastTimestamp:
          description: The last date and time the REST hook was triggered.
          example: 2022-05-03T00:09:00+12:00
          format: timestamp
          type: string

    CreateRESTHook:
      type: object
      required:
        - eventName
        - targetUrl
      properties:
        eventName:
          description: Name of the event.
          example: ActionDocumentCreated.
          type: string
          externalDocs:
            description: For the complete list of supported events please reference the API Developer Portal.
            url: https://docs.actionstep.com/webhooks/
        targetUrl:
          description: Url to be called.
          example: https://0486-222-152-188-245.ngrok-free.app/api/resthook
          type: string

    UpdateRESTHook:
      type: object
      required:
        - eventName
        - targetUrl
      properties:
        eventName:
          description: Name of the event.
          example: ActionDocumentCreated.
          type: string
          externalDocs:
            description: For the complete list of supported events please reference the API Developer Portal.
            url: https://docs.actionstep.com/webhooks/
        targetUrl:
          description: Url to be called.
          example: https://0486-222-152-188-245.ngrok-free.app/api/resthook
          type: string

  requestBodies:
    CreateRESTHook:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/CreateRESTHook'

    UpdateRESTHook:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UpdateRESTHook'