swagger: '2.0'
info:
  title: Masters Registry API
  version: 0.0.1
host: ows-masters-registry.theorchard.io
basePath: /
schemes:
  - https
paths:
  /bulk:
    get:
      parameters:
        - default: create_datetime
          description: field for ordering tasks
          in: query
          name: order_by
          required: false
          type: string
        - default: desc
          description: direction of ordering
          in: query
          name: order_direction
          required: false
          type: string
        - default: 30
          description: number of task statuses to be returned
          in: query
          name: num_records
          required: false
          type: integer
        - description: UUID to trace requests
          in: header
          name: Correlation-Id
          required: true
          type: string
        - description: Orchard users ID
          in: header
          name: Orchard-Id
          required: true
          type: integer
      responses:
        '200':
          examples:
            success:
              - correlation_id: '1476889902202'
                user_id: 1294
                create_datetime: '2016-10-19T15:11:47'
                status: DONE
                finish_datetime: '2016-10-19T15:18:54'
                count: 997
                result:
                  - upc: '5052575079863'
                    status_report:
                      - success: true
                        error_message: ''
                        isrc: GBLGL1053836
                      - success: true
                        error_message: ''
                        isrc: GBLGL1053838
                    error_count: 0
                    success_count: 12
                type: BULK_IMPORT
          description: OK
        '400':
          examples:
            default:
              message: Invalid number of records.
              code: invalid_num_records
          description: |
            Request invalid query parameter
      description: Get a list of bulk processing tasks with their statuses.
  /generate_report:
    get:
      produces:
        - text/csv
      parameters:
        - description: ID of task for generation report
          in: query
          name: task_id
          required: true
          type: integer
        - description: update report type - ISRC/UPC
          in: query
          name: report_type
          required: false
          type: string
        - description: UUID to trace requests
          in: header
          name: Correlation-Id
          required: true
          type: string
        - description: Orchard users ID
          in: header
          name: Orchard-Id
          required: true
          type: integer
      responses:
        '200':
          examples:
            success: |-
              UPC,Update Status,Successful ISRC Count,Failed ISRC Count
              "=""889845515661""",DONE,2,0
              "=""888002153500""",DONE,3,0
              "=""190374478403""",DONE,2,0
              "=""038153067328""",DONE,3,0
          description: OK
        '404':
          examples:
            default:
              message: Bulk task does not exist
              code: not_found_error
          description: Not Found
        '500':
          description: Server Error
      description: Download csv format report
  /ownership:
    get:
      parameters:
        - description: International Standard Recording Code
          in: query
          name: isrc
          required: true
          type: string
        - description: UUID to trace requests
          in: header
          name: Correlation-Id
          required: true
          type: string
      responses:
        '200':
          examples:
            default:
              locked_territories:
                - territories:
                    - BE
                    - NL
                  reason: Owned by Warner
                - territories:
                    - IT
                    - RU
                  reason: Conflict with Universal
              isrc: abc123
              unclaimed_territories: []
              tracks:
                - territories:
                    - CN
                    - CA
                    - KZ
                    - AF
                    - AS
                    - BR
                    - DE
                    - CH
                    - FR
                    - ES
                    - JP
                    - US
                  vendor_id: 47
                  vendor_name: Amin Refaat
                  subaccount_id: null
                  upc: 669910758229
                  track_name: Taurus
                  release_name: Zodiac Symphony
                  tuid: 111111
                  artist_name: Burkhard Schmidl
                  subaccount_name: null
                - territories:
                    - AR
                  vendor_id: 4372
                  vendor_name: Sam Records
                  subaccount_id: null
                  upc: 669910014525
                  track_name: 16 Tons
                  release_name: Pan-American Shindig
                  tuid: 23223
                  artist_name: Grandsons of the Pioneers
                  subaccount_name: null
          description: OK
      description: get ownership info for a given ISRC
  /masterrights:
    get:
      parameters:
        - description: International Standard Recording Codes
          in: query
          name: isrcs
          required: true
          type: string
        - description: UUID to trace requests
          in: header
          name: Correlation-Id
          required: true
          type: string
      responses:
        '200':
          examples:
            locked_territories:
              - territories:
                  - BE
                  - NL
                reason: Owned by Warner
              - territories:
                  - IT
                  - RU
                reason: Conflict with Universal
            isrc: abc123
            territories:
              - CA:
                - tuid: 123
                - tuid: 234
              - FR:
                - tuid: 123
                - tuid: 234
              - ES:
                - tuid: 123
                - tuid: 234
              - JP:
                - tuid: 123
                - tuid: 234
              - US:
                - tuid: 123
                - tuid: 234
            timestamp: 1489012800631.612
            updated_timestamp: 1514980909.436671
      description: get master rights info for given ISRC's
    post:
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: header
          name: Content-Type
          pattern: ^application/json$
          required: true
          type: string
        - description: UUID
          in: header
          name: Correlation-Id
          required: true
          type: string
        - in: body
          name: body
          schema:
            $ref: '#/definitions/OwnershipPost'
          required: true
      responses:
        '200':
          examples:
            default:
              tuid: 23223
              vendor_name: Sam Records
              vendor_id: 4372
              artist_name: Grandsons of the Pioneers
              track_name: 16 Tons
              upc: 669910014525
              release_name: Pan-American Shindig
              territories:
                - CN
                - CA
                - KZ
                - AF
                - AS

          description: |
            200 OK
        '400':
          examples:
            default:
              summary: The default response example
              value: |-
                {
                  "code": "tuid_claimed",
                  "message": "Tuid is already claimed."
                  "status": 400
                }
          description: |
            Request parameter/header validation failure
        '500':
          description: |
            500 Server error
      description: |
        Allow user to add an individual tuid for a territory
  /ownership/lock/isrcs:
    post:
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - description: UUID to trace requests
          in: header
          name: Correlation-Id
          required: true
          type: string
        - in: body
          name: body
          schema:
            $ref: '#/definitions/BodyLockBody'
          required: true
      responses:
        '200':
          examples:
            success:
              lock_reason: lost ownership dispute
              isrcs:
                - GBPS81528956
                - USJSJ1014077
              territories:
                - US
                - CA
                - MX
          description: OK
        '400':
          examples:
            invalid_territories:
              code: invalid_territories
              message: Invalid territories
          description: |
            Request parameter/header validation failure
        '500':
          description: |
            500 Server error
      description: Bulk Lock a list of ISRCs and territories
  /ownership/unlock/isrcs:
    post:
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - description: UUID to trace requests
          in: header
          name: Correlation-Id
          required: true
          type: string
        - in: body
          name: body
          schema:
            $ref: '#/definitions/BulkUnlockTerritories'
          required: true
      responses:
        '200':
          examples:
            success:
              isrcs:
                - GBPS81528956
                - USJSJ1014077
              territories:
                - US
                - CA
                - MX
          description: OK
        '400':
          examples:
            invalid_territories:
              code: invalid_territories
              message: Invalid territories
          description: |
            Request parameter/header validation failure
        '500':
          description: |
            500 Server error
      description: Bulk Unlock a list of ISRCs and territories
  /ownership/upcs:
    post:
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: header
          name: Content-Type
          pattern: ^application/json$
          required: true
          type: string
        - description: UUID
          in: header
          name: Correlation-Id
          required: true
          type: string
        - in: body
          name: body
          schema:
            $ref: '#/definitions/OwnershipUpcs'
          required: true
      responses:
        '200':
          examples:
            success:
              - upc: '190374000000'
                error_count: 0
                success_count: 2
                status_report:
                  - isrc: QM7281596971
                    success: true
                    error_message: null
                  - isrc: QM7281596973
                    success: true
                    error_message: null
              - upc: '190374000017'
                error_count: 1
                success_count: 1
                status_report:
                  - isrc: QM7281576986
                    success: true
                    error_message: null
                  - isrc: QM7281576987
                    success: false
                    error_message: unable to find territory carve-ins
          description: |
            200 OK
        '400':
          examples:
            upcs_not_found_or_deleted:
              errors:
                message:
                  upc: '123456789120'
                  error_count: 1
                  success_count: 0
                  error_message: UPC does not create
                  status_report: []
                code: upcs_not_found_or_deleted
              message: ''
              status: 400
          description: |
            Request parameter/header validation failure
        '500':
          description: |
            500 Server error
      description: |
        Bulk import UPCs
  /ownership/conflicts/resolve:
    put:
      description: |
        Bulk resolve conflicts for given list of ISRCs and territories
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - in: header
          name: Content-Type
          pattern: ^application/json$
          required: false
          type: string
        - description: UUID
          in: header
          name: Correlation-Id
          required: false
          type: string
        - in: body
          name: body
          schema:
            $ref: '#/definitions/OwnershipResolveConflicts'
          required: true
      responses:
        '200':
          description: |
            Task to remove ownership was created successfully
          examples:
            success:
              task_id: 1

        '400':
          description: |
            Request header/body validation failure
        '500':
          description: |
            500 Server error
