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

# Apply optimizer run

> Apply an Etsy Ads optimizer preview exactly as previewed: its planned pauses and moves to Lower click cost, or its search terms turned off, and nothing else.

**Cost:** 1 API credit per write.

> [!NOTE]
>
> Needs the seller's Chrome open somewhere, with the Alura extension and signed in to Etsy for this shop. The script or agent can run on another computer. An offline extension answers [`extension_offline`](https://docs.alura.io/errors/extension_offline); the [live status](https://docs.alura.io/api-reference/workspace/shops/live/get.md) can name a more specific connection problem. Errors cost no API credits. See [Chrome extension](https://docs.alura.io/api-reference/chrome-extension.md).

```bash
curl -X POST "https://api.alura.io/v1/workspace/ads/optimize/runs/0b9f0e3a-6d2c-4f0e-9a51-3c2d8e7f1a42/apply" \
  -H "Authorization: Bearer $ALURA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"plan_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}'
```

Needs the `ads:write` scope and the **Etsy Ads** workspace permission. Send `dry_run=true` to see the writes it would send, without sending them. Send the preview's `plan_hash` to be sure you apply the plan you read.

> [!WARNING]
>
> This changes your live Etsy Ads. Undo it with [Revert optimizer run](https://docs.alura.io/api-reference/workspace/ads/optimize/runs/revert.md), or in Alura's Etsy Ads history, where the seller sees it.

A run is applied once. Applying it again, with any `Idempotency-Key`, answers the run as recorded.

## When it is refused

Each of these sends nothing to Etsy:

| Answer | When |
| - | - |
| `410` [`optimize_run_expired`](https://docs.alura.io/errors/optimize_run_expired) | The preview expired |
| `409` [`optimize_settings_required`](https://docs.alura.io/errors/optimize_settings_required) | The preview used the safe default because no settings are saved |
| `409` [`optimize_plan_changed`](https://docs.alura.io/errors/optimize_plan_changed) | The saved settings changed since, or `plan_hash` is not the preview's |
| `409` [`optimize_run_too_large`](https://docs.alura.io/errors/optimize_run_too_large) | The plan holds more than 120 changes or more than 45 moves to Lower click cost. Preview with `overrides.max_actions`. |
| `409` [`optimize_shop_busy`](https://docs.alura.io/errors/optimize_shop_busy) | Another session is changing the shop's Etsy Ads: Alura's Etsy Ads page, or another run. Wait for `Retry-After`, then retry. |

## How the writes run

Just before writing, Alura reads each listing on Etsy:

* A listing already paused, or already on Lower click cost, is left out.
* A listing it can't read is `skipped`.
* A move records the strategy Etsy shows now, which a revert restores.

Then it sends one Etsy write per 15 listings of one kind, pauses first, each read back from Etsy before the next. A write that doesn't succeed stops the ones after it (`not_sent`).

Search terms go one write per term, at most 7, each read back from the listing's search terms. A term Etsy's read-back doesn't list stays `unconfirmed`.

A change counts as `applied` only when Etsy shows it. One Etsy can't show back stays `unconfirmed` and is never counted in `projected_monthly_spend_freed`.

Alura records the run in its Etsy Ads history with `source: api`.

## Limits

The shop takes 20 Etsy writes a minute and 500 a day, and 30 live reads a minute. Each change is read on Etsy before and after. A request that needs more than are left is refused first: `429` [`live_rate_limited`](https://docs.alura.io/errors/live_rate_limited), nothing sent.

Only a write that lands is charged. See [Credits and limits](https://docs.alura.io/api-reference/credits-and-limits.md).

Past its time budget, or when Etsy has not shown the outcome yet, it answers 202 with its change (a retry under the same `Idempotency-Key` then answers the result).


## OpenAPI

````yaml /openapi.json post /v1/workspace/ads/optimize/runs/{id}/apply
openapi: 3.1.0
info:
  title: Alura API
  version: 1.0.0
  description: Etsy market research for scripts and AI assistants.
servers:
  - url: https://api.alura.io
security:
  - apiKey: []
paths:
  /v1/workspace/ads/optimize/runs/{id}/apply:
    post:
      summary: Apply optimizer run
      description: >-
        Applies a preview run (`POST /v1/workspace/ads/optimize/runs`) exactly
        as previewed: its planned pauses and moves to Lower click cost, or its
        search terms turned off, and nothing else. Refused, with nothing sent to
        Etsy, when the preview expired (410 `optimize_run_expired`), when it
        used the safe default because no settings are saved (409
        `optimize_settings_required`), when the saved settings changed since or
        `plan_hash` (optional) is not the preview's (409
        `optimize_plan_changed`), or when it plans more than 120 changes (409
        `optimize_run_too_large`: preview with `overrides.max_actions`). Just
        before writing, Alura reads each listing on Etsy: one already paused (or
        on Lower click cost) is left out, one it can't read is `skipped`, and a
        move records the strategy Etsy shows now, which a revert restores. Then
        one Etsy write per 15 listings of one kind, pauses first, each read back
        from Etsy before the next (search terms: one write per term, at most 7,
        paced as Alura's keyword writes, each read back from the listing's
        search terms; a term Etsy's read-back doesn't list stays `unconfirmed`,
        never `applied`); a change counts as `applied` only when Etsy shows it,
        and one Etsy can't show back stays `unconfirmed` (never counted in
        `projected_monthly_spend_freed`). The run is recorded in Alura's Etsy
        Ads history (`source: api`), where the seller sees and can undo it,
        while another session changing the shop's Etsy Ads (Alura's Etsy Ads
        page, another run) is 409 `optimize_shop_busy`. A run is applied once:
        applying it again, with any `Idempotency-Key`, answers the run as
        recorded. Each Etsy write needs Chrome open with the Alura extension,
        logged into the shop on Etsy (`extension_offline`, `etsy_not_logged_in`
        or `etsy_shop_mismatch` say which is missing). A write that does not
        succeed stops the ones after it (`not_sent`). The shop takes 20 Etsy
        writes a minute and 500 a day: a request that needs more than are left
        is refused first, 429 `live_rate_limited`, nothing sent. Needs the
        `ads:write` scope and the Etsy Ads permission. Costs 1 API credit per
        Etsy write that lands; a refusal costs nothing, and `dry_run=true` shows
        the writes it would send for free. Past its time budget, or when Etsy
        has not shown the outcome yet, it answers 202 with its change (a retry
        under the same `Idempotency-Key` then answers the result).


        Cost: 1 API credit per write.
      operationId: workspace.ads.optimize.runs.apply
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            minLength: 1
            maxLength: 80
            pattern: ^[A-Za-z0-9_-]{1,80}$
            description: 'The run ID: a preview''s, or a run in the shop''s history.'
            example: 0b9f0e3a-6d2c-4f0e-9a51-3c2d8e7f1a42
        - name: dry_run
          in: query
          required: false
          description: >-
            `true`: plan the write and send nothing: what it would change, the
            Etsy calls it would make, and nothing reserved, charged or recorded.
            Free; counts toward the per-minute write limit.
          schema:
            type: boolean
        - name: Idempotency-Key
          in: header
          required: false
          description: >-
            Makes a retry safe: the same key with the same request within 24
            hours answers from the first write (with `Idempotent-Replayed:
            true`) and never writes to Etsy twice; a write that failed with
            nothing written (`Retry-After` set) is tried again under it. The
            same key with a different request is a 409 `conflict`; while the
            first request still runs, 409 `idempotency_processing` (or the same
            202). Required for relative changes such as `adjust_price`, and to
            add a listing file, image or video, or to change the alt text of an
            image (each uploads to Etsy, so a blind retry would upload again); a
            `dry_run=true` needs none.
          schema:
            type: string
            minLength: 1
            maxLength: 255
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                plan_hash:
                  description: >-
                    The preview's `plan_hash`: when sent, the apply is refused
                    (409 `optimize_plan_changed`, nothing sent) unless it is
                    still the plan kept for this run.
                  type: string
                  pattern: ^[0-9a-f]{64}$
              additionalProperties: false
            example:
              plan_hash: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
      responses:
        '200':
          description: >-
            OK: the write landed on Etsy (or, with `dry_run=true`, what it would
            do).
          headers:
            Request-Id:
              $ref: '#/components/headers/Request-Id'
            Alura-Credits-Cost:
              $ref: '#/components/headers/Alura-Credits-Cost'
            Alura-Credits-Remaining:
              $ref: '#/components/headers/Alura-Credits-Remaining'
            Idempotent-Replayed:
              description: '`true` when this answers an earlier request with the same key.'
              schema:
                type: string
            Alura-Write-Budget-Remaining:
              description: The shop's Etsy write budget left, when known.
              schema:
                type: integer
            Alura-Write-Deduplicated:
              description: >-
                Set when this write was answered, free, from an earlier
                identical write: that write's change id (`chn_...`). Nothing was
                sent to Etsy again.
              schema:
                type: string
          content:
            application/json:
              schema:
                anyOf:
                  - type: object
                    properties:
                      object:
                        type: string
                        const: workspace.ads_optimize_run
                      id:
                        type: string
                      readable:
                        type: boolean
                        const: true
                      status:
                        type: string
                        enum:
                          - applying
                          - applied
                          - partial
                        description: >-
                          `applying`: writes in flight; `applied`: every change
                          sent; `partial`: some failed or were not sent (an
                          interrupted run included, `interrupted_at`).
                      shop_id:
                        type: string
                      target:
                        type: string
                        enum:
                          - listings
                          - search_terms
                      source:
                        type: string
                        enum:
                          - api
                          - app
                          - restore
                        description: >-
                          Who wrote it: `api`, `app` (Alura's Etsy Ads page) or
                          `restore` (the app's strategy repair).
                      created_at:
                        type: string
                        description: ISO 8601, UTC.
                      strategy_name:
                        type: string
                        description: The name of the strategy the run used.
                      period:
                        type: string
                        description: >-
                          The stats period the plan judged: `last_30_days`,
                          `last_3_months`, `last_12_months` or `all_time`.
                      basis:
                        anyOf:
                          - type: string
                            enum:
                              - saved
                              - explicit
                              - default
                          - type: 'null'
                      applied_by:
                        anyOf:
                          - type: object
                            properties:
                              type:
                                type: string
                              id:
                                type: string
                              client:
                                type:
                                  - string
                                  - 'null'
                            required:
                              - type
                              - id
                              - client
                            additionalProperties: false
                          - type: 'null'
                        description: >-
                          Who applied an API run: the API key or OAuth grant;
                          null for app runs.
                      verified:
                        anyOf:
                          - type: string
                            enum:
                              - confirmed
                              - unverified
                          - type: 'null'
                        description: >-
                          `confirmed`: Etsy's read-back answered for the run;
                          `unverified`: writes went out but nothing confirmed
                          them; null: nothing needed confirming (or an older app
                          run).
                      undone:
                        type: boolean
                      closed_manually:
                        type: boolean
                      interrupted_at:
                        anyOf:
                          - type: string
                            description: ISO 8601, UTC.
                          - type: 'null'
                        description: >-
                          When a run that stopped mid-apply was finalized; its
                          unanswered writes are `unconfirmed` with
                          `outcome_unknown`.
                      projected_monthly_spend_freed:
                        anyOf:
                          - type: object
                            properties:
                              amount:
                                type: string
                                description: Decimal string with the currency's decimals.
                              currency:
                                type: string
                                description: >-
                                  ISO 4217. Etsy Ads money (budget, spend,
                                  revenue) is `USD` for every shop, whatever the
                                  shop's own currency; a listing's price is in
                                  the currency Etsy names for it.
                            required:
                              - amount
                              - currency
                            additionalProperties: false
                            description: An amount of money.
                          - type: 'null'
                        description: >-
                          The spend freed the run still claims, as Alura's Etsy
                          Ads page shows it: the paused listings' spend over the
                          period, as 30 days (spend freed, not guaranteed cash
                          saved), for changes Etsy's read-back showed and still
                          standing (none once undone; a restored, resolved or
                          restore-pending change no longer counts), only spend
                          Etsy reported; with `spend_unknown_count` above 0 a
                          lower bound. In US dollars, whatever currency the run
                          recorded (Etsy Ads money is US dollars for every
                          shop); null when it is unknown.
                      spend_unknown_count:
                        type: integer
                        description: >-
                          Changes the figure had to leave out because Etsy
                          didn't report their spend: never added as 0.
                      action_counts:
                        type: object
                        properties:
                          applied:
                            type: integer
                            description: Actions Etsy's read-back showed.
                          unconfirmed:
                            type: integer
                            description: >-
                              Actions that may be on Etsy but nothing proved
                              (never counted as applied or in the spend freed).
                          failed:
                            type: integer
                            description: Actions refused with nothing written.
                          skipped:
                            type: integer
                            description: >-
                              Actions not sent (unreadable first, or after a
                              write that did not succeed).
                          pending:
                            type: integer
                            description: Actions still in flight.
                          outcome_unknown:
                            type: integer
                            description: >-
                              Of the unconfirmed, those the run lost track of
                              before Etsy answered.
                        required:
                          - applied
                          - unconfirmed
                          - failed
                          - skipped
                          - pending
                          - outcome_unknown
                        additionalProperties: false
                        description: >-
                          The actions by how they ended: a run `applied` with
                          any unconfirmed action is not proven done.
                      advertised_before:
                        anyOf:
                          - type: integer
                          - type: 'null'
                      advertised_after:
                        anyOf:
                          - type: integer
                          - type: 'null'
                        description: >-
                          Etsy's advertised total read back after the run; null
                          when not read.
                      actions:
                        type: array
                        items:
                          type: object
                          properties:
                            key:
                              type: string
                              description: >-
                                The change's key in the run (what `item_keys` of
                                a revert names).
                            listing_id:
                              type: string
                              description: The Etsy listing ID, as a string.
                            title:
                              type: string
                              description: >-
                                The listing's title (for a `mark_irrelevant`
                                change: the search term).
                            image_url:
                              type:
                                - string
                                - 'null'
                            action:
                              type: string
                              enum:
                                - pause
                                - lower_click_cost
                                - mark_irrelevant
                              description: >-
                                `pause`: stop advertising; `lower_click_cost`:
                                move to Lower click cost; `mark_irrelevant`: a
                                search term turned off (app runs).
                            query:
                              description: >-
                                The search term of a `mark_irrelevant` change;
                                null otherwise.
                              type:
                                - string
                                - 'null'
                            reason:
                              description: >-
                                Why the rules matched, in words, as the run
                                recorded it.
                              type:
                                - string
                                - 'null'
                            prev_strategy:
                              anyOf:
                                - type: string
                                  enum:
                                    - efficient
                                    - lower_click_cost
                                    - greater_visibility
                                - type: 'null'
                              description: >-
                                The strategy a `lower_click_cost` change
                                replaced, as Etsy showed it just before the
                                write (what an undo restores); null otherwise or
                                when unknown.
                            status:
                              type: string
                              enum:
                                - pending
                                - applied
                                - unconfirmed
                                - failed
                                - skipped
                              description: >-
                                `pending`: its write is still in flight;
                                `applied`: Etsy's read-back shows it;
                                `unconfirmed`: it may be on Etsy but no
                                read-back proved it (or one contradicted it),
                                never counted as applied or in the spend freed;
                                `failed`: refused with nothing written;
                                `skipped`: not sent (its state on Etsy couldn't
                                be read first, or an earlier write of the run
                                did not succeed).
                            outcome_unknown:
                              type: boolean
                              description: >-
                                true when the run lost track of this write
                                before Etsy answered: it may or may not have
                                landed.
                            error:
                              description: >-
                                Why the write did not land, as the run recorded
                                it; null otherwise.
                              type:
                                - string
                                - 'null'
                            undo:
                              anyOf:
                                - type: string
                                  enum:
                                    - restored
                                    - restore_unconfirmed
                                    - resolved
                                    - changed_since
                                    - conflict
                                - type: 'null'
                              description: >-
                                `restored`: undone and read back;
                                `restore_unconfirmed`: an undo was sent but not
                                read back yet (a revert sends it again after
                                reading Etsy); `resolved`: marked resolved in
                                the app; `changed_since`: changed on Etsy since,
                                left as is; `conflict`: another run changed it
                                too, left for the seller; null: standing.
                            change:
                              anyOf:
                                - type: object
                                  properties:
                                    id:
                                      type: string
                                  required:
                                    - id
                                  additionalProperties: false
                                - type: 'null'
                              description: >-
                                The Etsy write's change (`chn_…`) when this API
                                sent it, readable at `GET
                                /v1/workspace/changes/{id}`; null otherwise.
                          required:
                            - key
                            - listing_id
                            - title
                            - image_url
                            - action
                            - query
                            - reason
                            - prev_strategy
                            - status
                            - outcome_unknown
                            - error
                            - undo
                            - change
                          additionalProperties: false
                      actions_next_offset:
                        anyOf:
                          - type: integer
                          - type: 'null'
                        description: >-
                          Where the run's next actions start when `actions`
                          holds only some of them (MCP's history shows a large
                          run a page at a time: pass it back as
                          `actions_offset`); null when `actions` runs to the
                          run's last. Always null over REST, which answers every
                          action.
                    required:
                      - object
                      - id
                      - readable
                      - status
                      - shop_id
                      - target
                      - source
                      - created_at
                      - strategy_name
                      - period
                      - basis
                      - applied_by
                      - verified
                      - undone
                      - closed_manually
                      - interrupted_at
                      - projected_monthly_spend_freed
                      - spend_unknown_count
                      - action_counts
                      - advertised_before
                      - advertised_after
                      - actions
                      - actions_next_offset
                    additionalProperties: false
                  - type: object
                    properties:
                      object:
                        type: string
                        const: workspace.write_plan
                      operation:
                        type: string
                        description: The operation this plan is for.
                      target:
                        type: object
                        properties:
                          type:
                            type: string
                            description: >-
                              What the write changes: `listing`, `shop`,
                              `receipt`. New types may be added.
                          id:
                            type: string
                            description: Etsy ID, as a string.
                          shop_id:
                            type: string
                            description: Etsy ID, as a string.
                        required:
                          - type
                          - id
                          - shop_id
                        additionalProperties: false
                        description: What the write would change.
                      changes:
                        type: array
                        items:
                          type: object
                          properties:
                            field:
                              type: string
                              description: The field, named as in the resource.
                            from:
                              description: >-
                                For a text the write replaces whole: Alura's
                                copy of it now (null when Alura has none).
                            to:
                              description: The value it would be set to.
                          required:
                            - field
                            - to
                          additionalProperties: false
                        description: What the write would set, field by field.
                      command_hash:
                        type: string
                        pattern: ^[0-9a-f]{64}$
                        description: >-
                          A hash of the change Alura would send to Etsy: the
                          same request on the same object plans the same change,
                          whatever Alura has stored about it.
                      estimate:
                        type: object
                        properties:
                          etsy_calls_min:
                            type: integer
                            minimum: 0
                            description: The fewest Etsy calls the write makes.
                          etsy_calls_max:
                            type: integer
                            minimum: 0
                            description: >-
                              The most Etsy calls the write makes, counting its
                              token refreshes and every call Alura may send
                              again (after a timeout, an Etsy 409 conflict, a
                              rejected token or a video re-association's 5xx);
                              only the calls it sends again after Etsy answers
                              429 (rate limited) are not counted.
                        required:
                          - etsy_calls_min
                          - etsy_calls_max
                        additionalProperties: false
                        description: Etsy calls the write would make, as a range.
                      write_budget_remaining:
                        anyOf:
                          - type: integer
                            minimum: 0
                          - type: 'null'
                        description: >-
                          The shop's Etsy calls left in its rolling 24-hour
                          write budget, as of Alura's last count; null when
                          unknown (a dry run does not ask Etsy).
                      consequential:
                        type: boolean
                        description: >-
                          Whether the write needs the seller's confirmation over
                          MCP (today: every write documented here).
                      confirmation_token:
                        description: >-
                          Always null: over MCP the seller confirms a
                          consequential write in the host's prompt or on Alura's
                          approval page, never with a token.
                        type:
                          - string
                          - 'null'
                      confirmation_expires_at:
                        description: Always null (see `confirmation_token`).
                        type:
                          - string
                          - 'null'
                      notices:
                        type: array
                        items:
                          type: object
                          properties:
                            code:
                              type: string
                              description: >-
                                `write_budget_stale`: Alura's last count of the
                                write budget is from before its window moved on,
                                so `write_budget_remaining` is null.
                                `not_reverted`: a revert leaves a field of the
                                change as it is (its detail says which and why).
                                `text_shortened`: the write makes a text it
                                replaces whole (a title, a description, an alt
                                text, a personalization text, a shop text, a
                                note) shorter than Alura's copy, by how much.
                                `text_shortened_unknown`: Alura could not read
                                its copy to compare. `line_breaks_removed`: the
                                write takes line breaks out of such a text.
                                `links_removed`: the write drops links such a
                                text has, or sends `[link removed]` (how Alura
                                shows a link to an assistant) as text. New codes
                                may be added.
                            detail:
                              type: string
                          required:
                            - code
                            - detail
                          additionalProperties: false
                        description: >-
                          What the user should know before confirming: a part of
                          the plan that is unknown, or a text the write
                          shortens; empty when nothing.
                    required:
                      - object
                      - operation
                      - target
                      - changes
                      - command_hash
                      - estimate
                      - write_budget_remaining
                      - consequential
                      - confirmation_token
                      - confirmation_expires_at
                      - notices
                    additionalProperties: false
              example:
                object: workspace.ads_optimize_run
                id: 0b9f0e3a-6d2c-4f0e-9a51-3c2d8e7f1a42
                readable: true
                status: applied
                shop_id: '22841907'
                target: listings
                source: api
                created_at: '2026-10-17T12:00:00.000Z'
                strategy_name: Budget Saver
                period: all_time
                basis: saved
                applied_by:
                  type: api_key
                  id: key_01JMOCK00000000000000000KEY
                  client: null
                verified: confirmed
                undone: false
                closed_manually: false
                interrupted_at: null
                projected_monthly_spend_freed:
                  amount: '1.75'
                  currency: USD
                spend_unknown_count: 0
                action_counts:
                  applied: 1
                  unconfirmed: 0
                  failed: 0
                  skipped: 0
                  pending: 0
                  outcome_unknown: 0
                advertised_before: 3
                advertised_after: null
                actions:
                  - key: pause:1834720563
                    listing_id: '1834720563'
                    title: Hand-thrown ceramic mug
                    image_url: null
                    action: pause
                    query: null
                    reason: Spend $42.50 > $10.00 and Orders 0 = 0
                    prev_strategy: null
                    status: applied
                    outcome_unknown: false
                    error: null
                    undo: null
                    change:
                      id: chn_01JMOCK0000000000000000000
                actions_next_offset: null
        '202':
          description: >-
            Accepted: the write is still being applied on Etsy, or its outcome
            is being checked. Poll the change at `Location`.
          headers:
            Request-Id:
              $ref: '#/components/headers/Request-Id'
            Alura-Credits-Cost:
              $ref: '#/components/headers/Alura-Credits-Cost'
            Alura-Credits-Remaining:
              $ref: '#/components/headers/Alura-Credits-Remaining'
            Location:
              description: 'The change to poll: `/v1/workspace/changes/{id}`.'
              schema:
                type: string
            Retry-After:
              description: Seconds to wait before polling.
              schema:
                type: integer
            Idempotent-Replayed:
              description: '`true` when this answers an earlier request with the same key.'
              schema:
                type: string
            Alura-Write-Deduplicated:
              description: >-
                Set when this write was answered, free, from an earlier
                identical write: that write's change id (`chn_...`). Nothing was
                sent to Etsy again.
              schema:
                type: string
          content:
            application/json:
              schema:
                type: object
                properties:
                  object:
                    type: string
                    const: workspace.change
                  id:
                    type: string
                    description: >-
                      `chn_` + the change's number (a change made in Alura), or
                      `chn_` + a write's 26-character ID (a change made through
                      the API).
                  shop_id:
                    type: string
                    description: The connected shop the change was made in.
                  target:
                    type: object
                    properties:
                      type:
                        type: string
                        description: >-
                          What was changed: `listing`, `shop`, `receipt` or a
                          shop setting (`section`, `return_policy`,
                          `shipping_profile`, ...). New types may be added.
                      id:
                        type: string
                        description: Etsy ID, as a string.
                    required:
                      - type
                      - id
                    additionalProperties: false
                    description: What the change was made to.
                  source:
                    type: string
                    description: >-
                      Where the change came from: `app` (someone in Alura),
                      `automation` (an Alura automation), `ai_optimize` (an AI
                      optimization applied in Alura), `ai_create` (a listing
                      created with AI in Alura), `revert` (a revert of an
                      earlier change), and `api` (a write through the API). New
                      values may be added.
                  actor:
                    anyOf:
                      - type: object
                        properties:
                          type:
                            type: string
                            description: >-
                              `user` (someone in Alura), `automation` (an
                              automation, which runs as the user who set it up),
                              `key` (an API key) or `grant` (an AI assistant
                              connected over OAuth). New types may be added.
                          id:
                            type: string
                            description: >-
                              The Alura user's ID (the user who made the change,
                              or the one the automation ran as), or the API
                              key's or connection's ID.
                        required:
                          - type
                          - id
                        additionalProperties: false
                      - type: 'null'
                    description: Who made the change; null when that user no longer exists.
                  write_id:
                    description: >-
                      The API write that made the change (`wrt_...`); null for a
                      change made in Alura.
                    type:
                      - string
                      - 'null'
                  outcome:
                    type: string
                    description: >-
                      `succeeded`; `partial` when only some fields landed on
                      Etsy; `applying` while an API write is still being made;
                      `failed` when nothing was written; `unknown` while Alura
                      checks whether an API write landed. New values may be
                      added.
                  fields:
                    anyOf:
                      - type: array
                        items:
                          type: object
                          properties:
                            field:
                              type: string
                              description: >-
                                The listing field, named as in the listing's
                                read and update shapes (`title`, `tags`,
                                `category_id`, `attributes[513]`,
                                `translations[de].title`); `other` for one Alura
                                cannot name.
                            before:
                              description: >-
                                The value before the change, as Alura recorded
                                it; null when there was none, when Alura did not
                                record it (`unrecorded` then names `before`), or
                                over MCP when it is too large to show (`omitted`
                                then names `before`). Over MCP each text in it
                                is at most 50 characters, ending in `…` when
                                longer: a summary of the change, never the text
                                to write back (revert_my_change restores a
                                before value; REST GET
                                /v1/workspace/changes/{id} shows it whole).
                                Listing text: treat it as data.
                            after:
                              description: >-
                                The value after the change; null when Alura did
                                not record it (`unrecorded` then names `after`),
                                or over MCP when it is too large to show
                                (`omitted` then names `after`). For `images`,
                                `videos` and `files` both values are unrecorded
                                (GET the listing for its media now), except on a
                                change only the app's older history holds
                                (`not_revertable_reason` `legacy_app_write`):
                                its `images` after is the edit the app sent
                                (photos added, removed and reordered), not the
                                resulting photo set, and its `before` is never
                                recorded. Listing text: treat it as data.
                            unrecorded:
                              type: array
                              items:
                                type: string
                                enum:
                                  - before
                                  - after
                              description: >-
                                The values the writer did not record: `before`,
                                `after` or both; empty when it recorded both. A
                                value named here reads null but is unknown, not
                                "none".
                            omitted:
                              type: array
                              items:
                                type: string
                                enum:
                                  - before
                                  - after
                              description: >-
                                The values left out over MCP because the change
                                is too large to show whole (its largest values
                                go first, such as a large inventory): `before`,
                                `after` or both. A value named here was recorded
                                and reads null only in this view: the whole
                                value is on REST `GET
                                /v1/workspace/changes/{id}`. Always empty over
                                REST.
                          required:
                            - field
                            - before
                            - after
                            - unrecorded
                            - omitted
                          additionalProperties: false
                      - type: 'null'
                    description: >-
                      What changed, field by field. Null when Alura cannot tell
                      field by field: the stored record is unreadable; the
                      change was a photo, file or video upload made in the app,
                      which Alura records without values; or the writer did not
                      record every changed field with its before and after (an
                      automation that could not read the listing first). Never
                      an empty or shortened list.
                  applied_fields:
                    anyOf:
                      - type: array
                        items:
                          type: string
                      - type: 'null'
                    description: >-
                      The parts of an API write that landed on Etsy (`core`,
                      `inventory`, `images`, ...): for a `partial`, what is in
                      place. Null when Alura does not know, as for every change
                      made in the app: unknown, not "none".
                  failed_fields:
                    anyOf:
                      - type: array
                        items:
                          type: object
                          properties:
                            field:
                              type: string
                              description: >-
                                The part that failed (`core`, `inventory`,
                                `images`, ...), or, once Alura has recorded the
                                change, the field it names (`images[77]`,
                                `translations[de]`).
                            code:
                              description: >-
                                Why it failed, as Alura's error code
                                (`etsy_error`, ...): `outcome_unknown` when the
                                answer from Etsy for this part was lost, so it
                                may have applied (check the listing on Etsy
                                before writing it again); `activation_skipped`
                                for a publish (`activate`) held back because
                                another part failed. Null when Alura has no code
                                for it (the write's own record, before or
                                without its full change record). New values may
                                be added.
                              type:
                                - string
                                - 'null'
                          required:
                            - field
                            - code
                          additionalProperties: false
                      - type: 'null'
                    description: >-
                      The parts of an API write that failed, each with its error
                      code: for a `partial`, what to finish with a new write.
                      Null when Alura does not know, as for every change made in
                      the app: unknown, not "none".
                  before_source:
                    description: >-
                      Where `before` came from: `live` (read from Etsy during
                      the write) or `cache` (Alura's copy); null when unknown,
                      as for every change made in the app.
                    type:
                      - string
                      - 'null'
                  before_as_of:
                    anyOf:
                      - type: string
                        description: ISO 8601, UTC.
                      - type: 'null'
                    description: When `before` was current; null when unknown.
                  event:
                    description: >-
                      What kind of change: `edited`, `created`, `published`,
                      `deleted`, `reverted`, `shipment_added`, `shop_updated`,
                      `settings_created`, `settings_updated`,
                      `settings_deleted`. Null while an API write is still being
                      made. New values may be added.
                    type:
                      - string
                      - 'null'
                  revertable:
                    type: boolean
                    description: >-
                      Whether `POST /v1/workspace/changes/{id}/revert` can undo
                      it (at least one field): a change Alura made through its
                      change log with `before` read live from Etsy, whose core
                      fields, inventory prices, SKUs or enabled flags,
                      attributes, translations or personalization landed.
                      Reverting checks the listing on Etsy again first (`409
                      changed_since` when it moved).
                  not_revertable_reason:
                    description: >-
                      Why none of it can be reverted: `legacy_app_write` (a
                      change recorded only by the app: history only),
                      `before_from_cache` (`before` came from Alura's copy, not
                      Etsy), `before_unrecorded`, `after_unrecorded`,
                      `not_landed` (its core fields did not land),
                      `outcome_unknown` (whether it landed is not known: its
                      outcome is `unknown` or `applying`, or a `partial` without
                      its applied parts recorded; it may have), `delete`,
                      `publish_fee` (undoing a publish is not free on Etsy),
                      `shipment_notified_buyer` (Etsy emailed the buyer),
                      `images`, `files` (a digital file added or removed: the
                      API keeps no copy of a file), `quantity` (never restored
                      from a snapshot: oversell risk), `reactivates_listing` (it
                      would put the listing back on sale), `target_not_listing`
                      (shop changes; a shop setting's change is `delete` once
                      Alura has recorded that it deleted the setting, else
                      `not_supported`), `not_supported` (a field or part the API
                      cannot restore yet), `etsy_updated_at_unrecorded` (the
                      updated time of the listing on Etsy after the change was
                      not recorded, so Alura's record of it is incomplete),
                      `needs_production_partners` (`who_made: someone_else`
                      cannot be restored without production partners, which a
                      revert never restores), `field_unrecorded` (the change did
                      not record a value it wrote), `translation_added` (the
                      change created a translation, and Etsy has no translation
                      delete), `variations_changed` (an inventory change that
                      added or removed variants, or moved which property sets
                      the price or SKU), `reference_deleted` (the section,
                      shipping profile or return policy it would put back has
                      been deleted since), `revertability_unknown` (on a write's
                      own answer only, when Alura could not read its change
                      record just then: GET /v1/workspace/changes/{id} answers
                      it). Null when it can. New values may be added.
                    type:
                      - string
                      - 'null'
                  reverts:
                    description: >-
                      For a change with `source: revert`: the id of the change
                      it undid (`chn_...`). Null otherwise, and on the
                      `workspace.change` a revert answers with while Etsy is
                      still answering (GET /v1/workspace/changes/{id} has it
                      once the revert is recorded).
                    type:
                      - string
                      - 'null'
                  created_at:
                    type: string
                    description: When the change was made.
                  as_of:
                    type: string
                    description: When this record was read.
                required:
                  - object
                  - id
                  - shop_id
                  - target
                  - source
                  - actor
                  - write_id
                  - outcome
                  - fields
                  - applied_fields
                  - failed_fields
                  - before_source
                  - before_as_of
                  - event
                  - revertable
                  - not_revertable_reason
                  - reverts
                  - created_at
                  - as_of
                additionalProperties: false
        '400':
          $ref: '#/components/responses/WriteProblem400'
        '401':
          $ref: '#/components/responses/Problem401'
        '402':
          $ref: '#/components/responses/WriteProblem402'
        '403':
          $ref: '#/components/responses/WriteProblem403'
        '404':
          description: >-
            Error. A refusal of a write Alura recorded carries its `change_id`,
            and by code `budget`, `reason`, `changed`, `missing`,
            `reconnect_url` or `missing_scopes`. `not_found` carries `shop_id`.
          content:
            application/problem+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Problem'
                  - type: object
                    properties:
                      change_id:
                        type: string
                        description: >-
                          The recorded write this refusal answers, as its change
                          (`chn_...`): read it (`GET
                          /v1/workspace/changes/{id}`) before writing again.
                      budget:
                        type: string
                        description: >-
                          `shop_write_budget_exhausted`: which of the shop's
                          Etsy write budgets ran out (`creates`, `activations`,
                          `etsy_calls`).
                      reason:
                        description: >-
                          Why, as an identifier: for `change_not_revertable`,
                          why the revert was refused; null when none was named.
                        type:
                          - string
                          - 'null'
                      changed:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `changed_since`: the fields that changed on Etsy since
                          the change; `media_changed`: what differs from
                          `images_expected`, `videos_expected` or
                          `files_expected`, as `images.unexpected.<id>` (on
                          Etsy, not expected) or `images.missing.<id>`
                          (expected, no longer on Etsy); null when none was
                          named.
                      missing:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `listing_not_publishable`: what Etsy said the listing
                          lacks to publish; null when it named none.
                      reconnect_url:
                        type: string
                        description: >-
                          `reconnect_required` and `etsy_scope_required`: where
                          the shop is reconnected in Alura.
                      missing_scopes:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `etsy_scope_required`: the Etsy scopes the shop's
                          connection lacks; null when none was named.
                      shop_id:
                        description: The Etsy shop ID Alura read for.
                        type: string
        '405':
          $ref: '#/components/responses/Problem405'
        '409':
          description: >-
            Error. A refusal of a write Alura recorded carries its `change_id`,
            and by code `budget`, `reason`, `changed`, `missing`,
            `reconnect_url` or `missing_scopes`. `etsy_not_logged_in` carries
            `shop_id`. `etsy_shop_mismatch` carries `shop_id`, `state`,
            `holder`, `last_served_at`, `action`. `holder_offline` carries
            `shop_id`, `state`, `holder`, `last_served_at`, `action`.
            `login_expired` carries `shop_id`, `state`, `holder`,
            `last_served_at`, `action`. `never_connected` carries `shop_id`,
            `state`, `holder`, `last_served_at`, `action`. `saved_shops_off`
            carries `shop_id`, `state`, `holder`, `last_served_at`, `action`.
            `etsy_refused` carries `shop_id`. `settings_unreadable` carries
            `version`. `runs_unreadable` carries `unreadable`.
          content:
            application/problem+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Problem'
                  - type: object
                    properties:
                      change_id:
                        type: string
                        description: >-
                          The recorded write this refusal answers, as its change
                          (`chn_...`): read it (`GET
                          /v1/workspace/changes/{id}`) before writing again.
                      budget:
                        type: string
                        description: >-
                          `shop_write_budget_exhausted`: which of the shop's
                          Etsy write budgets ran out (`creates`, `activations`,
                          `etsy_calls`).
                      reason:
                        description: >-
                          Why, as an identifier: for `change_not_revertable`,
                          why the revert was refused; null when none was named.
                        type:
                          - string
                          - 'null'
                      changed:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `changed_since`: the fields that changed on Etsy since
                          the change; `media_changed`: what differs from
                          `images_expected`, `videos_expected` or
                          `files_expected`, as `images.unexpected.<id>` (on
                          Etsy, not expected) or `images.missing.<id>`
                          (expected, no longer on Etsy); null when none was
                          named.
                      missing:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `listing_not_publishable`: what Etsy said the listing
                          lacks to publish; null when it named none.
                      reconnect_url:
                        type: string
                        description: >-
                          `reconnect_required` and `etsy_scope_required`: where
                          the shop is reconnected in Alura.
                      missing_scopes:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `etsy_scope_required`: the Etsy scopes the shop's
                          connection lacks; null when none was named.
                      shop_id:
                        description: The Etsy shop ID Alura read for.
                        type: string
                      state:
                        description: >-
                          The shop's live state, the same as GET
                          /v1/workspace/live shows for it.
                        type: string
                        enum:
                          - login_expired
                          - etsy_shop_mismatch
                          - holder_offline
                          - never_connected
                          - saved_shops_off
                      holder:
                        description: >-
                          The browser the state is about; null when none holds
                          the shop, or it is not known.
                        anyOf:
                          - type: object
                            properties:
                              label:
                                type: string
                                description: >-
                                  The browser's name, as Settings lists it
                                  ("Chrome on macOS · 64NN").
                              last_seen_at:
                                description: >-
                                  When it was last online (ISO 8601); null when
                                  unknown.
                                type:
                                  - string
                                  - 'null'
                            required:
                              - label
                              - last_seen_at
                            additionalProperties: false
                          - type: 'null'
                      last_served_at:
                        description: >-
                          When a browser last served this shop (ISO 8601); null
                          when none did.
                        type:
                          - string
                          - 'null'
                      action:
                        description: What fixes it, in one sentence for the seller.
                        type: string
                      version:
                        type: integer
                        minimum: 0
                        description: >-
                          The settings' version: 0 when none are saved, else
                          bumped by 1 on every save, the app's and the API's.
                      unreadable:
                        type: array
                        items:
                          type: object
                          properties:
                            id:
                              type: string
                            created_at:
                              type:
                                - string
                                - 'null'
                          required:
                            - id
                            - created_at
                          additionalProperties: false
                        description: The stored runs Alura cannot read, by id and date.
        '410':
          $ref: '#/components/responses/WriteProblem410'
        '422':
          $ref: '#/components/responses/WriteProblem422'
        '429':
          description: >-
            Error. A refusal of a write Alura recorded carries its `change_id`,
            and by code `budget`, `reason`, `changed`, `missing`,
            `reconnect_url` or `missing_scopes`. `etsy_rate_limited` carries
            `shop_id`, `retry_after_seconds`. `live_rate_limited` carries
            `shop_id`, `retry_after_seconds`.
          content:
            application/problem+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Problem'
                  - type: object
                    properties:
                      change_id:
                        type: string
                        description: >-
                          The recorded write this refusal answers, as its change
                          (`chn_...`): read it (`GET
                          /v1/workspace/changes/{id}`) before writing again.
                      budget:
                        type: string
                        description: >-
                          `shop_write_budget_exhausted`: which of the shop's
                          Etsy write budgets ran out (`creates`, `activations`,
                          `etsy_calls`).
                      reason:
                        description: >-
                          Why, as an identifier: for `change_not_revertable`,
                          why the revert was refused; null when none was named.
                        type:
                          - string
                          - 'null'
                      changed:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `changed_since`: the fields that changed on Etsy since
                          the change; `media_changed`: what differs from
                          `images_expected`, `videos_expected` or
                          `files_expected`, as `images.unexpected.<id>` (on
                          Etsy, not expected) or `images.missing.<id>`
                          (expected, no longer on Etsy); null when none was
                          named.
                      missing:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `listing_not_publishable`: what Etsy said the listing
                          lacks to publish; null when it named none.
                      reconnect_url:
                        type: string
                        description: >-
                          `reconnect_required` and `etsy_scope_required`: where
                          the shop is reconnected in Alura.
                      missing_scopes:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `etsy_scope_required`: the Etsy scopes the shop's
                          connection lacks; null when none was named.
                      shop_id:
                        description: The Etsy shop ID Alura read for.
                        type: string
                      retry_after_seconds:
                        type: integer
                        minimum: 1
                        description: >-
                          Seconds to wait before retrying, the same as the
                          Retry-After header.
        '500':
          $ref: '#/components/responses/WriteProblem500'
        '502':
          description: >-
            Error. A refusal of a write Alura recorded carries its `change_id`,
            and by code `budget`, `reason`, `changed`, `missing`,
            `reconnect_url` or `missing_scopes`. `etsy_changed` carries
            `shop_id`.
          content:
            application/problem+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Problem'
                  - type: object
                    properties:
                      change_id:
                        type: string
                        description: >-
                          The recorded write this refusal answers, as its change
                          (`chn_...`): read it (`GET
                          /v1/workspace/changes/{id}`) before writing again.
                      budget:
                        type: string
                        description: >-
                          `shop_write_budget_exhausted`: which of the shop's
                          Etsy write budgets ran out (`creates`, `activations`,
                          `etsy_calls`).
                      reason:
                        description: >-
                          Why, as an identifier: for `change_not_revertable`,
                          why the revert was refused; null when none was named.
                        type:
                          - string
                          - 'null'
                      changed:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `changed_since`: the fields that changed on Etsy since
                          the change; `media_changed`: what differs from
                          `images_expected`, `videos_expected` or
                          `files_expected`, as `images.unexpected.<id>` (on
                          Etsy, not expected) or `images.missing.<id>`
                          (expected, no longer on Etsy); null when none was
                          named.
                      missing:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `listing_not_publishable`: what Etsy said the listing
                          lacks to publish; null when it named none.
                      reconnect_url:
                        type: string
                        description: >-
                          `reconnect_required` and `etsy_scope_required`: where
                          the shop is reconnected in Alura.
                      missing_scopes:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `etsy_scope_required`: the Etsy scopes the shop's
                          connection lacks; null when none was named.
                      shop_id:
                        description: The Etsy shop ID Alura read for.
                        type: string
        '503':
          description: >-
            Error. A refusal of a write Alura recorded carries its `change_id`,
            and by code `budget`, `reason`, `changed`, `missing`,
            `reconnect_url` or `missing_scopes`. `extension_offline` carries
            `shop_id`. `etsy_challenge` carries `shop_id`. `etsy_unavailable`
            carries `shop_id`, `reason`. `live_data_paused` carries `shop_id`.
          content:
            application/problem+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Problem'
                  - type: object
                    properties:
                      change_id:
                        type: string
                        description: >-
                          The recorded write this refusal answers, as its change
                          (`chn_...`): read it (`GET
                          /v1/workspace/changes/{id}`) before writing again.
                      budget:
                        type: string
                        description: >-
                          `shop_write_budget_exhausted`: which of the shop's
                          Etsy write budgets ran out (`creates`, `activations`,
                          `etsy_calls`).
                      reason:
                        description: >-
                          A saved shop's browser context was busy; retry after
                          Retry-After.
                        type: string
                        const: shop_busy
                      changed:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `changed_since`: the fields that changed on Etsy since
                          the change; `media_changed`: what differs from
                          `images_expected`, `videos_expected` or
                          `files_expected`, as `images.unexpected.<id>` (on
                          Etsy, not expected) or `images.missing.<id>`
                          (expected, no longer on Etsy); null when none was
                          named.
                      missing:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `listing_not_publishable`: what Etsy said the listing
                          lacks to publish; null when it named none.
                      reconnect_url:
                        type: string
                        description: >-
                          `reconnect_required` and `etsy_scope_required`: where
                          the shop is reconnected in Alura.
                      missing_scopes:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `etsy_scope_required`: the Etsy scopes the shop's
                          connection lacks; null when none was named.
                      shop_id:
                        description: The Etsy shop ID Alura read for.
                        type: string
        '504':
          description: >-
            Error. A refusal of a write Alura recorded carries its `change_id`,
            and by code `budget`, `reason`, `changed`, `missing`,
            `reconnect_url` or `missing_scopes`. `upstream_timeout` carries
            `shop_id`, `hint`.
          content:
            application/problem+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Problem'
                  - type: object
                    properties:
                      change_id:
                        type: string
                        description: >-
                          The recorded write this refusal answers, as its change
                          (`chn_...`): read it (`GET
                          /v1/workspace/changes/{id}`) before writing again.
                      budget:
                        type: string
                        description: >-
                          `shop_write_budget_exhausted`: which of the shop's
                          Etsy write budgets ran out (`creates`, `activations`,
                          `etsy_calls`).
                      reason:
                        description: >-
                          Why, as an identifier: for `change_not_revertable`,
                          why the revert was refused; null when none was named.
                        type:
                          - string
                          - 'null'
                      changed:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `changed_since`: the fields that changed on Etsy since
                          the change; `media_changed`: what differs from
                          `images_expected`, `videos_expected` or
                          `files_expected`, as `images.unexpected.<id>` (on
                          Etsy, not expected) or `images.missing.<id>`
                          (expected, no longer on Etsy); null when none was
                          named.
                      missing:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `listing_not_publishable`: what Etsy said the listing
                          lacks to publish; null when it named none.
                      reconnect_url:
                        type: string
                        description: >-
                          `reconnect_required` and `etsy_scope_required`: where
                          the shop is reconnected in Alura.
                      missing_scopes:
                        anyOf:
                          - type: array
                            items:
                              type: string
                          - type: 'null'
                        description: >-
                          `etsy_scope_required`: the Etsy scopes the shop's
                          connection lacks; null when none was named.
                      shop_id:
                        description: The Etsy shop ID Alura read for.
                        type: string
                      hint:
                        description: >-
                          After an Etsy-side failure on `range=max`, read again:
                          a shorter range that is likelier to answer.
                        type: object
                        properties:
                          range:
                            type: string
                            const: last_30
                        required:
                          - range
                        additionalProperties: false
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >-
            curl -X POST
            "https://api.alura.io/v1/workspace/ads/optimize/runs/0b9f0e3a-6d2c-4f0e-9a51-3c2d8e7f1a42/apply"
            \
              -H "Authorization: Bearer $ALURA_API_KEY" \
              -H "Content-Type: application/json" \
              -H "Idempotency-Key: 5f0c8e2a-4b1d-4c3e-9a7f-2b5d6e8f0a1c" \
              -d '{"plan_hash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}'
        - lang: typescript
          label: TypeScript
          source: >-
            const res = await
            fetch('https://api.alura.io/v1/workspace/ads/optimize/runs/0b9f0e3a-6d2c-4f0e-9a51-3c2d8e7f1a42/apply',
            {
              method: 'POST',
              headers: {
                Authorization: `Bearer ${process.env.ALURA_API_KEY}`,
                'Content-Type': 'application/json',
                'Idempotency-Key': '5f0c8e2a-4b1d-4c3e-9a7f-2b5d6e8f0a1c',
              },
              body: JSON.stringify({
                "plan_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
              }),
            });

            console.log(await res.json());
        - lang: python
          label: Python
          source: |-
            import json
            import os
            import urllib.request

            request = urllib.request.Request(
                "https://api.alura.io/v1/workspace/ads/optimize/runs/0b9f0e3a-6d2c-4f0e-9a51-3c2d8e7f1a42/apply",
                method="POST",
                data=json.dumps({
                  "plan_hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
                }).encode(),
                headers={
                    "Authorization": f"Bearer {os.environ['ALURA_API_KEY']}",
                    "Content-Type": "application/json",
                    "Idempotency-Key": "5f0c8e2a-4b1d-4c3e-9a7f-2b5d6e8f0a1c",
                },
            )
            with urllib.request.urlopen(request) as response:
                print(json.load(response))
components:
  headers:
    Request-Id:
      description: '`req_` + ULID; quote it when reporting a problem.'
      schema:
        type: string
    Alura-Credits-Cost:
      description: API credits this call cost.
      schema:
        type: integer
    Alura-Credits-Remaining:
      description: >-
        API credits left in the workspace's monthly allowance, counting calls
        still in flight. Absent when it cannot be read right now.
      schema:
        type: integer
  responses:
    WriteProblem400:
      description: >-
        Error. A refusal of a write Alura recorded carries its `change_id`, and
        by code `budget`, `reason`, `changed`, `missing`, `reconnect_url` or
        `missing_scopes`.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/WriteProblem'
    Problem401:
      description: Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: https://docs.alura.io/errors/unauthorized
            title: Unauthorized
            status: 401
            code: unauthorized
            detail: Unauthorized
            suggestion: 'Send a valid API key as `Authorization: Bearer alura_sk_...`.'
            retryable: false
            request_id: req_01JQ5W3H8M2N4P6R8T0V2X4Z6B
    WriteProblem402:
      description: >-
        Error. A refusal of a write Alura recorded carries its `change_id`, and
        by code `budget`, `reason`, `changed`, `missing`, `reconnect_url` or
        `missing_scopes`.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/WriteProblem'
    WriteProblem403:
      description: >-
        Error. A refusal of a write Alura recorded carries its `change_id`, and
        by code `budget`, `reason`, `changed`, `missing`, `reconnect_url` or
        `missing_scopes`.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/WriteProblem'
    Problem405:
      description: Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: https://docs.alura.io/errors/method_not_allowed
            title: Method not allowed
            status: 405
            code: method_not_allowed
            detail: Method not allowed
            suggestion: Use one of the methods in the Allow header.
            retryable: false
            request_id: req_01JQ5W3H8M2N4P6R8T0V2X4Z6B
    WriteProblem410:
      description: >-
        Error. A refusal of a write Alura recorded carries its `change_id`, and
        by code `budget`, `reason`, `changed`, `missing`, `reconnect_url` or
        `missing_scopes`.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/WriteProblem'
    WriteProblem422:
      description: >-
        Error. A refusal of a write Alura recorded carries its `change_id`, and
        by code `budget`, `reason`, `changed`, `missing`, `reconnect_url` or
        `missing_scopes`.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/WriteProblem'
    WriteProblem500:
      description: >-
        Error. A refusal of a write Alura recorded carries its `change_id`, and
        by code `budget`, `reason`, `changed`, `missing`, `reconnect_url` or
        `missing_scopes`.
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/WriteProblem'
  schemas:
    Problem:
      type: object
      description: RFC 9457 problem details.
      properties:
        type:
          type: string
          format: uri
        title:
          type: string
        status:
          type: integer
        code:
          type: string
          description: A code from the error catalog; new codes may be added.
          x-extensible-enum:
            - invalid_request
            - unknown_parameter
            - invalid_cursor
            - cursor_window_exceeded
            - invalid_reference
            - id_type_mismatch
            - invalid_keyword
            - shop_id_required
            - listing_not_publishable
            - sales_window_not_covered
            - range_too_long_for_interval
            - target_not_available
            - unauthorized
            - credits_exhausted
            - plan_required
            - insufficient_scope
            - workspace_required
            - workspace_locked
            - your_shop_unavailable
            - writes_suspended
            - browser_refused
            - live_data_not_enabled
            - send_not_enabled
            - attachments_not_enabled
            - self_approval
            - role_required
            - impersonation_refused
            - recent_sign_in_required
            - etsy_scope_required
            - etsy_partner_required
            - not_found
            - not_collected
            - not_found_on_etsy
            - shop_opted_out
            - method_not_allowed
            - conflict
            - settings_conflict
            - settings_unreadable
            - optimize_settings_required
            - optimize_plan_changed
            - optimize_run_applied
            - optimize_run_applying
            - optimize_run_too_large
            - optimize_nothing_to_apply
            - optimize_nothing_to_revert
            - optimize_shop_busy
            - runs_unreadable
            - run_not_resumable
            - suggestion_not_pending
            - draft_sent
            - draft_dismissed
            - draft_sending
            - conversation_changed
            - key_limit_reached
            - etsy_not_logged_in
            - etsy_shop_mismatch
            - holder_offline
            - login_expired
            - never_connected
            - etsy_refused
            - extension_update_required
            - attachment_used
            - attachment_expired
            - attachment_unavailable
            - saved_shops_off
            - review_already_replied
            - insights_search_unavailable
            - reconnect_required
            - settings_not_fetched
            - listing_busy
            - settings_busy
            - shop_create_busy
            - idempotency_partial_unverifiable
            - listing_has_variations
            - listing_sold_out
            - changed_since
            - change_not_revertable
            - media_changed
            - text_changed
            - inventory_changed
            - base_unverifiable
            - listing_in_ab_test
            - activation_skipped
            - idempotency_processing
            - confirmation_required
            - test_shop_active_cap
            - write_outcome_unknown
            - margin_required
            - unprocessable
            - knowledge_limit_reached
            - status_required
            - listing_removed_on_etsy
            - optimize_run_expired
            - endpoint_removed
            - rate_limited
            - throttled
            - daily_credit_cap_exceeded
            - credits_reserved
            - fetch_limit_reached
            - write_rate_limited
            - sync_cooldown
            - shop_write_budget_exhausted
            - live_rate_limited
            - etsy_rate_limited
            - internal_error
            - write_misconfigured
            - etsy_changed
            - upstream_unavailable
            - extension_offline
            - etsy_unavailable
            - etsy_challenge
            - live_data_paused
            - live_data_unavailable
            - credits_unavailable
            - service_unavailable
            - fetch_unavailable
            - create_lock_unavailable
            - writes_paused
            - etsy_capacity
            - upstream_timeout
        detail:
          type: string
        suggestion:
          type: string
        retryable:
          type: boolean
        request_id:
          type: string
        upgrade_url:
          type: string
          format: uri
          description: 'credits_exhausted and plan_required: where to upgrade the plan.'
        credits_needed:
          type: integer
          description: 'API credit refusals: what the call needed.'
        credits_remaining:
          type: integer
          description: >-
            API credit refusals: what is left (of the month, or of the day for
            daily_credit_cap_exceeded).
        resets_at:
          type: string
          format: date-time
          description: >-
            credits_exhausted and daily_credit_cap_exceeded: when the limit
            resets.
      required:
        - type
        - title
        - status
        - code
        - detail
        - suggestion
        - retryable
        - request_id
    WriteProblem:
      type: object
      description: >-
        RFC 9457 problem details. A refusal of a write Alura recorded carries
        its `change_id`, and by code `budget`, `reason`, `changed`, `missing`,
        `reconnect_url` or `missing_scopes`.
      properties:
        type:
          type: string
          format: uri
        title:
          type: string
        status:
          type: integer
        code:
          type: string
          description: A code from the error catalog; new codes may be added.
          x-extensible-enum:
            - invalid_request
            - unknown_parameter
            - invalid_cursor
            - cursor_window_exceeded
            - invalid_reference
            - id_type_mismatch
            - invalid_keyword
            - shop_id_required
            - listing_not_publishable
            - sales_window_not_covered
            - range_too_long_for_interval
            - target_not_available
            - unauthorized
            - credits_exhausted
            - plan_required
            - insufficient_scope
            - workspace_required
            - workspace_locked
            - your_shop_unavailable
            - writes_suspended
            - browser_refused
            - live_data_not_enabled
            - send_not_enabled
            - attachments_not_enabled
            - self_approval
            - role_required
            - impersonation_refused
            - recent_sign_in_required
            - etsy_scope_required
            - etsy_partner_required
            - not_found
            - not_collected
            - not_found_on_etsy
            - shop_opted_out
            - method_not_allowed
            - conflict
            - settings_conflict
            - settings_unreadable
            - optimize_settings_required
            - optimize_plan_changed
            - optimize_run_applied
            - optimize_run_applying
            - optimize_run_too_large
            - optimize_nothing_to_apply
            - optimize_nothing_to_revert
            - optimize_shop_busy
            - runs_unreadable
            - run_not_resumable
            - suggestion_not_pending
            - draft_sent
            - draft_dismissed
            - draft_sending
            - conversation_changed
            - key_limit_reached
            - etsy_not_logged_in
            - etsy_shop_mismatch
            - holder_offline
            - login_expired
            - never_connected
            - etsy_refused
            - extension_update_required
            - attachment_used
            - attachment_expired
            - attachment_unavailable
            - saved_shops_off
            - review_already_replied
            - insights_search_unavailable
            - reconnect_required
            - settings_not_fetched
            - listing_busy
            - settings_busy
            - shop_create_busy
            - idempotency_partial_unverifiable
            - listing_has_variations
            - listing_sold_out
            - changed_since
            - change_not_revertable
            - media_changed
            - text_changed
            - inventory_changed
            - base_unverifiable
            - listing_in_ab_test
            - activation_skipped
            - idempotency_processing
            - confirmation_required
            - test_shop_active_cap
            - write_outcome_unknown
            - margin_required
            - unprocessable
            - knowledge_limit_reached
            - status_required
            - listing_removed_on_etsy
            - optimize_run_expired
            - endpoint_removed
            - rate_limited
            - throttled
            - daily_credit_cap_exceeded
            - credits_reserved
            - fetch_limit_reached
            - write_rate_limited
            - sync_cooldown
            - shop_write_budget_exhausted
            - live_rate_limited
            - etsy_rate_limited
            - internal_error
            - write_misconfigured
            - etsy_changed
            - upstream_unavailable
            - extension_offline
            - etsy_unavailable
            - etsy_challenge
            - live_data_paused
            - live_data_unavailable
            - credits_unavailable
            - service_unavailable
            - fetch_unavailable
            - create_lock_unavailable
            - writes_paused
            - etsy_capacity
            - upstream_timeout
        detail:
          type: string
        suggestion:
          type: string
        retryable:
          type: boolean
        request_id:
          type: string
        upgrade_url:
          type: string
          format: uri
          description: 'credits_exhausted and plan_required: where to upgrade the plan.'
        credits_needed:
          type: integer
          description: 'API credit refusals: what the call needed.'
        credits_remaining:
          type: integer
          description: >-
            API credit refusals: what is left (of the month, or of the day for
            daily_credit_cap_exceeded).
        resets_at:
          type: string
          format: date-time
          description: >-
            credits_exhausted and daily_credit_cap_exceeded: when the limit
            resets.
        change_id:
          type: string
          description: >-
            The recorded write this refusal answers, as its change (`chn_...`):
            read it (`GET /v1/workspace/changes/{id}`) before writing again.
        budget:
          type: string
          description: >-
            `shop_write_budget_exhausted`: which of the shop's Etsy write
            budgets ran out (`creates`, `activations`, `etsy_calls`).
        reason:
          description: >-
            Why, as an identifier: for `change_not_revertable`, why the revert
            was refused; null when none was named.
          type:
            - string
            - 'null'
        changed:
          anyOf:
            - type: array
              items:
                type: string
            - type: 'null'
          description: >-
            `changed_since`: the fields that changed on Etsy since the change;
            `media_changed`: what differs from `images_expected`,
            `videos_expected` or `files_expected`, as `images.unexpected.<id>`
            (on Etsy, not expected) or `images.missing.<id>` (expected, no
            longer on Etsy); null when none was named.
        missing:
          anyOf:
            - type: array
              items:
                type: string
            - type: 'null'
          description: >-
            `listing_not_publishable`: what Etsy said the listing lacks to
            publish; null when it named none.
        reconnect_url:
          type: string
          description: >-
            `reconnect_required` and `etsy_scope_required`: where the shop is
            reconnected in Alura.
        missing_scopes:
          anyOf:
            - type: array
              items:
                type: string
            - type: 'null'
          description: >-
            `etsy_scope_required`: the Etsy scopes the shop's connection lacks;
            null when none was named.
      required:
        - type
        - title
        - status
        - code
        - detail
        - suggestion
        - retryable
        - request_id
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: 'An API key: `Authorization: Bearer alura_sk_...`.'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.