openapi: 3.0.3

info:
  title: Contact Relationships
  description: "Actionstep provide a feature to manage relationships between contacts. This is useful for tracking relationships between clients, contacts, and other entities in your system. For example, you might want to track that a client is the spouse of another client, or that a contact is the parent of a child. The contact relationships endpoint allow you to create and manage these relationships using the Actionstep API. 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: Tutorial - Working with Contact Relationships
  url: https://docs.actionstep.com/tutorial-contact-relationships/

paths:
  '/contactrelationships':
    get:
      description: Returns the collection of all contact relationships.
      tags:
        - Contact Relationships
      responses:
        '200':
          description: OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PagedContactRelationships'

    post:
      description: Create a new contact relationship.
      tags:
        - Contact Relationships
      requestBody:
        $ref: '#/components/requestBodies/CreateContactRelationship'
      responses:
        '200':
          description: OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateContactRelationship'

  '/contactrelationships/{id}':
    get:
      description: Returns a single contact relationship record.
      tags:
        - Contact Relationships
      parameters:
        - name: id
          in: path
          description: Unique identifier for a single contact relationship record. The identifier is composed from the relationship, fromContact, and toContact properties separated by "--".
          required: true
          schema:
            type: string
            format: string
          example: Father-41854-845258
      responses:
        '200':
          description: OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContactRelationship'

    delete:
      description: Deletes a single contact relationship record.
      tags:
        - Contact Relationships
      parameters:
        - name: id
          in: path
          description: Unique identifier for a single contact relationship record. The identifier is composed from the relationship, fromContact, and toContact properties separated by "--".
          required: true
          schema:
            type: string
            format: string
          example: Father-41854-845258
      responses:
        '204':
          description: Success, No Content.

components:
  schemas:
    PagedContactRelationships:
      type: object
      properties:
        contactrelationships:
          type: array
          items:
            $ref: '#/components/schemas/ContactRelationship'
        meta:
          $ref: '#/components/schemas/PageMetaData'

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

    PagingData:
      type: object
      properties:
        contactrelationships:
          $ref: '#/components/schemas/ContactRelationshipsPageData'

    ContactRelationshipsPageData:
      type: object
      properties:
        recordCount:
          description: The total number of contact relationship records 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 contact relationship records.
          type: integer
          example: 2
        pageSize:
          description: Page size.
          type: integer
          example: 50
        prevPage:
          description: A URL to the previous page of contact relationship records.
          type: string
          example: https://ap-southeast-2.actionstep.com/api/rest/contactrelationships?page=1
        nextPage:
          description: A URL to the next page of contact relationship records.
          type: string
          example: https://ap-southeast-2.actionstep.com/api/rest/contactrelationships?page=3

    ContactRelationship:
      type: object
      properties:
        id:
          description: Unique identifier for a single contact relationship record. The identifier is composed from the relationship, fromContact, and toContact properties separated by "--".
          type: string
          format: string
          example: Father-41854-845258
          readOnly: true
        relationship:
          description: The relationship name between the two contacts.
          type: string
          format: string
          example: Father
        links:
          $ref: '#/components/schemas/ContactRelationshipLinks'

    ContactRelationshipLinks:
      type: object
      properties:
        fromContact:
          description: Unique identifier for the contact from which a relationship is established.
          example: 41854
          type: integer
          readOnly: true
        toContact:
          description: Unique identifier for the contact to which a relationship is established.
          example: 321845
          type: integer
          readOnly: true          

    CreateContactRelationship:
      type: object
      required:
        - relationship
      properties:
        relationship:
          description: The relationship name between the two contacts.
          type: string
          format: string
          example: Father
        links:
          $ref: '#/components/schemas/CreateContactRelationshipLinks'

    CreateContactRelationshipLinks:
      type: object
      required:
        - fromContact
        - toContact
      properties:
        fromContact:
          description: Unique identifier for the contact from which a relationship is to be established.
          example: 41854
          type: integer
        toContact:
          description: Unique identifier for the contact to which a relationship is to be established.
          example: 321845
          type: integer

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