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

# Update Domain Mapping

> Updates an existing domain mapping.



## OpenAPI

````yaml https://api.twine.se/spec/openapi.json put /v1/org/domain-mappings/{domain_mapping_id}
openapi: 3.0.3
info:
  contact:
    email: help@twine.se
    name: Twine Support
  description: >+
    # Introduction

    Welcome to the Twine Public API reference. This API allows you to read data
    from Twine's system, and to write data back for supported domains. See the
    Pushing data section below for what can be written.


    # Versioning

    The API is versioned. The current version is v1.1, served under the `/v1`
    path. As the API is subject to change, new versions may be released. Always
    refer to the latest documentation to ensure you're using the correct
    version.


    ## Dated model attributes

    In v1.1, every entity field is tracked by change date. This allows you to
    fetch data as it existed at a specific point in time, or retrieve all
    changes from a specific point in time up to the present. You can also supply
    a shape to the API to get data in a format that suits your needs.


    ### Dated values


    In the v1.1 model, all fields are represented by an array of values with an
    optional valid_from timestamp. A null value for valid_from indicates that
    the field value is valid from the beginning of time, meaning it has no
    recorded history in the system. When multiple values exist in the array,
    they are sorted in descending order with the most recent value first. The
    last value may or may not have a null timestamp. An array can never contain
    more than one value with a null timestamp.


    # Authentication

    The Twine public API uses Bearer token authentication. The token should be
    sent in the `Authorization` header with the value `Bearer <token>`.


    ## Provisioning a token

    To provision a token, you must first generate a long-lived refresh token
    using Twine backoffice. This token can then be used to generate short-lived
    access tokens. The refresh token should be kept secret and never shared.

    Follow these steps to obtain an access token:


    1. Invoke `/provisioning/refresh-token/begin` using the JTI you received
    when provisioning the refresh token.

    2. The response will contain a `salt` value

    3. Concatenate the salt with the refresh token, separated by a colon (`:`)

    4. Hash the concatenated string using SHA256, e.g. `sha256
    "<salt>:<refresh_token>"`

    5. The hash should be in lower case

    6. Invoke `/provisioning/refresh-token/refresh` with the JTI (as `jti`) and
    the hash (as `signature`) in the body

    7. The response will contain an access token


    ## Legacy tokens

    Legacy tokens are still supported. These tokens are long-lived and can be
    used to authenticate against the API. However, we recommend using the new
    token provisioning system.


    ## Token expiration

    Provisioned tokens are short-lived. Decode them to find the expiry time.
    Legacy tokens have longer expiry times.


    # Filtering

    Some endpoints allow filtering on certain fields. Not all fields are
    filterable, and filter operations may vary between fields. Refer to specific
    endpoints to discover what is possible. All filters follow the same
    structure:


    ```bash

    GET
    /v1/org/employees?filters[updated_at][value]=2022-01-01T00:00:00Z&filters[updated_at][op]=gt

    ```


    # Ordering

    Some endpoints allow ordering on certain fields. Not all fields are
    orderable. Refer to specific endpoints to discover what is possible. All
    ordering follows the same structure:


    ```bash

    GET /v1/org/employees?order[field]=updated_at&order[direction]=desc

    ```


    # Data reliability

    A given piece of data is a snapshot of the latest data fetched from the
    Vendor. In some cases the data returned by Twine will be out of sync with
    the Vendor.

    This is due to the nature of the integration and the data provided by the
    Vendor. Twine will always strive to provide the most accurate data possible.

    Depending on the Customer, the data may be updated in near real-time, or
    with a longer delay.


    # Permissions

    All API requests are subject to a permissions check. Permissions are
    configured by Twine staff or an approved external admin.


    # Rate limiting

    The API is not currently rate limited. However, you should expect this to
    change in the near future. At that time you will start receiving 429 Too
    Many Requests responses. More information will be provided here when rate
    limiting is implemented.


    ## Fetching single resources

    When requesting single resources with inadequate permissions, you will
    receive a 403 Forbidden in response.


    ## Fetching lists of resources

    When requesting a list of resources, the API will filter out resources you
    do not have access to. This means that the

    response may contain fewer resources than requested. The API will always
    return a 200 OK response, even if the list is empty.


    # Pushing data

    NOTE: The API currently only supports the `employee` domain for writing
    data.


    There are multiple considerations to take into account when writing data to
    the API.


    * In order to write data, the role being used must have the `create` and/or
    `update` permissions for the `employee` domain.

    * As per the RESTful API design specs, the `POST` method is used to create
    new resources, while the `PUT` method is used to update existing resources,
    and the `PATCH` method is used to partially update existing resources.

    * Even though `PATCH` will not touch unspecified dated properties, it will
    still replace all entries of targeted dated properties with the new values
    provided in the request body. This means that if you want to keep existing
    historical values for a given dated property, you must include them in the
    request body. This behaviour can be changed in the future given enough
    demand.

    * If there are incoming domain mappings for the `employee` domain, you
    should avoid updating any properties that are mapped in those integrations.
    Otherwise there will be uncertainty about which integration is responsible
    for the data.

    * If there is a configured `twine` integration with outgoing domain mappings
    for the `employee` domain, a replication job will be created to push the
    changes to the configured integration. If you want to avoid this, create a
    condition in the target integration.


    # Nomenclature


    Throughout the API, we use the following terms:


    | Term        | Description |

    |-------------|-------------|

    | Customer    | The entity on whose behalf Twine processes personnel data |

    | Vendor      | Third party supplier of data with which Twine integrates on
    behalf of Customer |


    # FAQ


    ### Do you have a sandbox environment?

    Yes. Please contact Twine support to get access.


    ### Are there webhooks?

    Not yet, but it is on the roadmap.


    ### How can I keep the response body small?

    Use the `select` parameter to only fetch the fields you need. This will
    reduce the response size and speed up the request. Combine this

    with filtering by `updated_at` to only fetch the data that has changed since
    your last request.

  title: |
    Twine Public API
  version: |
    v1.2
  x-logo:
    altText: Twine Logo
    backgroundColor: '#00000000'
    url: >-
      https://images.squarespace-cdn.com/content/v1/63cec8699b6d396be083ed8b/a2746b2d-2582-49f0-93bb-99a8765c5450/LogoTwineHorizontal.png?format=12w
