# Update Configuration

**POST** `/v1/keys/{key}/configs/{config}`

Replaces a configuration's payload and returns the updated configuration. The name is fixed at creation.

## Example request

**curl**

```bash
curl -X POST 'https://api.addresszen.com/v1/keys/ak_test/configs/woocommerce?user_token=uk_secret' \
  -H 'Content-Type: application/json' \
  -d '{
    "payload": "{\"removeOrganisation\": true}"
  }'
```

**JavaScript**

```javascript
import { createZenClient, updateConfig } from '@addresszen/sdk';

const client = createZenClient({ apiKey: 'ak_test', userToken: 'uk_secret' });

const { data } = await updateConfig({
  client,
  path: { key: 'ak_test', config: 'woocommerce' },
  body: {
    payload: '{"removeOrganisation": true}',
  },
});
```

**Python**

```python
# pip install addresszen
import json

from addresszen import AddressZen

with AddressZen("ak_test") as client:
    result = client.update_config(
        "ak_test",
        "woocommerce",
        user_token="uk_secret",
        payload=json.dumps({"removeOrganisation": True}),
    )
```

**Ruby**

```ruby
require "net/http"
require "json"

uri = URI("https://api.addresszen.com/v1/keys/ak_test/configs/woocommerce?user_token=uk_secret")
body = {
  payload: '{"removeOrganisation": true}',
}
response = Net::HTTP.post(uri, body.to_json, "Content-Type" => "application/json")
result = JSON.parse(response.body)["result"]
```

**PHP**

```php
<?php
$ch = curl_init("https://api.addresszen.com/v1/keys/ak_test/configs/woocommerce?user_token=uk_secret");
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => ["Content-Type: application/json"],
  CURLOPT_POSTFIELDS => json_encode([
    "payload" => '{"removeOrganisation": true}',
  ]),
  CURLOPT_RETURNTRANSFER => true,
]);
$result = json_decode(curl_exec($ch), true)["result"];
```

## Example body

```json
{
  "payload": "{\n  \"removeOrganisation\": false\n}\n"
}
```

## Example response

**200 OK**

```json
{
  "result": {
    "updatedAt": "2016-01-21T17:14:49.971Z",
    "createdAt": "2016-01-21T17:14:49.971Z",
    "name": "woocommerce",
    "payload": "{\n  \"removeOrganisation\": false\n}\n"
  },
  "code": 2000,
  "message": "Success"
}
```

## Path parameters

* `key` string

  **API Key**

  The API Key. Begins `ak_`.

  Example: `ak_test`

* `config` string

  **Configuration Name**

  User-provided configuration object name.

  Example: `checkout-form`

## Query parameters

* `user_token` string optional

  **Management Key**

  A secret key used to manage your account and API Keys. It was previously called the user token.

  Your management key can be retrieved and managed from your [accounts page](https://addresszen.com/account).

  Typically begins `uk_`. Prefer sending it in the `Authorization` header as `Bearer uk_...` instead of this query parameter. The `Authorization: user_token="uk_..."` header also works.

  Example: `uk_B59ScW1p1HHouf1VqclEPZUx`

## Request body

The request body must contain a JSON object with:

* `body` ConfigUpdateParam

  Config object update parameters

  * `payload` string optional

    A serialized payload of up to `65536` characters

    Example: `{ "removeOrganisation": false }`

## Response

Returns the updated configuration object with refreshed timestamps.

* `result` Config

  | Field       | Type   | Description                                                                                  |
  | ----------- | ------ | -------------------------------------------------------------------------------------------- |
  | `updatedAt` | string | Timestamp for when the config was last updated. Example: `2016-01-21T17:14:49.971Z`          |
  | `createdAt` | string | Timestamp for when the config was created. Example: `2016-01-21T17:14:49.971Z`               |
  | `name`      | string | A unique name to identify the configuration payload. Example: `woocommerce`                  |
  | `payload`   | string | A serialised payload of up to `65536` characters. Example: `{ "removeOrganisation": false }` |

The `result` sits inside the standard `{ result, code, message }` envelope. See the [API reference](/docs/api/api-reference.md) for the wrapper format.
