---
title: "Update a Campaign"
method: PATCH
path: "/campaigns/{campaign_id}"
tags: ["Campaigns"]
---

# Update a Campaign

`PATCH /campaigns/{campaign_id}`

Update a campaign's metadata.

## Path parameters

- `campaign_id` integer, required

## Query parameters

- `action` 'publish' | 'start' | 'pause' | 'resume' | 'unarchive'

## Request body

- CampaignUpdate
  - `changes` SharedCodeChange[] — A list of changes to apply to the Campaign
    - `async` boolean — Indicates whether or not to execute the change asyncronously. If true, src will be returned in the response. Otherwise, it will be not included.
    - `dependencies` string[] — A list of dependent change IDs that must happen before this change
    - `id` string, uuid — The ID of the change
    - `name` string — Name of the change
    - `selector` string — CSS selector to determine where changes are applied. Required for changes of type 'custom_css'.
    - `src` string — The path to the change payload on the CDN. Only present if 'async' is True.
    - `type` 'custom_code' | 'custom_css', required — The type of this change.
    - `value` string, required — The value for the change can be JavaScript or CSS as a string.
  - `description` string — The description or goal for a Campaign
  - `experiment_priorities` array[] — A list of lists of Experiment IDs that indicate the relative priority of how to show those Experiments in the context of the Campaign. Each list inside of the list represents a group of Experiments of equal priority where groups that appear earlier in the list are of higher priority to be shown.
    - integer[]
  - `for_journey` boolean — Whether the Campaign has been part of journey or not
  - `holdback` integer — Percentage of visitors to exclude from personalization, measured in basis points. 100 basis points = 1% traffic. For example, a value of 500 would mean that 95% of visitors will see a personalized experience and 5% will see the holdback.
  - `journey_id` string — The journey this campaign is associated with, or null if not set
  - `metrics` Metric[] — An ordered list of metrics to track for the Campaign
    - `aggregator` 'unique' | 'count' | 'sum' | 'bounce' | 'exit' | 'ratio' — The aggregation function for the numerator of the metric. 'unique' measures the number of unique visitors/sessions that include the specified Event. 'count' measures the total number of occurrences of Event for the scope (visitor/session). 'sum' is the sum of the 'field' value
    - `display_title` string — Display title for the metric
    - `event_id` integer, nullable — The ID for the Event to select data from. Omitted for global metrics that are not relative to a specific Event, i.e. "overall revenue"
    - `event_properties` MetricEventProperties — The conditions used to filter the metric on specific event property values.
      - `filter` MetricFilter — The set of event property conditions a conversion must match to be counted toward the metric.
        - `combine_operator` 'and' | 'or' — Determines whether all conditions (and) or any condition (or) must be met.
        - `conditions` MetricFilterCondition[]
          - `name` string — The name of the event property to match to.
          - `operator` 'equal_to' | 'not_equal_to' | 'greater_than' | 'greater_than_or_equal_to' | 'less_than' | 'less_than_or_equal_to' | 'contains' | 'does_not_contain' — The type of match to be performed. equal_to and not_equal_to are available for all property types. greater_than, greater_than_or_equal_to, less_than, and less_than_or_equal_to are only available for properties with type number. contains and does_not_contain are only available for properties with type string.
          - `type` 'boolean' | 'number' | 'string' — The data type of the event property.
          - `value` string — The value the conversion's property should match, according to the operator.
    - `field` 'revenue' | 'value' — The field to aggregate for the numerator of the metric. Required when 'aggregator' = 'sum', otherwise omitted
    - `metrics` CompoundSubMetric[] — A list of all metrics that will be used in the calculation of a ratio metric.
      - `aggregator` 'unique' | 'count' | 'sum' — The aggregation function for the numerator of the metric. 'unique' measures the number of unique visitors/sessions that include the specified Event. 'count' measures the total number of occurrences of Event for the scope (visitor/session). 'sum' is the sum of the 'field' value.
      - `event_id` integer, nullable — The ID for the Event to select data from.
      - `event_type` 'custom' | 'click' | 'pageview' — The type of this Event.
      - `field` 'revenue' | 'value', nullable — The field to aggregate for the numerator of the metric. Required when 'aggregator' = 'sum', otherwise omitted.
      - `scope` 'session' | 'visitor' | 'event' — Specifies how Events should be grouped. Can also be thought of as the denominator of the metric. 'session' divides by the number of sessions. "Influenced sessions", or sessions that do not contain a decision Event but carry a decision from a previous session are not included in counts for numerator or denominator. 'visitor' divides by the number of visitors. 'event' divides by the total occurrences (impressions) of the specified Event.
    - `scope` 'session' | 'visitor' | 'event' — Specifies how Events should be grouped together. Can also be thought of as the denonimator of the metric. 'session' divides by the number of sessions. "Influenced sessions", or sessions that do not contain a decision Event but carry a decision from a previous session are not included in counts for numerator or denominator. 'visitor' divides by the number of visitors. 'event' divides by the total occurrences (impressions) of the specified Event
    - `time_window` string — The maximum amount of time a numerator event can differ from a denominator event in order to be included in a ratio metric. This can be an integer, or an integer followed by a letter denoting the unit of time (d = days, h = hours, m = minutes). If no unit of time is supplied, hours is assumed. If no value is supplied, a time window of 48 hours is assumed.
    - `winning_direction` 'increasing' | 'decreasing' — The winning direction of this metric
  - `name` string — The name of the Campaign
  - `page_ids` integer[] — A list of Page IDs used in the Campaign. Only `url_targeting` or `page_ids` can be used when updating a Campaign, but not both.
  - `url_targeting` URLTargeting
    - `activation_code` string — Stringified Javascript function that determines when the Page is activated. Only required when activation_type is 'polling' or 'callback'.
    - `activation_type` 'immediate' | 'manual' | 'polling' | 'callback' | 'dom_changed' | 'url_changed' — How this page is activated. See the full documentation on the Page object.
    - `conditions` string — Conditions to activate the experiment; our knowledge base article on Activation Types is the best guide for how to set up this data.
    - `edit_url` string, required — URL to load in the editor for this page
    - `key` string — Unique string identifier for this Page within the Project
    - `page_id` integer — The unique identifier of the Page that represents the experiment or campaign's URL Targeting.

