openapi: 3.1.0
x-customer-voice: true
info:
  title: Viewcast Select
  version: 0.2.0
  description: |
    Purchase, poll, and retrieve a reach-and-frequency analysis for a
    campaign scenario — the `select` analysis type on Viewcast, alongside
    its existing display-level measurement (draft/final/direct purchases).
    Creating and managing the campaign scenario itself is a separate
    surface at `/v2/scenarios/campaigns/*` — see the Scenarios reference.

    Purchasing an analysis is asynchronous:
    `POST /v2/viewcast/measurements/purchase/select` returns `202` with
    `status: "queued"`; poll the existing
    `GET /v2/viewcast/measurements/{asset_id}` endpoint (documented in the
    Viewcast contract — this surface does not define a separate poll route)
    for state. Once state is `in_flight` or `completed`, the report is
    available at `GET /v2/viewcast/select/{asset_id}`: while `in_flight` it
    updates weekly for as long as the campaign flight runs; once
    `completed`, the report is final and permanently retrievable. A failed
    run auto-refunds the purchase charge, less a 1-credit charge for the
    API call itself; the campaign scenario asset stays `draft` and is
    immediately re-purchasable.

    Authenticate with an org-scoped API key (`X-API-Key: mw_…`). Purchasing
    an analysis costs 5000 credits — the largest single-call charge in this
    API. Polling is free (same policy as every other Viewcast measurement
    poll); report retrieval costs 1 credit.

    A completed report can be shared through a public link that needs no
    key: `POST /v2/viewcast/select/{asset_id}/share` returns the link once,
    valid for 90 days. Renew it with `…/share/renew` (same link, new expiry),
    check it with `GET …/share`, and replace it by creating it again (the old
    link stops working). Anyone holding the link reads the report at
    `GET /v2/viewcast/select/shared/{token}`, free and without a key.
  contact:
    name: Motionworks AI
    url: https://mworks.com
    email: api@mworks.com
servers:
  - url: https://api2.mworks.com/v2
    description: Production
security:
  - apiKey: []