definitions:
  OwnershipPost:
    type: object
    properties:
      tuid:
        type: integer
        example: 12345
      isrc:
        type: string
        minLength: 12
        maxLength: 12
        example: ABC123
      territories:
        type: array
        minItems: 1
        example:
          - US
          - Canada
          - MX
    required:
      - tuid
      - isrc
      - territories
  BodyLockBody:
    type: object
    properties:
      lock_reason:
        type: string
        maxLength: 256
        example: lost ownership dispute
      isrcs:
        type: array
        minItems: 1
        maxItems: 2000
        example:
          - GBPS81528956
          - USJSJ1014077
      territories:
        type: array
        minItems: 1
        example:
          - US
          - CA
          - MX
    required:
      - lock_reason
      - isrcs
      - territories
  BulkUnlockTerritories:
    type: object
    properties:
      isrcs:
        type: array
        minItems: 1
        example:
          - GBPS81528956
          - USJSJ1014077
      territories:
        type: array
        minItems: 1
        example:
          - US
          - CA
          - MX
    required:
      - isrcs
      - territories
  OwnershipUpcs:
    type: object
    properties:
      upcs:
        type: array
        minItems: 1
        example:
          - '669910758229'
          - '669910758230'
          - '669910758231'
    required:
      - upcs
  OwnershipResolveConflicts:
    type: object
    properties:
      account_id:
        type: integer
      account_type:
        type: string
        example: vendor or subaccount
      isrcs:
        type: array
        minItems: 1
        example:
          - GBPS81528956
          - USJSJ1014077
      territories:
        type: array
        minItems: 1
        example:
          - US
          - CA
          - MX
securityDefinitions: {}