## Response `200`

Return the updated Campaign

- Campaign
  - `archived` boolean — Whether the Campaign has been archived
  - `changes` SharedCodeChange[] — A list of changes to apply to the Campaign. This corresponds to the Campaign's Shared Code in the application. Only supports 'custom_css' or 'custom_code' type changes.
    - `async` boolean — Indicates whether or not to execute the change asyncronously. If true, src will be returned in the response. Otherwise, it will be not included.
    - `dependencies` string[] — A list of dependent change IDs that must happen before this change
    - `id` string, uuid — The ID of the change
    - `name` string — Name of the change
    - `selector` string — CSS selector to determine where changes are applied. Required for changes of type 'custom_css'.
    - `src` string — The path to the change payload on the CDN. Only present if 'async' is True.
    - `type` 'custom_code' | 'custom_css', required — The type of this change.
    - `value` string, required — The value for the change can be JavaScript or CSS as a string.
  - `created` string, date-time — The time the Campaign was initially created
  - `custom_field_values` object — Map of custom field `api_name` to value for this Campaign. Keys correspond to the `api_name` of a custom field definition for the Project, and values are typed according to that definition's `field_type`. Returns an empty object when no values are set.
  - `description` string — The description or goal for a Campaign
  - `earliest` string, date-time — The first time the Campaign was activated
  - `experiment_priorities` array[] — A list of lists of Experiment IDs that indicate the relative priority of how to show those Experiments in the context of the Campaign. Each list inside of the list represents a group of Experiments of equal priority where groups that appear earlier in the list are of higher priority to be shown.
    - integer[]
  - `for_journey` boolean — Whether the Campaign has been part of journey or not
  - `holdback` integer — Percentage of visitors to exclude from personalization, measured in basis points. 100 basis points = 1% traffic. For example, a value of 500 would mean that 95% of visitors will see a personalized experience and 5% will see the holdback.
  - `id` integer — The unique identifier for the Campaign
  - `journey_id` string — The journey this campaign is associated with, or null if not set
  - `last_modified` string, date-time — The last time the Campaign was modified
  - `latest` string, date-time — The last time the Campaign was paused (not present if the Campaign still running)
  - `metrics` Metric[] — An ordered list of metrics to track for the Campaign
    - `aggregator` 'unique' | 'count' | 'sum' | 'bounce' | 'exit' | 'ratio' — The aggregation function for the numerator of the metric. 'unique' measures the number of unique visitors/sessions that include the specified Event. 'count' measures the total number of occurrences of Event for the scope (visitor/session). 'sum' is the sum of the 'field' value
    - `display_title` string — Display title for the metric
    - `event_id` integer, nullable — The ID for the Event to select data from. Omitted for global metrics that are not relative to a specific Event, i.e. "overall revenue"
    - `event_properties` MetricEventProperties — The conditions used to filter the metric on specific event property values.
      - `filter` MetricFilter — The set of event property conditions a conversion must match to be counted toward the metric.
        - `combine_operator` 'and' | 'or' — Determines whether all conditions (and) or any condition (or) must be met.
        - `conditions` MetricFilterCondition[]
          - `name` string — The name of the event property to match to.
          - `operator` 'equal_to' | 'not_equal_to' | 'greater_than' | 'greater_than_or_equal_to' | 'less_than' | 'less_than_or_equal_to' | 'contains' | 'does_not_contain' — The type of match to be performed. equal_to and not_equal_to are available for all property types. greater_than, greater_than_or_equal_to, less_than, and less_than_or_equal_to are only available for properties with type number. contains and does_not_contain are only available for properties with type string.
          - `type` 'boolean' | 'number' | 'string' — The data type of the event property.
          - `value` string — The value the conversion's property should match, according to the operator.
    - `field` 'revenue' | 'value' — The field to aggregate for the numerator of the metric. Required when 'aggregator' = 'sum', otherwise omitted
    - `metrics` CompoundSubMetric[] — A list of all metrics that will be used in the calculation of a ratio metric.
      - `aggregator` 'unique' | 'count' | 'sum' — The aggregation function for the numerator of the metric. 'unique' measures the number of unique visitors/sessions that include the specified Event. 'count' measures the total number of occurrences of Event for the scope (visitor/session). 'sum' is the sum of the 'field' value.
      - `event_id` integer, nullable — The ID for the Event to select data from.
      - `event_type` 'custom' | 'click' | 'pageview' — The type of this Event.
      - `field` 'revenue' | 'value', nullable — The field to aggregate for the numerator of the metric. Required when 'aggregator' = 'sum', otherwise omitted.
      - `scope` 'session' | 'visitor' | 'event' — Specifies how Events should be grouped. Can also be thought of as the denominator of the metric. 'session' divides by the number of sessions. "Influenced sessions", or sessions that do not contain a decision Event but carry a decision from a previous session are not included in counts for numerator or denominator. 'visitor' divides by the number of visitors. 'event' divides by the total occurrences (impressions) of the specified Event.
    - `scope` 'session' | 'visitor' | 'event' — Specifies how Events should be grouped together. Can also be thought of as the denonimator of the metric. 'session' divides by the number of sessions. "Influenced sessions", or sessions that do not contain a decision Event but carry a decision from a previous session are not included in counts for numerator or denominator. 'visitor' divides by the number of visitors. 'event' divides by the total occurrences (impressions) of the specified Event
    - `time_window` string — The maximum amount of time a numerator event can differ from a denominator event in order to be included in a ratio metric. This can be an integer, or an integer followed by a letter denoting the unit of time (d = days, h = hours, m = minutes). If no unit of time is supplied, hours is assumed. If no value is supplied, a time window of 48 hours is assumed.
    - `winning_direction` 'increasing' | 'decreasing' — The winning direction of this metric
  - `name` string — The name of the Campaign
  - `page_ids` integer[] — A list of Page IDs used in the Campaign
  - `project_id` integer, required — The Project ID the Campaign is in
  - `status` 'not_started' | 'running' | 'paused' | 'archived' — Current state of the Campaign. not_started means the Campaign has never been published to the world. running means the Campaign is currently live to the world. paused means the Campaign has been published, but is currently not running. archived means the Campaign is paused and not visible in the web UI.
  - `type` 'personalization' | 'other' — Indicates the type of this campaign. Campaigns created or fetched via the API should currently all have a type of `personalization`, but if you get a campaign_id for an experiment and look it up, you may get an `other` value.
  - `url_targeting` URLTargeting
    - `activation_code` string — Stringified Javascript function that determines when the Page is activated. Only required when activation_type is 'polling' or 'callback'.
    - `activation_type` 'immediate' | 'manual' | 'polling' | 'callback' | 'dom_changed' | 'url_changed' — How this page is activated. See the full documentation on the Page object.
    - `conditions` string — Conditions to activate the experiment; our knowledge base article on Activation Types is the best guide for how to set up this data.
    - `edit_url` string, required — URL to load in the editor for this page
    - `key` string — Unique string identifier for this Page within the Project
    - `page_id` integer — The unique identifier of the Page that represents the experiment or campaign's URL Targeting.

## Other responses

- `400` — Invalid ID supplied
- `401` — Invalid credentials
- `403` — You do not have permission to edit the specified Campaign
- `404` — Campaign not found
- `default` — Unexpected error

---

[API](https://skmtc.dev/optimizely/apis/optimizely-api.md) · [All operations](https://skmtc.dev/optimizely/apis/optimizely-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/optimizely/optimizely-api/revisions/5151fe6a2297/schema)
