## Update Promo Code

### cURL

```bash
curl --request POST \
  --url https://api.withflex.com/v1/promo_codes/{id} \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "promo_code": {
    "active": false,
    "metadata": {
      "key": "value"
    }
  }
}
'
```

```python
import requests

url = "https://api.withflex.com/v1/promo_codes/{id}"

payload = { "promo_code": {
        "active": False,
        "metadata": { "key": "value" }
    } }
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

```javascript
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({promo_code: {active: false, metadata: {key: 'value'}}})
};

fetch('https://api.withflex.com/v1/promo_codes/{id}', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://api.withflex.com/v1/promo_codes/{id}",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'promo_code' => [
        'active' => false,
        'metadata' => [
                'key' => 'value'
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

url := "https://api.withflex.com/v1/promo_codes/{id}"

payload := strings.NewReader("{\n  \"promo_code\": {\n    \"active\": false,\n    \"metadata\": {\n      \"key\": \"value\"\n    }\n  }\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))
}
```

```java
HttpResponse<String> response = Unirest.post("https://api.withflex.com/v1/promo_codes/{id}")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"promo_code\": {\n    \"active\": false,\n    \"metadata\": {\n      \"key\": \"value\"\n    }\n  }\n}")
  .asString();
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.withflex.com/v1/promo_codes/{id}")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"promo_code\": {\n    \"active\": false,\n    \"metadata\": {\n      \"key\": \"value\"\n    }\n  }\n}"

response = http.request(request)
puts response.read_body
```

### Example Responses

#### Success Response (200)
```json
{
  "promo_code": {
    "promo_code_id": "fpromo_01HACM7FZ1084XB1GB6053VM0E",
    "code": "SUMMER2016",
    "coupon": {
      "coupon_id": "fcoup_1234567890",
      "amount_off": 100,
      "applies_to": null,
      "duration": "once",
      "duration_in_months": null,
      "metadata": {
        "key": "value"
      },
      "name": "Coupon",
      "percent_off": 10,
      "max_redemptions": 100,
      "times_redeemed": 0,
      "valid": true,
      "created_at": "2024-05-17T14:59:21Z",
      "test_mode": true
    },
    "max_redemptions": 100,
    "times_redeemed": 0,
    "created_at": "2024-05-17T14:59:21Z",
    "customer": "fcus_01HACM7FZ1084XB1GB6053VM0D",
    "active": true,
    "metadata": {
      "key": "value"
    },
    "test_mode": false
  }
}
```

#### Error Responses

1. 401 Unauthorized
   ```json
{
  "code": "string",
  "detail": "string"
}
```

2. 403 Forbidden
   ```json
{
  "code": "string",
  "detail": "string"
}
```

3. 404 Not Found
   ```json
{
  "code": "string",
  "detail": "string"
}
```

4. 409 Conflict
   ```json
{
  "code": "string",
  "detail": "string"
}
```

5. 422 Unprocessable Entity
   ```json
{
  "detail": [
    {
      "loc": [
        "string"
      ],
      "msg": "string",
      "type": "string"
    }
  ]
}
```

6. 429 Too Many Requests
   ```json
{
  "code": "string",
  "detail": "string"
}
```

### Authorizations

**Authorization**: Use a Bearer token to access this API.

### Path Parameters

- **id** (string, required): Example: "fpromo_01J9XR8M3K7VZ8N2YB4WJ6T0RA"

### Body

**Content-Type**: application/json

- **promo_code** (object, required): The promotion code.  
Example:
```json
{
  "active": false,
  "metadata": { "key": "value" }
}
```

### Response

**200 OK**: An envelope wrapping a single promotion code object.