components:
  securitySchemes:
    apiKey:
      type: apiKey
      name: X-API-Key
      in: header
  schemas:
    ViewcastSelectStatus:
      type: string
      enum:
        - queued
        - running
        - completed
        - failed
      description: |
        Where the analysis run is: `queued` (accepted, not started),
        `running`, `completed` (the campaign asset's report is retrievable)
        or `failed` (`failure_reason` is populated and the purchase charge
        is refunded, less a 1-credit charge for the API call itself).
    ViewcastSelectPurchaseRequest:
      type: object
      required:
        - asset_id
        - measurement_request_id
      properties:
        asset_id:
          type: string
          description: The campaign scenario asset to purchase an analysis for, created via the campaign scenario asset library.
        measurement_request_id:
          type: string
          format: uuid
          description: |
            Idempotency key you mint (UUID). A retry with the same key and
            an identical body replays the original result at no additional
            charge; the same key with a different body is rejected with
            `409`. Carried in the request body, not an `Idempotency-Key`
            header.
      description: POST /measurements/purchase request body — asset_id rides in the body, not the path.
    ViewcastSelectResult:
      type: object
      required:
        - measurement_id
        - asset_id
        - status
        - queued_at
      description: |
        The `202` initial-acceptance body for a purchase — NOT the shape
        of a poll response. There is no dedicated Viewcast Select poll
        endpoint; ongoing status polling reuses the existing
        `GET /v2/viewcast/measurements/{asset_id}` route, which returns
        the Viewcast contract's own measurement-result shape (carrying an
        additional required `kind` field with no campaign-scenario value
        defined yet — reconciling the two shapes is a follow-up, not
        resolved here).
      properties:
        measurement_id:
          type: string
          nullable: true
          description: Null only in the brief poll-before-queue race window.
        asset_id:
          type: string
        status:
          $ref: '#/components/schemas/ViewcastSelectStatus'
        queued_at:
          type: string
          format: date-time
        completed_at:
          type: string
          format: date-time
        refund_credits:
          type: integer
          description: Populated on `failed` — the purchase charge, refunded less a 1-credit charge for the API call itself (4,999 of the 5,000 credits).
        failure_reason:
          type: string
    ViewcastSelectRemeasureResult:
      type: object
      required:
        - measurement_id
        - asset_id
        - measurement_request_id
        - measurement_revision_id
        - revision
        - state
        - operation
        - report_asset_id
        - planning_campaign_scenario_asset
        - queued_at
      properties:
        measurement_id:
          type: string
          description: The remeasurement audit-operation id, serialized as a string.
        asset_id:
          type: string
          description: The completed final campaign asset.
        measurement_request_id:
          type: string
          format: uuid
        measurement_revision_id:
          type: string
          format: uuid
        revision:
          type: integer
          minimum: 2
        state:
          type: string
          enum:
            - queued
        operation:
          type: string
          enum:
            - viewcast_select_remeasure
        report_asset_id:
          type: string
          description: Distinct report key for this revision; the original campaign report key is never overwritten.
        planning_campaign_scenario_asset:
          type: string
          format: uuid
          description: Provenance link to the planning campaign that fed the final campaign asset.
        queued_at:
          type: string
          format: date-time
    ViewcastSelectRevision:
      type: object
      required:
        - revision
        - measurement_revision_id
        - state
        - final_campaign_asset_id
        - planning_campaign_scenario_asset_id
        - report_asset_id
        - queued_at
      properties:
        revision:
          type: integer
          minimum: 1
        measurement_revision_id:
          type:
            - string
            - 'null'
          format: uuid
          description: Null for revision 1, which is the original final measurement stored on campaign_assets.
        measurement_request_id:
          type:
            - string
            - 'null'
          format: uuid
        state:
          type: string
          enum:
            - draft
            - queued
            - running
            - completed
            - failed
        final_campaign_asset_id:
          type: string
          format: uuid
        planning_campaign_scenario_asset_id:
          type:
            - string
            - 'null'
          format: uuid
        report_asset_id:
          type: string
        run_id:
          type:
            - string
            - 'null'
        report_id:
          type:
            - string
            - 'null'
        credit_amount:
          type:
            - integer
            - 'null'
          description: Null for revision 1 while the campaign is still draft and has not been purchased.
        refund_credits:
          type:
            - integer
            - 'null'
          description: Null when no refund is known or no refund has occurred.
        failure_reason:
          type:
            - string
            - 'null'
        queued_at:
          type:
            - string
            - 'null'
          format: date-time
          description: |
            For revision 1, the latest initial-purchase operation's queue time.
            Null for a draft or when no initial-purchase provenance is available.
            Stored remeasure revisions always carry their purchase queue time.
        completed_at:
          type:
            - string
            - 'null'
          format: date-time
        failed_at:
          type:
            - string
            - 'null'
          format: date-time
    ViewcastSelectRevisionHistory:
      type: object
      required:
        - current_revision
        - revisions
      properties:
        current_revision:
          type:
            - integer
            - 'null'
          minimum: 1
          description: |
            The revision served by the current-report URL, including revision 1
            while its original report is in flight. Null when no revision is
            servable, including a draft, queued or failed original campaign.
        revisions:
          type: array
          items:
            $ref: '#/components/schemas/ViewcastSelectRevision'
    ViewcastSelectRevisionReportMeta:
      allOf:
        - $ref: '#/components/schemas/ViewcastSelectReportMeta'
        - type: object
          required:
            - revision
          properties:
            revision:
              $ref: '#/components/schemas/ViewcastSelectRevision'
    ViewcastSelectReport:
      type: object
      additionalProperties: true
      description: |
        The full measurement result for this campaign, returned exactly as
        produced by the analysis, aside from a short list of internal-only
        fields removed before the response is served. Each spot's per-day
        delivery comes in the form you ask for with `delivery`:

        - `full` (the default): `spots[].spot_performance.daily_delivery`,
          the full cell array (one entry per market per day, one nested
          object per metric).
        - `compact`: `spots[].spot_performance.daily_delivery_series`, the
          same data as runs of consecutive days, much smaller on large
          reports. Each entry covers one run of consecutive days that share
          a market and a measurement state, with `market` (a `kind`/`id`
          pair), `start` (the first day, `YYYY-MM-DD`; entry `i` of each
          per-day array is `start` + `i` days), `measurement_state`
          (`final`, `preliminary`, or `projected`), and one entry per
          metric (`ots`, `lts`) carrying `value[]` (one number or null per
          day, in order), `ci_lo`/`ci_hi` (per-day confidence-interval
          ends, or null when no day in the run has a real interval), and
          `exceptions[]` (runs of days, `first_day`..`last_day` as
          inclusive day offsets from `start`, whose other recorded
          attributes are identical; a covered day takes those attributes
          from the exception and its value from `value[i]`). A day not
          covered by any exception is an ordinary day of its run: it
          carries no exception attributes and takes the run's
          `measurement_state`. When `ci_lo`/`ci_hi` are present, a null
          entry marks a day whose interval has no width: for a measured
          value, the interval is the value itself. To read a compact spot,
          walk each run day by day: the date is `start` + the array index,
          the metric's value is `value[i]`, and a null value means
          unmeasured for that metric on that day, not a measured zero.

        The report's top-level `speed_profile` is the speed profile it was
        measured with, the campaign asset's `speed_profile` at purchase.
        Reports measured before speed profiles could be chosen carry
        `weighted_daily`, an older name for `measured`.

        A response carries at most 20,000,000 bytes of report. A report
        larger than that in the requested form is returned without
        `spots`: instead it carries `spot_index`, one entry per spot in
        report order, and `meta.spots_omitted` is `true`. Request the spots
        you need with `spot_ids`, in batches that fit the limit (each
        `spot_index` entry gives the spot's size in both forms).

        Because the analysis is refined over time, treat this as an
        open-ended object rather than a fixed set of fields: new fields can
        appear, existing ones are not guaranteed to keep a specific
        structure release to release, and a numeric-looking value may
        arrive as a string. `report_id` and `debug.qa.qa_flag` are
        currently present on every report; `report_id` identifies this
        analysis run and is not guaranteed to equal the scenario identifier
        you supplied when purchasing, and `debug` as a whole may change
        shape release to release. Retrievable while the campaign asset is
        `in_flight` (interim, updated weekly) or once it is `completed`
        (final, permanent).
      properties:
        spot_index:
          type: array
          description: |
            Present instead of `spots` when the report is larger than the
            response limit in the requested form. One entry per spot, in
            report order.
          items:
            $ref: '#/components/schemas/ViewcastSelectSpotIndexEntry'
    ViewcastSelectSpotIndexEntry:
      type: object
      properties:
        spot_id:
          type: integer
          description: The spot's `spot_id`; pass it in `spot_ids`.
        viewshed_id:
          type: string
          nullable: true
        customer_spot_id:
          type: string
          nullable: true
        customer_operator_name:
          type: string
          nullable: true
        full_bytes:
          type: integer
          description: Size of this spot in the `full` form.
        compact_bytes:
          type: integer
          description: Size of this spot in the `compact` form.
    ViewcastSelectReportMeta:
      allOf:
        - $ref: '#/components/schemas/Meta'
        - type: object
          properties:
            delivery:
              type: string
              enum:
                - full
                - compact
              description: The delivery form served.
            spots_omitted:
              type: boolean
              description: |
                Present and `true` when the report was larger than the
                response limit, so `data` carries `spot_index` instead of
                `spots`.
            response_cap_bytes:
              type: integer
              description: The response limit, present with `spots_omitted`.
    ViewcastSelectShareCreateRequest:
      type: object
      additionalProperties: false
      properties:
        compare_asset_id:
          type: string
          description: |
            A completed campaign asset in your organization, other than this
            one, shown on the shared report as "Same plan, one year earlier".
            Omit it for a report with no comparison.
      description: POST /viewcast/select/{asset_id}/share request body. The body may be empty.
    ViewcastSelectShareLink:
      type: object
      required:
        - asset_id
        - share_id
        - state
        - compare_asset_id
        - created_at
        - renewed_at
        - expires_at
        - revoked_at
      properties:
        asset_id:
          type: string
        share_id:
          type: string
        state:
          type: string
          enum:
            - active
            - expired
            - revoked
          description: '`active` until `expires_at`; `revoked` once the link is replaced by a new one.'
        share_url:
          type: string
          format: uri
          description: |
            The public link. Returned only by the call that creates it; it
            cannot be retrieved again. Create the link again to get a new one.
          example: https://www.mworks.com/campaigns/report/3q2-7wF0bVvG1dQe8nY5xKc4LmTzRJpAa9sHuNoWkEx
        compare_asset_id:
          type:
            - string
            - 'null'
        created_at:
          type: string
          format: date-time
        renewed_at:
          type:
            - string
            - 'null'
          format: date-time
        expires_at:
          type: string
          format: date-time
          description: 90 days after the link was created or last renewed.
        revoked_at:
          type:
            - string
            - 'null'
          format: date-time
    ViewcastSelectShareLinkResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/ViewcastSelectShareLink'
        meta:
          $ref: '#/components/schemas/Meta'
    ViewcastSelectSharedCampaign:
      type: object
      required:
        - asset_id
        - state
        - flight
        - spots
        - cohort
        - speed_profile
        - created_at
        - updated_at
      additionalProperties: true
      description: |
        The campaign as `GET /v2/scenarios/campaigns/{asset_id}` returns it,
        without `org_id`, `customer` or `campaign.reference`.
      properties:
        asset_id:
          type: string
        state:
          type: string
        campaign:
          type: object
          properties:
            name:
              type: string
        flight:
          type: object
          properties:
            start_date:
              type: string
              format: date
            end_date:
              type: string
              format: date
        spots:
          type: array
          items:
            type: object
          description: The campaign's displays and posting windows, as on the campaign asset.
        cohort:
          type: object
          description: The campaign's markets and audience, as on the campaign asset.
        speed_profile:
          type: string
          enum:
            - measured
            - weekly_congested
            - daily_congested
          description: The campaign's speed profile, as on the campaign asset.
        last_measured_at:
          type:
            - string
            - 'null'
          format: date-time
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    ViewcastSelectSharedReport:
      type: object
      required:
        - campaign
        - report
      properties:
        campaign:
          $ref: '#/components/schemas/ViewcastSelectSharedCampaign'
        report:
          $ref: '#/components/schemas/ViewcastSelectReport'
    ViewcastSelectSharedReportResponse:
      type: object
      properties:
        data:
          type: object
          required:
            - campaign
            - report
            - share
          properties:
            campaign:
              $ref: '#/components/schemas/ViewcastSelectSharedCampaign'
            report:
              $ref: '#/components/schemas/ViewcastSelectReport'
            compare:
              $ref: '#/components/schemas/ViewcastSelectSharedReport'
            share:
              type: object
              required:
                - expires_at
              properties:
                expires_at:
                  type: string
                  format: date-time
        meta:
          $ref: '#/components/schemas/Meta'
    Provenance:
      type: object
      properties:
        source:
          type: string
        source_doc:
          type: string
          format: uri
        methodology_version:
          type: string
        data_vintage:
          type: string
          format: date
        data_freshness:
          type: string
          enum:
            - hourly
            - daily
            - weekly
            - monthly
            - annually
            - on-demand
            - static
        data_latency_days:
          type: integer
        data_maturity:
          type: string
          enum:
            - production
            - research-preview
            - synthetic-only
            - roadmap
    Meta:
      type: object
      properties:
        request_id:
          type: string
        credits_used:
          type: integer
        credits_remaining:
          type: integer
        product:
          type: string
        version:
          type: string
        provenance:
          $ref: '#/components/schemas/Provenance'
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
            status:
              type: integer
            request_id:
              type: string
            product:
              type: string
            docs_url:
              type: string
paths:
  /viewcast/measurements/purchase/select:
    post:
      operationId: purchaseViewcastSelect
      summary: Purchase a Viewcast Select analysis
      description: |
        Purchases and runs a reach-and-frequency Viewcast Select analysis
        for a campaign scenario asset you own. `asset_id` rides in the
        body, not the path. Costs 5000 credits, charged on acceptance.
        `202` + `status: "queued"`. Automatically refunded, less a 1-credit
        charge for the API call itself, if the run fails. Poll
        `GET /v2/viewcast/measurements/{asset_id}` — the
        existing, free Viewcast measurement-poll route, not a new
        endpoint on this surface — for completion.
      tags:
        - Measurements
      x-credit-cost: 5000
      x-motionworks-status: production
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ViewcastSelectPurchaseRequest'
      responses:
        '202':
          description: Accepted and queued.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/ViewcastSelectResult'
                  meta:
                    $ref: '#/components/schemas/Meta'
        '400':
          description: Invalid request, or the asset is not in a purchasable state (`draft` or `failed`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Unknown asset_id, or an asset that does not belong to your organization.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: '`measurement_request_id` reused with a different body.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /viewcast/measurements/purchase/select/remeasure:
    post:
      operationId: remeasureViewcastSelect
      summary: Remeasure a completed Viewcast Select campaign
      description: |
        Creates a new, full-price measurement revision for a completed final
        campaign asset you own. Costs 5,000 credits, charged on acceptance.
        The original campaign and every earlier report stay unchanged. The
        new run measures only the final campaign's selected spots and its
        locked flight, cohort and customer inputs, never unselected planning
        spots. Each revision keeps its planning-to-final provenance link.

        Returns `202` with `state: "queued"` and a revision number beginning
        at 2; revision 1 is the original final measurement. Reusing the same
        `measurement_request_id` replays the original response without another
        charge or revision. Only one remeasure may be queued or running per
        campaign: a different key while one is in flight returns 409 without a
        charge. Once that revision completes or fails, a new key creates the
        next revision. Failed runs refund 4,999 credits; the 1-credit API call
        charge is retained.

        Poll the existing free `GET /v2/viewcast/measurements/{asset_id}` route.
        Its `remeasure` object reports the latest revision, state and failure
        reason while the original campaign remains completed.
      tags:
        - Measurements
      x-credit-cost: 5000
      x-motionworks-status: production
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ViewcastSelectPurchaseRequest'
      responses:
        '202':
          description: Remeasurement accepted and queued. The same body is returned on an idempotent replay.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/ViewcastSelectRemeasureResult'
                  meta:
                    $ref: '#/components/schemas/Meta'
        '400':
          description: Invalid UUID/body, or the asset is not a completed final campaign.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: Insufficient credits; no revision is created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Unknown asset_id, or an asset that does not belong to your organization.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: The request id was used for a different asset or operation, or another remeasure is queued or running for this campaign. No new charge or revision is created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: '`DATA_UNAVAILABLE`: the purchase could not be read or accepted right now. Retry shortly; no new revision is created.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /viewcast/select/{asset_id}:
    get:
      operationId: getViewcastSelectReport
      summary: Retrieve a completed Viewcast Select report
      description: |
        Returns the latest completed measurement revision for a campaign
        scenario asset, or the original in-flight report before any later
        revision completes. If the latest completed report is temporarily
        unavailable from storage, this URL serves the previous completed
        revision and `meta.revision` identifies the revision actually served.
        Earlier final reports remain retrievable through the per-revision URL.
        Choose the per-day delivery form with
        `delivery`. A report larger than 20,000,000 bytes in that form is
        returned with a `spot_index` instead of its spots; request the
        spots with `spot_ids`. 1 credit per call, including calls that
        select spots; a call that returns an error is not charged.
      tags:
        - Reports
      x-credit-cost: 1
      x-motionworks-status: production
      parameters:
        - name: asset_id
          in: path
          required: true
          schema:
            type: string
        - name: delivery
          in: query
          required: false
          description: |
            `full` (default) serves each spot's per-day delivery as
            `daily_delivery` cells; `compact` serves it as
            `daily_delivery_series`, the same data in runs of days.
          schema:
            type: string
            enum:
              - full
              - compact
            default: full
        - name: spot_ids
          in: query
          required: false
          description: |
            Comma-separated `spot_id` values (from `spots[]` or
            `spot_index[]`), at most 500 per call. Returns the report with
            only those spots, in report order. The selected spots must fit
            the 20,000,000-byte response limit together.
          schema:
            type: string
          example: 28934,28935
      responses:
        '200':
          description: The report.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/ViewcastSelectReport'
                  meta:
                    $ref: '#/components/schemas/ViewcastSelectRevisionReportMeta'
        '400':
          description: |
            `VALIDATION_ERROR`: `delivery` is not `full` or `compact`, or
            `spot_ids` is empty, not a list of integers, has more than 500
            ids, or names a spot not in this report.
            `SELECTION_TOO_LARGE`: the selected spots together exceed the
            20,000,000-byte response limit; the message gives their size.
            Request fewer spots per call.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Unknown asset_id, an asset that does not belong to your organization, or an asset in `draft`, `queued`, or `failed` state (no report to serve yet).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: '`UPSTREAM_UNAVAILABLE`: the report could not be read right now. Retry shortly; the call is not charged.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /viewcast/select/{asset_id}/revisions:
    get:
      operationId: listViewcastSelectRevisions
      summary: List a campaign's measurement revisions
      description: |
        Returns revision 1 (the original final measurement) followed by every
        explicit remeasurement in revision order. Includes state, report key,
        timestamps, failure/refund details and the planning-to-final
        provenance link. `current_revision` is null when no report is servable.
        Revision 1 queue provenance comes from the latest initial-purchase
        operation and is null when that provenance is unavailable. Costs 1 credit.
      tags:
        - Reports
      x-credit-cost: 1
      x-motionworks-status: production
      parameters:
        - name: asset_id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Revision history in ascending revision order.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/ViewcastSelectRevisionHistory'
                  meta:
                    $ref: '#/components/schemas/Meta'
        '404':
          description: Unknown asset_id, or an asset that does not belong to your organization.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: '`DATA_UNAVAILABLE`: revision history could not be read right now. Retry shortly; the call is not charged.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /viewcast/select/{asset_id}/revisions/{revision}:
    get:
      operationId: getViewcastSelectRevision
      summary: Retrieve one measurement revision
      description: |
        Returns the selected revision's immutable report and revision metadata
        in `meta.revision`. Revision 1 may be an interim report while the
        original campaign is in flight and is final once that campaign completes;
        a completed remeasurement is final. Pinned revision reads never fall back
        to another revision. Queued and failed revisions return 404 because they
        have no report to serve. Supports the same `delivery` and `spot_ids`
        controls as the current report URL. Costs 1 credit.
      tags:
        - Reports
      x-credit-cost: 1
      x-motionworks-status: production
      parameters:
        - name: asset_id
          in: path
          required: true
          schema:
            type: string
        - name: revision
          in: path
          required: true
          schema:
            type: integer
            minimum: 1
        - name: delivery
          in: query
          schema:
            type: string
            enum:
              - full
              - compact
            default: full
        - name: spot_ids
          in: query
          schema:
            type: string
          example: 28934,28935
      responses:
        '200':
          description: The selected revision's report and revision metadata.
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/ViewcastSelectReport'
                  meta:
                    $ref: '#/components/schemas/ViewcastSelectRevisionReportMeta'
        '400':
          description: Invalid revision, delivery or spot selection.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Unknown or non-owned asset, unknown revision, or a revision without a servable report.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: The report service is unavailable; the call is not charged.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /viewcast/select/{asset_id}/share:
    post:
      operationId: createViewcastSelectShareLink
      summary: Create a public link to a completed report
      description: |
        Creates a public link to this campaign's report, valid for 90 days.
        The link is in `share_url` and is returned only in this response.
        If the campaign already has a link, active or expired, it is replaced:
        the old link stops working for good and a new one is created. Only a `completed` campaign can be shared.
      tags:
        - Share links
      x-credit-cost: 1
      x-motionworks-status: production
      parameters:
        - name: asset_id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ViewcastSelectShareCreateRequest'
      responses:
        '201':
          description: The new link, with `share_url`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ViewcastSelectShareLinkResponse'
        '400':
          description: '`VALIDATION_ERROR`: `compare_asset_id` is not a completed campaign in your organization, or is this campaign.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Unknown asset_id, or an asset that does not belong to your organization.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: '`CAMPAIGN_NOT_COMPLETED`: the campaign is not `completed` yet.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
    get:
      operationId: getViewcastSelectShareLink
      summary: Check a campaign's public link
      description: |
        Returns the campaign's most recent link and whether it is `active`,
        `expired` or `revoked`. The link itself (`share_url`) is not
        returned; create the link again to get a new one.
      tags:
        - Share links
      x-credit-cost: 1
      x-motionworks-status: production
      parameters:
        - name: asset_id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: The most recent link, without `share_url`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ViewcastSelectShareLinkResponse'
        '404':
          description: Unknown asset_id, an asset that does not belong to your organization, or a campaign that has never had a link.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /viewcast/select/{asset_id}/share/renew:
    post:
      operationId: renewViewcastSelectShareLink
      summary: Extend a public link by 90 days
      description: |
        Sets the link's expiry to 90 days from now. The link itself does not
        change. An expired link can be renewed; a link that was replaced by
        a new one cannot.
      tags:
        - Share links
      x-credit-cost: 1
      x-motionworks-status: production
      parameters:
        - name: asset_id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: The renewed link, without `share_url`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ViewcastSelectShareLinkResponse'
        '404':
          description: Unknown asset_id, an asset that does not belong to your organization, or no link to renew.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
  /viewcast/select/shared/{token}:
    get:
      operationId: getViewcastSelectSharedReport
      summary: Read a shared report
      description: |
        Returns the campaign and its latest completed report for a public
        link, matching the current-report URL. No API key and no credits. The
        report is in the compact delivery form, without internal and customer
        details. `compare` is present when the link was created with
        `compare_asset_id`; it also resolves to that campaign's latest
        completed report. If storage has not caught up with the latest completed
        report, both the main report and comparison fall back to the previous
        completed revision, matching the authenticated current-report URL.
        Requests are rate-limited per IP and per link.
      tags:
        - Share links
      security: []
      x-credit-cost: 0
      x-motionworks-status: production
      parameters:
        - name: token
          in: path
          required: true
          description: The last path segment of `share_url`.
          schema:
            type: string
            pattern: ^[A-Za-z0-9_-]{43}$
      responses:
        '200':
          description: The shared campaign and report.
          headers:
            Cache-Control:
              schema:
                type: string
              description: '`private, no-store`'
            Referrer-Policy:
              schema:
                type: string
              description: '`no-referrer`'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ViewcastSelectSharedReportResponse'
        '404':
          description: The link is unknown, expired or was replaced. All three return the same response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: '`RATE_LIMIT_EXCEEDED`: too many requests from this IP, or for this link. Retry after the `Retry-After` header.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: '`UPSTREAM_UNAVAILABLE`: the report service is unavailable. Retry shortly.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '503':
          description: '`DATA_UNAVAILABLE`: the link could not be checked right now. Retry shortly.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
x-tagGroups:
  - name: Viewcast Select
    tags:
      - Measurements
      - Reports
      - Share links
tags:
  - name: Measurements
    description: |
      Purchase a Viewcast Select reach-and-frequency analysis. Poll for
      completion via the existing, free Viewcast measurement-poll route
      (not documented in this surface — see the Viewcast contract).
  - name: Reports
    description: Retrieve a completed Viewcast Select analysis report.
  - name: Share links
    description: |
      Share a completed report through a public link that needs no API key.
      Links last 90 days, can be renewed, and stop working when replaced.

      **Share a report.** Create a link for a completed campaign, optionally
      with its prior-year twin as the comparison. The response carries
      `share_url` once; keep it, because no later call returns it.

      ```bash
      curl -X POST https://api2.mworks.com/v2/viewcast/select/$ASSET_ID/share \
        -H "X-API-Key: $MW_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{"compare_asset_id": "'$PRIOR_YEAR_ASSET_ID'"}'
      ```

      Calling it again replaces the link: the old URL stops working at once.

      **Extend it** by 90 days from today, keeping the same URL. This also
      brings back a link that has expired.

      ```bash
      curl -X POST https://api2.mworks.com/v2/viewcast/select/$ASSET_ID/share/renew \
        -H "X-API-Key: $MW_API_KEY"
      ```

      **Check it**: `state` is `active`, `expired` or `revoked`.

      ```bash
      curl https://api2.mworks.com/v2/viewcast/select/$ASSET_ID/share \
        -H "X-API-Key: $MW_API_KEY"
      ```
