# POST - Update campaign

The update endpoint allows you to update campaigns created from the API.

### Request structure

#### Route

The campaigns API exposes a POST endpoint at: `https://api.batch.com/1.1/BATCH_API_KEY/campaigns/update/CAMPAIGN_TOKEN`

Here are examples of valid cURL, PHP or Python requests syntax:

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST "https://api.batch.com/1.1/BATCH_API_KEY/campaigns/update/CAMPAIGN_TOKEN" \
-H "Content-Type: application/json" \
-H "X-Authorization: BATCH_REST_API_KEY" \
-d '{
	"name": "Updated Test Campaign Name",
	"live": true
}'
```

{% endtab %}

{% tab title="PHP" %}

```php
use GuzzleHttp\Client;
$client = new Client();
$response = $client->request("POST", "https://api.batch.com/1.1/BATCH_API_KEY/campaigns/update/CAMPAIGN_TOKEN", [
	"headers" => [
		"Content-Type" => "application/json",
		"X-Authorization" => "BATCH_REST_API_KEY"
	],
	"json" => [
		"name" => "Updated Test Campaign Name",
		"live" => true
	]
]);
```

{% endtab %}

{% tab title="Python" %}

```python
import requests, json
response = requests.request("POST", "https://api.batch.com/1.1/BATCH_API_KEY/campaigns/update/CAMPAIGN_TOKEN",
	headers={
		'Content-Type': 'application/json'
		'X-Authorization': 'BATCH_REST_API_KEY'
	},
	data=json.dumps({
		'name': 'Updated Test Campaign Name',
		'live': True
	})
)
```

{% endtab %}
{% endtabs %}

The `BATCH_API_KEY` value is either your **Live**, **Dev** or **SDK** Batch API key from the settings page of your app within the dashboard *(Settings → General)*.

The `CAMPAIGN_TOKEN` value is the token you receive when you [successfully create](https://doc.batch.com/developer/api/mep/campaigns/create) a push campaign using the API.

#### Headers

In order to authenticate with the API, you need to provide your **company REST API Key** as the value of the `X-Authorization` header. You can find it in ⚙ Settings → General.

#### Post data

The body of the request must contain a [valid JSON payload](https://doc.batch.com/developer/api/mep/campaigns/parameters) containing at least the same number of parameters you used when you first created your campaign or more.

> **Please note that**:\
> \- Complete campaigns cannot be set live again.\
> \- Parameters added after an update cannot be removed.\
> \- You cannot switch back to a one-time campaign after chosing a recurring campaign.

### Responses

#### Success

If the POST to the API endpoint is successfull you will receive an **HTTP 200** confirmation.

#### Failure

If the POST data does not meet the API requirements you will receive an actionable error message. Contact us at <support@batch.com> if you need further support.

* `AUTHENTICATION_INVALID` (Http status code: 401, Error code: 10)
* `API_MISUSE` (Http status code: 403, Error code: 12)
* `ROUTE_NOT_FOUND` (Http status code: 404, Error code: 20)
* `MISSING_PARAMETER` (Http status code: 400, Error code: 30)
* `MALFORMED_PARAMETER` (Http status code: 400, Error code: 31)
* `MALFORMED_JSON_BODY` (Http status code: 400, Error code: 32)
* `SERVER_ERROR` (Http status code: 500, Error code: 1)
* `MAINTENANCE_ERROR` (Http status code: 503, Error code: 2)
* `TOO_MANY_REQUESTS` (Http status code: 429, Error code: 60)\
  If you get a "too many requests" response, please wait for at least 5 seconds before trying again. Further requests might still return this error.