servers:
  - description: Twine Public Production API
    url: https://api.twine.se
    variables: {}
  - description: Twine Public Staging API
    url: https://api-stage.twine.se
    variables: {}
security:
  - BearerAuth: []
tags:
  - description: >+
      # Fetching

      Employees can be retrieved in paginated lists, or one by one. The employee
      object remains the same in both cases.


      # Data consistency

      Twine allows Customers to map their data to their own wishes. In some
      cases, fields might not contain what you expect.

      Fields like `first_name` and `private_id_number` are more or less
      guaranteed to contain what you expect. However, fields like `phone1`,
      `phone2`

      might mean different things depending on the Customer. Some Customers will
      want to store an employee's private phone number in `phone1`,

      while others will store the work phone number instead. Always refer to the
      Customer's data mapping (upcoming API endpoint) to understand what the
      fields contain.

    name: Employees
  - description: >
      # Fetching

      Organizational units can be retrieved in paginated lists, or one by one.
      The organizational unit object remains the same in both cases.


      # Data consistency

      Twine will attempt to normalize the source system's organizational unit
      tier. If successful, the `tier` field will contain the normalized tier and
      be of type [OrganizationalUnitTier](#model/organizationalunittier)
    name: Organizational Units
  - description: >+
      # Fetching

      Time reports can be retrieved in paginated lists.


      # Time types

      Twine allows Customers to map their time types to their own wishes. In
      some cases, time types might not contain what you expect.

    name: Time Reports
paths:
  /v1/org/domain-mappings/{domain_mapping_id}:
    put:
      tags:
        - DomainMappings
      summary: Update Domain Mapping
      description: Updates an existing domain mapping.
      operationId: updateDomainMapping
      parameters:
        - description: The UUID of the domain mapping to edit
          in: path
          name: domain_mapping_id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DomainMappingEditRequest'
        description: DomainMappingEditRequest
        required: false
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DomainMappingResponse'
          description: Domain Mapping Response
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BadRequestError'
          description: Bad Request Response
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ForbiddenError'
          description: Forbidden Response
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InternalServerError'
          description: Internal Error Response
      callbacks: {}
components:
  schemas:
    DomainMappingEditRequest:
      description: Schema for editing a domain mapping
      properties:
        conditions:
          description: >-
            List of conditions to create and attach to the created domain
            mapping.
          items:
            $ref: '#/components/schemas/ConditionCreate'
          nullable: true
          type: array
        enabled:
          default: true
          description: Whether the domain mapping is enabled. Defaults to true.
          example: true
          nullable: true
          type: boolean
        sync_triggers:
          description: >-
            List of sync triggers to upsert and attach to the created domain
            mapping. _NOTE_: Currently only one sync trigger can be created
            while creating a domain mapping. If multiple sync triggers are
            specified, only the first will be used. This restriction will be
            lifted in the future.
          items:
            $ref: '#/components/schemas/SyncTriggerUpdate'
          nullable: true
          type: array
      title: DomainMappingEditRequest
      type: object
    DomainMappingResponse:
      description: Response schema for a single domain mapping.
      properties:
        data:
          $ref: '#/components/schemas/DomainMapping'
      title: DomainMappingResponse
      type: object
    BadRequestError:
      description: Bad request error
      properties:
        code:
          example: 400
          type: integer
        errors:
          default: []
          items:
            description: Singular error
            properties:
              domain:
                type: string
              message:
                type: string
              reason:
                type: string
            required:
              - domain
              - reason
              - message
            title: InnerError
            type: object
          type: array
        message:
          example: Bad Request
          type: string
      required:
        - code
        - message
        - errors
      title: BadRequestError
      type: object
    ForbiddenError:
      description: Forbidden error
      properties:
        code:
          example: 403
          type: integer
        errors:
          default: []
          items:
            description: Singular error
            properties:
              domain:
                type: string
              message:
                type: string
              reason:
                type: string
            required:
              - domain
              - reason
              - message
            title: InnerError
            type: object
          type: array
        message:
          example: Forbidden
          type: string
      required:
        - code
        - message
        - errors
      title: ForbiddenError
      type: object
    InternalServerError:
      description: Internal server error
      properties:
        code:
          example: 500
          type: integer
        errors:
          default: []
          items:
            description: Singular error
            properties:
              domain:
                type: string
              message:
                type: string
              reason:
                type: string
            required:
              - domain
              - reason
              - message
            title: InnerError
            type: object
          type: array
        message:
          example: Internal Server Error
          type: string
      required:
        - code
        - message
        - errors
      title: InternalServerError
      type: object
    ConditionCreate:
      description: An object representing a creatable condition.
      properties:
        apply_on_actions:
          description: List of actions the condition applies to
          items:
            enum:
              - create
              - update
            type: string
          nullable: false
          type: array
        condition:
          description: V2 Graph Engine condition
          type: object
        description:
          description: A brief description of the condition
          nullable: true
          type: string
        domain:
          description: The data domain
          enum:
            - finance
            - employee_competence
            - competence
            - expense_transaction
            - salary_transaction
            - file_transfer
            - project
            - org_unit
            - customer
            - schedule
            - time_report
            - employee
          example: employee
          title: Domain
          type: string
        enabled:
          default: true
          description: Whether the condition is enabled
          nullable: false
          type: boolean
      required:
        - condition
        - enabled
        - domain
        - apply_on_actions
      title: ConditionCreate
      type: object
    SyncTriggerUpdate:
      description: An object representing a creatable sync trigger.
      properties:
        cron_expression:
          description: >-
            The cron expression for the scheduled trigger. If null, the trigger
            can only be run manually
          example: 0 0 * * *
          nullable: true
          type: string
        domain_configuration:
          description: The domain-specific configuration for the sync trigger.
          nullable: true
          oneOf:
            - $ref: '#/components/schemas/SyncTriggerTimeReportSettings'
          type: object
        enabled:
          default: false
          description: >-
            Whether the sync trigger should be enabled from start. Ignored if no
            cron_expression is set. Defaults to false.
          example: false
          nullable: true
          type: boolean
        id:
          description: >-
            The UUID of the sync trigger to update. If omitted, a new sync
            trigger will be created.
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: false
          type: string
        parent_id:
          description: The parent trigger's UUID
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: true
          type: string
      title: SyncTriggerUpdate
      type: object
    DomainMapping:
      description: An object representing a domain mapping.
      properties:
        all_conditions_must_apply:
          description: >-
            Whether every condition must match (AND) rather than any one of them
            (OR). Has no effect when `conditions` is empty.
          example: false
          nullable: false
          type: boolean
        conditions:
          description: List of conditions associated with this domain mapping.
          items:
            $ref: '#/components/schemas/Condition'
          nullable: true
          type: array
        description:
          description: Free-text description of the mapping.
          example: Employees from the HR system into payroll
          nullable: true
          type: string
        enabled:
          description: Whether the domain mapping is enabled
          example: true
          nullable: false
          type: boolean
        from_domain:
          description: The source domain for the mapping.
          enum:
            - finance
            - employee_competence
            - competence
            - expense_transaction
            - salary_transaction
            - file_transfer
            - project
            - org_unit
            - customer
            - schedule
            - time_report
            - employee
          example: employee
          title: Domain
          type: string
        id:
          description: The sync trigger's UUID
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: false
          type: string
        inserted_at:
          description: Timestamp of when the domain mapping was created
          example: '2021-06-01T12:00:00Z'
          format: date-time
          type: string
        mode:
          description: >-
            `default` is a full read/write mapping. `update_existing_only` syncs
            updates onto existing Twine entities only — unmapped incoming
            entities are dropped and replication is refused.
          enum:
            - update_existing_only
            - default
          example: default
          nullable: false
          type: string
        org_id:
          description: The parent organization's UUID
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: false
          type: string
        source_system_integration_id:
          description: 'The source system integration''s UUID. '
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: false
          type: string
        sync_triggers:
          description: List of sync triggers associated with this domain mapping.
          items:
            $ref: '#/components/schemas/SyncTrigger'
          nullable: true
          type: array
        target_system_integration_id:
          description: 'The source system integration''s UUID. '
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: false
          type: string
        to_domain:
          description: The target domain for the mapping.
          enum:
            - finance
            - employee_competence
            - competence
            - expense_transaction
            - salary_transaction
            - file_transfer
            - project
            - org_unit
            - customer
            - schedule
            - time_report
            - employee
          example: employee
          title: Domain
          type: string
        updated_at:
          description: Timestamp of when the domain mapping was last updated
          example: '2021-06-01T12:00:00Z'
          format: date-time
          type: string
      required:
        - id
        - org_id
        - source_system_integration_id
        - target_system_integration_id
        - from_domain
        - to_domain
        - enabled
      title: DomainMapping
      type: object
    SyncTriggerTimeReportSettings:
      description: An object representing the time report settings for a sync trigger.
      properties:
        domain:
          default: time_report
          description: Must always be `time_report`
          type: string
        from_date:
          description: Explicit from date for the time report sync
          format: date
          nullable: true
          type: string
        from_date_engine:
          description: >-
            Dynamic configuration for the from date. Should not be specified if
            from_date is set, and vice versa.
          nullable: true
          type: object
        to_date:
          description: Explicit to date for the time report sync
          format: date
          nullable: true
          type: string
        to_date_engine:
          description: >-
            Dynamic configuration for the to date. Should not be specified if
            to_date is set, and vice versa.
          nullable: true
          type: object
      title: SyncTriggerTimeReportSettings
      type: object
    Condition:
      description: A condition for filtering data.
      properties:
        apply_on_actions:
          description: List of actions the condition applies to
          items:
            enum:
              - create
              - update
            type: string
          nullable: false
          type: array
        condition:
          description: V2 Graph Engine condition
          type: object
        description:
          description: A brief description of the condition
          nullable: true
          type: string
        domain:
          description: The data domain
          enum:
            - finance
            - employee_competence
            - competence
            - expense_transaction
            - salary_transaction
            - file_transfer
            - project
            - org_unit
            - customer
            - schedule
            - time_report
            - employee
          example: employee
          title: Domain
          type: string
        enabled:
          default: true
          description: Whether the condition is enabled
          type: boolean
        id:
          description: The condition's UUID.
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: false
          type: string
      required:
        - id
        - condition
        - domain
        - apply_on_actions
        - enabled
      title: Condition
      type: object
    SyncTrigger:
      description: An object representing a sync trigger in a domain mapping.
      properties:
        cron_expression:
          description: >-
            The cron expression for the scheduled trigger. If null, the trigger
            can only be run manually
          example: 0 0 * * *
          nullable: true
          type: string
        domain_configuration:
          description: The domain-specific configuration for the sync trigger.
          nullable: true
          oneOf:
            - $ref: '#/components/schemas/SyncTriggerTimeReportSettings'
          type: object
        domain_mapping_id:
          description: The parent domain mapping's UUID
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: false
          type: string
        id:
          description: The sync trigger's UUID
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: false
          type: string
        last_sync_ended_at:
          description: >-
            The last time the sync was completed. It is possible for this
            timestamp to be earlier than `last_sync_started_at`, which would
            indicate a failed sync
          example: '2023-01-01T00:00:00Z'
          format: date-time
          nullable: true
          type: string
        last_sync_started_at:
          description: The last time the sync was started.
          example: '2023-01-01T00:00:00Z'
          format: date-time
          nullable: true
          type: string
        next_sync_at:
          description: >-
            The next scheduled sync time. This is not an exact point in time as
            the sync will most likely be started shortly afterwards.
          example: '2023-01-01T00:00:00Z'
          format: date-time
          nullable: true
          type: string
        org_id:
          description: The parent organization's UUID
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: false
          type: string
        parent_id:
          description: The parent trigger's UUID
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: true
          type: string
        system_integration_id:
          description: The parent system integration's UUID
          example: 018eae56-8f9d-7ca0-bea3-17f3db6cf75b
          format: uuid
          nullable: false
          type: string
      required:
        - id
        - org_id
        - system_integration_id
        - domain_mapping_id
      title: SyncTrigger
      type: object
  securitySchemes:
    BearerAuth:
      bearerFormat: JWT
      description: Bearer token for authentication
      scheme: bearer
      type: http

````