> ## 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.

# Save optimizer settings

> Replace one shop's Etsy Ads optimizer settings with a whole new settings object. Alura's Etsy Ads page uses the same settings.

**Cost:** Free.

> [!NOTE]
>
> Works while the extension is offline: this call uses only what Alura stores. See [Chrome extension](https://docs.alura.io/api-reference/chrome-extension.md).

```bash
curl -X PUT "https://api.alura.io/v1/workspace/ads/optimize/settings?shop_id=22841907" \
  -H "Authorization: Bearer $ALURA_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{"version": 3, "settings": {"schemaVersion": 1, "economics": {"marginPct": 30}, "listings": {"selectedStrategyId": "budget-saver", "customStrategies": []}, "searchTerms": {"selectedStrategyId": "keyword-saver", "customStrategies": []}}}'
```

Needs the `ads:write` scope and the **Etsy Ads** workspace permission. A shop outside the workspace answers `404`. Send `Idempotency-Key` to retry safely.

## Save without overwriting

These are the settings of Alura's Etsy Ads optimizer. A change here is what Alura's Etsy Ads page uses, and a change there shows here.

`settings` replaces the whole object, so [read the settings](https://docs.alura.io/api-reference/workspace/ads/optimize/settings/get.md) first and send back the `version` you read, `0` when none were saved.

| Answer | Means |
| - | - |
| `409` [`settings_conflict`](https://docs.alura.io/errors/settings_conflict) | The settings were saved since you read them. The answer holds what is stored now, and nothing is saved. |
| `409` [`settings_unreadable`](https://docs.alura.io/errors/settings_unreadable) | Alura can't read what is stored. It is never overwritten. |


## OpenAPI

````yaml /openapi.json put /v1/workspace/ads/optimize/settings
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/settings:
    put:
      summary: Save optimizer settings
      description: >-
        Replaces one shop's Etsy Ads optimizer settings with `settings`, the
        whole object. These are the settings of Alura's Etsy Ads optimizer: a
        change here is what Alura's Etsy Ads page uses, and a change there shows
        here. Send the `version` you read (0 when none were saved): if the
        settings were saved since, the answer is 409 `settings_conflict` with
        what is stored now, and nothing is saved. Stored settings Alura cannot
        read are 409 `settings_unreadable` and are never overwritten. A shop
        outside the workspace is 404. Over MCP the save needs the user's
        confirmation first. Needs the `ads:write` scope and the Etsy Ads
        permission. Retry safely with `Idempotency-Key`. Free.


        Cost: free.
      operationId: workspace.ads.optimize.settings.put
      parameters:
        - name: shop_id
          in: query
          required: false
          description: >-
            The Etsy shop ID of one of the workspace's connected shops; optional
            when the workspace has one. A shop outside the workspace is 404.
          schema:
            description: >-
              The Etsy shop ID of one of the workspace's connected shops;
              optional when the workspace has one. A shop outside the workspace
              is 404.
            type: string
            pattern: ^[0-9]{1,20}$
            example: '22841907'
        - name: Idempotency-Key
          in: header
          required: false
          description: >-
            Makes a retry safe: the same key with the same request within 24
            hours returns the first result (with `Idempotent-Replayed: true`)
            instead of writing again. The same key with a different request is a
            409 `conflict`; while the first request still runs, 409
            `idempotency_processing`.
          schema:
            type: string
            minLength: 1
            maxLength: 255
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                settings:
                  description: >-
                    The whole settings object to save (OptimizerSettings v1),
                    snake_case as the GET answers it (camelCase keys are still
                    taken, deprecated); it replaces what is stored.
                  type: object
                  properties:
                    schema_version:
                      type: number
                      const: 1
                    economics:
                      type: object
                      properties:
                        margin_pct:
                          anyOf:
                            - type: number
                              minimum: 0
                              maximum: 95
                            - type: 'null'
                        digital_margin_pct:
                          type: number
                          minimum: 0
                          maximum: 95
                        section_margins:
                          maxItems: 500
                          type: array
                          items:
                            type: object
                            properties:
                              section_id:
                                type: integer
                                exclusiveMinimum: 0
                              title:
                                type: string
                                maxLength: 200
                              margin_percent:
                                type: number
                                minimum: 0
                                maximum: 95
                            required:
                              - section_id
                              - title
                              - margin_percent
                            additionalProperties: false
                        processing_rate_pct:
                          type: number
                          minimum: 0
                          maximum: 100
                        processing_fixed_cents:
                          type: integer
                          minimum: 0
                        regulatory_rate_pct:
                          type: number
                          minimum: 0
                          maximum: 100
                        listing_fee_cents:
                          type: integer
                          minimum: 0
                        fee_vat_pct:
                          type: number
                          minimum: 0
                          maximum: 100
                        conversion_fee_pct:
                          type: number
                          minimum: 0
                          maximum: 100
                      required:
                        - margin_pct
                      additionalProperties: false
                    listings:
                      type: object
                      properties:
                        selected_strategy_id:
                          type: string
                          minLength: 1
                          maxLength: 80
                        custom_strategies:
                          maxItems: 50
                          type: array
                          items:
                            type: object
                            properties:
                              id:
                                type: string
                                minLength: 1
                                maxLength: 80
                              name:
                                type: string
                                minLength: 1
                                maxLength: 200
                              description:
                                type: string
                                maxLength: 1000
                              mode:
                                type: string
                                enum:
                                  - listings
                                  - keywords
                              period:
                                type: string
                                enum:
                                  - all_time
                                  - last_12_months
                                  - last_3_months
                                  - last_30_days
                              action:
                                type: string
                                enum:
                                  - pause
                                  - lower_click_cost
                              rule_groups:
                                maxItems: 20
                                type: array
                                items:
                                  type: object
                                  properties:
                                    id:
                                      type: string
                                      minLength: 1
                                      maxLength: 80
                                    conditions:
                                      maxItems: 20
                                      type: array
                                      items:
                                        type: object
                                        properties:
                                          factor:
                                            type: string
                                            enum:
                                              - spend
                                              - roas
                                              - orders
                                              - revenue
                                              - clicks
                                              - views
                                              - ctr
                                          op:
                                            type: string
                                            enum:
                                              - gt
                                              - lt
                                              - eq
                                          value:
                                            type: number
                                          relative_to:
                                            type: string
                                            const: break_even
                                          margin_pct:
                                            type: number
                                            minimum: 0
                                            maximum: 95
                                          unconverted:
                                            type: string
                                            const: USD
                                        required:
                                          - factor
                                          - op
                                          - value
                                        additionalProperties: false
                                  required:
                                    - id
                                    - conditions
                                  additionalProperties: false
                              exclusions:
                                type: object
                                properties:
                                  listing_ids:
                                    maxItems: 5000
                                    type: array
                                    items:
                                      type: integer
                                      exclusiveMinimum: 0
                                  section_ids:
                                    maxItems: 500
                                    type: array
                                    items:
                                      type: integer
                                      exclusiveMinimum: 0
                                  min_price:
                                    type: number
                                    minimum: 0
                                  max_price:
                                    type: number
                                    minimum: 0
                                  skip_digital:
                                    type: boolean
                                required:
                                  - listing_ids
                                  - section_ids
                                additionalProperties: false
                              overrides:
                                maxItems: 20
                                type: array
                                items:
                                  type: object
                                  properties:
                                    id:
                                      type: string
                                      minLength: 1
                                      maxLength: 80
                                    label:
                                      type: string
                                      maxLength: 200
                                    match:
                                      type: object
                                      properties:
                                        section_ids:
                                          maxItems: 500
                                          type: array
                                          items:
                                            type: integer
                                            exclusiveMinimum: 0
                                        listing_ids:
                                          maxItems: 5000
                                          type: array
                                          items:
                                            type: integer
                                            exclusiveMinimum: 0
                                        is_digital:
                                          type: boolean
                                        price_gte:
                                          type: number
                                          minimum: 0
                                        price_lte:
                                          type: number
                                          minimum: 0
                                      additionalProperties: false
                                    rule_groups:
                                      maxItems: 20
                                      type: array
                                      items:
                                        type: object
                                        properties:
                                          id:
                                            type: string
                                            minLength: 1
                                            maxLength: 80
                                          conditions:
                                            maxItems: 20
                                            type: array
                                            items:
                                              type: object
                                              properties:
                                                factor:
                                                  type: string
                                                  enum:
                                                    - spend
                                                    - roas
                                                    - orders
                                                    - revenue
                                                    - clicks
                                                    - views
                                                    - ctr
                                                op:
                                                  type: string
                                                  enum:
                                                    - gt
                                                    - lt
                                                    - eq
                                                value:
                                                  type: number
                                                relative_to:
                                                  type: string
                                                  const: break_even
                                                margin_pct:
                                                  type: number
                                                  minimum: 0
                                                  maximum: 95
                                                unconverted:
                                                  type: string
                                                  const: USD
                                              required:
                                                - factor
                                                - op
                                                - value
                                              additionalProperties: false
                                        required:
                                          - id
                                          - conditions
                                        additionalProperties: false
                                    action:
                                      type: string
                                      enum:
                                        - pause
                                        - lower_click_cost
                                  required:
                                    - id
                                    - label
                                    - match
                                    - rule_groups
                                  additionalProperties: false
                              guardrails:
                                type: object
                                properties:
                                  min_clicks:
                                    type: integer
                                    minimum: 0
                                  rule_of_three:
                                    type: boolean
                                  grace_days:
                                    type: integer
                                    minimum: 0
                                  max_actions_per_run:
                                    type: integer
                                    minimum: 1
                                  keyword_listing_cap:
                                    type: integer
                                    minimum: 1
                                additionalProperties: false
                              is_custom:
                                type: boolean
                              model_version:
                                type: integer
                                exclusiveMinimum: 0
                            required:
                              - id
                              - name
                              - period
                              - action
                              - rule_groups
                            additionalProperties: false
                        draft:
                          type: object
                          properties:
                            id:
                              type: string
                              minLength: 1
                              maxLength: 80
                            name:
                              type: string
                              minLength: 1
                              maxLength: 200
                            description:
                              type: string
                              maxLength: 1000
                            mode:
                              type: string
                              enum:
                                - listings
                                - keywords
                            period:
                              type: string
                              enum:
                                - all_time
                                - last_12_months
                                - last_3_months
                                - last_30_days
                            action:
                              type: string
                              enum:
                                - pause
                                - lower_click_cost
                            rule_groups:
                              maxItems: 20
                              type: array
                              items:
                                type: object
                                properties:
                                  id:
                                    type: string
                                    minLength: 1
                                    maxLength: 80
                                  conditions:
                                    maxItems: 20
                                    type: array
                                    items:
                                      type: object
                                      properties:
                                        factor:
                                          type: string
                                          enum:
                                            - spend
                                            - roas
                                            - orders
                                            - revenue
                                            - clicks
                                            - views
                                            - ctr
                                        op:
                                          type: string
                                          enum:
                                            - gt
                                            - lt
                                            - eq
                                        value:
                                          type: number
                                        relative_to:
                                          type: string
                                          const: break_even
                                        margin_pct:
                                          type: number
                                          minimum: 0
                                          maximum: 95
                                        unconverted:
                                          type: string
                                          const: USD
                                      required:
                                        - factor
                                        - op
                                        - value
                                      additionalProperties: false
                                required:
                                  - id
                                  - conditions
                                additionalProperties: false
                            exclusions:
                              type: object
                              properties:
                                listing_ids:
                                  maxItems: 5000
                                  type: array
                                  items:
                                    type: integer
                                    exclusiveMinimum: 0
                                section_ids:
                                  maxItems: 500
                                  type: array
                                  items:
                                    type: integer
                                    exclusiveMinimum: 0
                                min_price:
                                  type: number
                                  minimum: 0
                                max_price:
                                  type: number
                                  minimum: 0
                                skip_digital:
                                  type: boolean
                              required:
                                - listing_ids
                                - section_ids
                              additionalProperties: false
                            overrides:
                              maxItems: 20
                              type: array
                              items:
                                type: object
                                properties:
                                  id:
                                    type: string
                                    minLength: 1
                                    maxLength: 80
                                  label:
                                    type: string
                                    maxLength: 200
                                  match:
                                    type: object
                                    properties:
                                      section_ids:
                                        maxItems: 500
                                        type: array
                                        items:
                                          type: integer
                                          exclusiveMinimum: 0
                                      listing_ids:
                                        maxItems: 5000
                                        type: array
                                        items:
                                          type: integer
                                          exclusiveMinimum: 0
                                      is_digital:
                                        type: boolean
                                      price_gte:
                                        type: number
                                        minimum: 0
                                      price_lte:
                                        type: number
                                        minimum: 0
                                    additionalProperties: false
                                  rule_groups:
                                    maxItems: 20
                                    type: array
                                    items:
                                      type: object
                                      properties:
                                        id:
                                          type: string
                                          minLength: 1
                                          maxLength: 80
                                        conditions:
                                          maxItems: 20
                                          type: array
                                          items:
                                            type: object
                                            properties:
                                              factor:
                                                type: string
                                                enum:
                                                  - spend
                                                  - roas
                                                  - orders
                                                  - revenue
                                                  - clicks
                                                  - views
                                                  - ctr
                                              op:
                                                type: string
                                                enum:
                                                  - gt
                                                  - lt
                                                  - eq
                                              value:
                                                type: number
                                              relative_to:
                                                type: string
                                                const: break_even
                                              margin_pct:
                                                type: number
                                                minimum: 0
                                                maximum: 95
                                              unconverted:
                                                type: string
                                                const: USD
                                            required:
                                              - factor
                                              - op
                                              - value
                                            additionalProperties: false
                                      required:
                                        - id
                                        - conditions
                                      additionalProperties: false
                                  action:
                                    type: string
                                    enum:
                                      - pause
                                      - lower_click_cost
                                required:
                                  - id
                                  - label
                                  - match
                                  - rule_groups
                                additionalProperties: false
                            guardrails:
                              type: object
                              properties:
                                min_clicks:
                                  type: integer
                                  minimum: 0
                                rule_of_three:
                                  type: boolean
                                grace_days:
                                  type: integer
                                  minimum: 0
                                max_actions_per_run:
                                  type: integer
                                  minimum: 1
                                keyword_listing_cap:
                                  type: integer
                                  minimum: 1
                              additionalProperties: false
                            is_custom:
                              type: boolean
                            model_version:
                              type: integer
                              exclusiveMinimum: 0
                          required:
                            - id
                            - name
                            - period
                            - action
                            - rule_groups
                          additionalProperties: false
                      required:
                        - selected_strategy_id
                        - custom_strategies
                      additionalProperties: false
                    search_terms:
                      type: object
                      properties:
                        selected_strategy_id:
                          type: string
                          minLength: 1
                          maxLength: 80
                        custom_strategies:
                          maxItems: 50
                          type: array
                          items:
                            type: object
                            properties:
                              id:
                                type: string
                                minLength: 1
                                maxLength: 80
                              name:
                                type: string
                                minLength: 1
                                maxLength: 200
                              description:
                                type: string
                                maxLength: 1000
                              mode:
                                type: string
                                enum:
                                  - listings
                                  - keywords
                              period:
                                type: string
                                enum:
                                  - all_time
                                  - last_12_months
                                  - last_3_months
                                  - last_30_days
                              action:
                                type: string
                                enum:
                                  - pause
                                  - lower_click_cost
                              rule_groups:
                                maxItems: 20
                                type: array
                                items:
                                  type: object
                                  properties:
                                    id:
                                      type: string
                                      minLength: 1
                                      maxLength: 80
                                    conditions:
                                      maxItems: 20
                                      type: array
                                      items:
                                        type: object
                                        properties:
                                          factor:
                                            type: string
                                            enum:
                                              - spend
                                              - roas
                                              - orders
                                              - revenue
                                              - clicks
                                              - views
                                              - ctr
                                          op:
                                            type: string
                                            enum:
                                              - gt
                                              - lt
                                              - eq
                                          value:
                                            type: number
                                          relative_to:
                                            type: string
                                            const: break_even
                                          margin_pct:
                                            type: number
                                            minimum: 0
                                            maximum: 95
                                          unconverted:
                                            type: string
                                            const: USD
                                        required:
                                          - factor
                                          - op
                                          - value
                                        additionalProperties: false
                                  required:
                                    - id
                                    - conditions
                                  additionalProperties: false
                              exclusions:
                                type: object
                                properties:
                                  listing_ids:
                                    maxItems: 5000
                                    type: array
                                    items:
                                      type: integer
                                      exclusiveMinimum: 0
                                  section_ids:
                                    maxItems: 500
                                    type: array
                                    items:
                                      type: integer
                                      exclusiveMinimum: 0
                                  min_price:
                                    type: number
                                    minimum: 0
                                  max_price:
                                    type: number
                                    minimum: 0
                                  skip_digital:
                                    type: boolean
                                required:
                                  - listing_ids
                                  - section_ids
                                additionalProperties: false
                              overrides:
                                maxItems: 20
                                type: array
                                items:
                                  type: object
                                  properties:
                                    id:
                                      type: string
                                      minLength: 1
                                      maxLength: 80
                                    label:
                                      type: string
                                      maxLength: 200
                                    match:
                                      type: object
                                      properties:
                                        section_ids:
                                          maxItems: 500
                                          type: array
                                          items:
                                            type: integer
                                            exclusiveMinimum: 0
                                        listing_ids:
                                          maxItems: 5000
                                          type: array
                                          items:
                                            type: integer
                                            exclusiveMinimum: 0
                                        is_digital:
                                          type: boolean
                                        price_gte:
                                          type: number
                                          minimum: 0
                                        price_lte:
                                          type: number
                                          minimum: 0
                                      additionalProperties: false
                                    rule_groups:
                                      maxItems: 20
                                      type: array
                                      items:
                                        type: object
                                        properties:
                                          id:
                                            type: string
                                            minLength: 1
                                            maxLength: 80
                                          conditions:
                                            maxItems: 20
                                            type: array
                                            items:
                                              type: object
                                              properties:
                                                factor:
                                                  type: string
                                                  enum:
                                                    - spend
                                                    - roas
                                                    - orders
                                                    - revenue
                                                    - clicks
                                                    - views
                                                    - ctr
                                                op:
                                                  type: string
                                                  enum:
                                                    - gt
                                                    - lt
                                                    - eq
                                                value:
                                                  type: number
                                                relative_to:
                                                  type: string
                                                  const: break_even
                                                margin_pct:
                                                  type: number
                                                  minimum: 0
                                                  maximum: 95
                                                unconverted:
                                                  type: string
                                                  const: USD
                                              required:
                                                - factor
                                                - op
                                                - value
                                              additionalProperties: false
                                        required:
                                          - id
                                          - conditions
                                        additionalProperties: false
                                    action:
                                      type: string
                                      enum:
                                        - pause
                                        - lower_click_cost
                                  required:
                                    - id
                                    - label
                                    - match
                                    - rule_groups
                                  additionalProperties: false
                              guardrails:
                                type: object
                                properties:
                                  min_clicks:
                                    type: integer
                                    minimum: 0
                                  rule_of_three:
                                    type: boolean
                                  grace_days:
                                    type: integer
                                    minimum: 0
                                  max_actions_per_run:
                                    type: integer
                                    minimum: 1
                                  keyword_listing_cap:
                                    type: integer
                                    minimum: 1
                                additionalProperties: false
                              is_custom:
                                type: boolean
                              model_version:
                                type: integer
                                exclusiveMinimum: 0
                            required:
                              - id
                              - name
                              - period
                              - action
                              - rule_groups
                            additionalProperties: false
                        draft:
                          type: object
                          properties:
                            id:
                              type: string
                              minLength: 1
                              maxLength: 80
                            name:
                              type: string
                              minLength: 1
                              maxLength: 200
                            description:
                              type: string
                              maxLength: 1000
                            mode:
                              type: string
                              enum:
                                - listings
                                - keywords
                            period:
                              type: string
                              enum:
                                - all_time
                                - last_12_months
                                - last_3_months
                                - last_30_days
                            action:
                              type: string
                              enum:
                                - pause
                                - lower_click_cost
                            rule_groups:
                              maxItems: 20
                              type: array
                              items:
                                type: object
                                properties:
                                  id:
                                    type: string
                                    minLength: 1
                                    maxLength: 80
                                  conditions:
                                    maxItems: 20
                                    type: array
                                    items:
                                      type: object
                                      properties:
                                        factor:
                                          type: string
                                          enum:
                                            - spend
                                            - roas
                                            - orders
                                            - revenue
                                            - clicks
                                            - views
                                            - ctr
                                        op:
                                          type: string
                                          enum:
                                            - gt
                                            - lt
                                            - eq
                                        value:
                                          type: number
                                        relative_to:
                                          type: string
                                          const: break_even
                                        margin_pct:
                                          type: number
                                          minimum: 0
                                          maximum: 95
                                        unconverted:
                                          type: string
                                          const: USD
                                      required:
                                        - factor
                                        - op
                                        - value
                                      additionalProperties: false
                                required:
                                  - id
                                  - conditions
                                additionalProperties: false
                            exclusions:
                              type: object
                              properties:
                                listing_ids:
                                  maxItems: 5000
                                  type: array
                                  items:
                                    type: integer
                                    exclusiveMinimum: 0
                                section_ids:
                                  maxItems: 500
                                  type: array
                                  items:
                                    type: integer
                                    exclusiveMinimum: 0
                                min_price:
                                  type: number
                                  minimum: 0
                                max_price:
                                  type: number
                                  minimum: 0
                                skip_digital:
                                  type: boolean
                              required:
                                - listing_ids
                                - section_ids
                              additionalProperties: false
                            overrides:
                              maxItems: 20
                              type: array
                              items:
                                type: object
                                properties:
                                  id:
                                    type: string
                                    minLength: 1
                                    maxLength: 80
                                  label:
                                    type: string
                                    maxLength: 200
                                  match:
                                    type: object
                                    properties:
                                      section_ids:
                                        maxItems: 500
                                        type: array
                                        items:
                                          type: integer
                                          exclusiveMinimum: 0
                                      listing_ids:
                                        maxItems: 5000
                                        type: array
                                        items:
                                          type: integer
                                          exclusiveMinimum: 0
                                      is_digital:
                                        type: boolean
                                      price_gte:
                                        type: number
                                        minimum: 0
                                      price_lte:
                                        type: number
                                        minimum: 0
                                    additionalProperties: false
                                  rule_groups:
                                    maxItems: 20
                                    type: array
                                    items:
                                      type: object
                                      properties:
                                        id:
                                          type: string
                                          minLength: 1
                                          maxLength: 80
                                        conditions:
                                          maxItems: 20
                                          type: array
                                          items:
                                            type: object
                                            properties:
                                              factor:
                                                type: string
                                                enum:
                                                  - spend
                                                  - roas
                                                  - orders
                                                  - revenue
                                                  - clicks
                                                  - views
                                                  - ctr
                                              op:
                                                type: string
                                                enum:
                                                  - gt
                                                  - lt
                                                  - eq
                                              value:
                                                type: number
                                              relative_to:
                                                type: string
                                                const: break_even
                                              margin_pct:
                                                type: number
                                                minimum: 0
                                                maximum: 95
                                              unconverted:
                                                type: string
                                                const: USD
                                            required:
                                              - factor
                                              - op
                                              - value
                                            additionalProperties: false
                                      required:
                                        - id
                                        - conditions
                                      additionalProperties: false
                                  action:
                                    type: string
                                    enum:
                                      - pause
                                      - lower_click_cost
                                required:
                                  - id
                                  - label
                                  - match
                                  - rule_groups
                                additionalProperties: false
                            guardrails:
                              type: object
                              properties:
                                min_clicks:
                                  type: integer
                                  minimum: 0
                                rule_of_three:
                                  type: boolean
                                grace_days:
                                  type: integer
                                  minimum: 0
                                max_actions_per_run:
                                  type: integer
                                  minimum: 1
                                keyword_listing_cap:
                                  type: integer
                                  minimum: 1
                              additionalProperties: false
                            is_custom:
                              type: boolean
                            model_version:
                              type: integer
                              exclusiveMinimum: 0
                          required:
                            - id
                            - name
                            - period
                            - action
                            - rule_groups
                          additionalProperties: false
                      required:
                        - selected_strategy_id
                        - custom_strategies
                      additionalProperties: false
                  required:
                    - schema_version
                    - economics
                    - listings
                    - search_terms
                  additionalProperties: false
                version:
                  type: integer
                  minimum: 0
                  maximum: 2147483646
                  description: >-
                    The `version` you read: 0 when none were saved. A different
                    stored version answers 409 `settings_conflict` with what is
                    stored, and nothing is saved.
              required:
                - version
              additionalProperties: false
            example:
              settings:
                schema_version: 1
                economics:
                  margin_pct: 30
                listings:
                  selected_strategy_id: my-rules
                  custom_strategies:
                    - id: my-rules
                      name: My rules
                      period: last_3_months
                      action: pause
                      rule_groups:
                        - id: group-1
                          conditions:
                            - factor: spend
                              op: gt
                              value: 15
                            - factor: roas
                              op: lt
                              value: 2
                      guardrails:
                        min_clicks: 10
                        max_actions_per_run: 25
                      is_custom: true
                search_terms:
                  selected_strategy_id: keyword-saver
                  custom_strategies: []
              version: 3
      responses:
        '200':
          description: OK
          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'
          content:
            application/json:
              schema:
                type: object
                properties:
                  object:
                    type: string
                    const: workspace.ads_optimizer_settings
                  shop_id:
                    type: string
                  settings:
                    anyOf:
                      - type: object
                        propertyNames:
                          type: string
                        additionalProperties: {}
                        description: >-
                          The optimizer settings as Alura's Etsy Ads page saves
                          them (OptimizerSettings v1, the PUT body's
                          `settings`), keys snake_case: `economics` (margins and
                          fee overrides), and for `listings` and `search_terms`
                          the selected strategy, the custom strategies and the
                          unsaved draft.
                      - type: 'null'
                    description: >-
                      The saved settings; null when the shop has none saved (a
                      preview then uses the default preset).
                  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.
                required:
                  - object
                  - shop_id
                  - settings
                  - version
                additionalProperties: false
              example:
                object: workspace.ads_optimizer_settings
                shop_id: '22841907'
                settings:
                  schema_version: 1
                  economics:
                    margin_pct: 30
                  listings:
                    selected_strategy_id: my-rules
                    custom_strategies:
                      - id: my-rules
                        name: My rules
                        period: last_3_months
                        action: pause
                        rule_groups:
                          - id: group-1
                            conditions:
                              - factor: spend
                                op: gt
                                value: 15
                              - factor: roas
                                op: lt
                                value: 2
                        guardrails:
                          min_clicks: 10
                          max_actions_per_run: 25
                        is_custom: true
                  search_terms:
                    selected_strategy_id: keyword-saver
                    custom_strategies: []
                version: 4
        '400':
          $ref: '#/components/responses/Problem400'
        '401':
          $ref: '#/components/responses/Problem401'
        '402':
          $ref: '#/components/responses/Problem402'
        '403':
          $ref: '#/components/responses/Problem403'
        '404':
          $ref: '#/components/responses/Problem404'
        '405':
          $ref: '#/components/responses/Problem405'
        '409':
          description: >-
            Error. `settings_conflict` carries `settings`, `version`.
            `settings_unreadable` carries `version`.
          content:
            application/problem+json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Problem'
                  - type: object
                    properties:
                      settings:
                        anyOf:
                          - type: object
                            propertyNames:
                              type: string
                            additionalProperties: {}
                            description: >-
                              The optimizer settings as Alura's Etsy Ads page
                              saves them (OptimizerSettings v1, the PUT body's
                              `settings`), keys snake_case: `economics` (margins
                              and fee overrides), and for `listings` and
                              `search_terms` the selected strategy, the custom
                              strategies and the unsaved draft.
                          - type: 'null'
                      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.
        '429':
          $ref: '#/components/responses/Problem429'
        '500':
          $ref: '#/components/responses/Problem500'
        '503':
          $ref: '#/components/responses/Problem503'
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >-
            curl -X PUT
            "https://api.alura.io/v1/workspace/ads/optimize/settings?shop_id=22841907"
            \
              -H "Authorization: Bearer $ALURA_API_KEY" \
              -H "Content-Type: application/json" \
              -H "Idempotency-Key: 5f0c8e2a-4b1d-4c3e-9a7f-2b5d6e8f0a1c" \
              -d '{"settings":{"schema_version":1,"economics":{"margin_pct":30},"listings":{"selected_strategy_id":"my-rules","custom_strategies":[{"id":"my-rules","name":"My rules","period":"last_3_months","action":"pause","rule_groups":[{"id":"group-1","conditions":[{"factor":"spend","op":"gt","value":15},{"factor":"roas","op":"lt","value":2}]}],"guardrails":{"min_clicks":10,"max_actions_per_run":25},"is_custom":true}]},"search_terms":{"selected_strategy_id":"keyword-saver","custom_strategies":[]}},"version":3}'
        - lang: typescript
          label: TypeScript
          source: >-
            const res = await
            fetch('https://api.alura.io/v1/workspace/ads/optimize/settings?shop_id=22841907',
            {
              method: 'PUT',
              headers: {
                Authorization: `Bearer ${process.env.ALURA_API_KEY}`,
                'Content-Type': 'application/json',
                'Idempotency-Key': '5f0c8e2a-4b1d-4c3e-9a7f-2b5d6e8f0a1c',
              },
              body: JSON.stringify({
                "settings": {
                  "schema_version": 1,
                  "economics": {
                    "margin_pct": 30
                  },
                  "listings": {
                    "selected_strategy_id": "my-rules",
                    "custom_strategies": [
                      {
                        "id": "my-rules",
                        "name": "My rules",
                        "period": "last_3_months",
                        "action": "pause",
                        "rule_groups": [
                          {
                            "id": "group-1",
                            "conditions": [
                              {
                                "factor": "spend",
                                "op": "gt",
                                "value": 15
                              },
                              {
                                "factor": "roas",
                                "op": "lt",
                                "value": 2
                              }
                            ]
                          }
                        ],
                        "guardrails": {
                          "min_clicks": 10,
                          "max_actions_per_run": 25
                        },
                        "is_custom": true
                      }
                    ]
                  },
                  "search_terms": {
                    "selected_strategy_id": "keyword-saver",
                    "custom_strategies": []
                  }
                },
                "version": 3
              }),
            });

            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/settings?shop_id=22841907",
                method="PUT",
                data=json.dumps({
                  "settings": {
                    "schema_version": 1,
                    "economics": {
                      "margin_pct": 30
                    },
                    "listings": {
                      "selected_strategy_id": "my-rules",
                      "custom_strategies": [
                        {
                          "id": "my-rules",
                          "name": "My rules",
                          "period": "last_3_months",
                          "action": "pause",
                          "rule_groups": [
                            {
                              "id": "group-1",
                              "conditions": [
                                {
                                  "factor": "spend",
                                  "op": "gt",
                                  "value": 15
                                },
                                {
                                  "factor": "roas",
                                  "op": "lt",
                                  "value": 2
                                }
                              ]
                            }
                          ],
                          "guardrails": {
                            "min_clicks": 10,
                            "max_actions_per_run": 25
                          },
                          "is_custom": true
                        }
                      ]
                    },
                    "search_terms": {
                      "selected_strategy_id": "keyword-saver",
                      "custom_strategies": []
                    }
                  },
                  "version": 3
                }).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:
    Problem400:
      description: Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: https://docs.alura.io/errors/invalid_request
            title: Invalid request
            status: 400
            code: invalid_request
            detail: Invalid request
            suggestion: Fix the request as the detail says, then send it again.
            retryable: false
            request_id: req_01JQ5W3H8M2N4P6R8T0V2X4Z6B
    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
    Problem402:
      description: Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: https://docs.alura.io/errors/credits_exhausted
            title: API credits exhausted
            status: 402
            code: credits_exhausted
            detail: API credits exhausted
            suggestion: Upgrade the plan or wait for the monthly reset.
            retryable: false
            request_id: req_01JQ5W3H8M2N4P6R8T0V2X4Z6B
    Problem403:
      description: Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: https://docs.alura.io/errors/plan_required
            title: Plan required
            status: 403
            code: plan_required
            detail: Plan required
            suggestion: Upgrade the workspace plan to use this operation.
            retryable: false
            request_id: req_01JQ5W3H8M2N4P6R8T0V2X4Z6B
    Problem404:
      description: Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: https://docs.alura.io/errors/not_found
            title: Not found
            status: 404
            code: not_found
            detail: Not found
            suggestion: Check the ID, or search for it first.
            retryable: false
            request_id: req_01JQ5W3H8M2N4P6R8T0V2X4Z6B
    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
    Problem429:
      description: Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: https://docs.alura.io/errors/rate_limited
            title: Rate limited
            status: 429
            code: rate_limited
            detail: Rate limited
            suggestion: Wait for Retry-After, then retry.
            retryable: true
            request_id: req_01JQ5W3H8M2N4P6R8T0V2X4Z6B
    Problem500:
      description: Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: https://docs.alura.io/errors/internal_error
            title: Internal error
            status: 500
            code: internal_error
            detail: Internal error
            suggestion: Retry; if it keeps failing, report the request_id.
            retryable: true
            request_id: req_01JQ5W3H8M2N4P6R8T0V2X4Z6B
    Problem503:
      description: Error
      content:
        application/problem+json:
          schema:
            $ref: '#/components/schemas/Problem'
          example:
            type: https://docs.alura.io/errors/base_unverifiable
            title: Base not verifiable
            status: 503
            code: base_unverifiable
            detail: Base not verifiable
            suggestion: >-
              Alura could not read from Etsy the text or inventory this write
              names a version of, so it could not check it, and nothing was
              written. Retry after Retry-After.
            retryable: true
            request_id: req_01JQ5W3H8M2N4P6R8T0V2X4Z6B
  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
  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.