# Freeze/Unfreeze

## Freeze or Unfreeze a card

<mark style="color:green;">`POST`</mark> <https://api.krezypay.com/v1/sandbox/card/card_status>

**Headers**

| Name          | Value              |
| ------------- | ------------------ |
| Content-Type  | `application/json` |
| Authorization | `Bearer <token>`   |

**Body**

| Name         | Type   | Description                                                |
| ------------ | ------ | ---------------------------------------------------------- |
| card\_id     | string | The card identifier                                        |
| card\_status | string | The status of the card. It must be "active" or "inactive". |

**Response**

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

```json

{
    "status": "success",
    "message": "This card has been unfrozen successfully"
}

```

{% endtab %}

{% tab title="400" %}

```json
{
  "error": "Invalid request"
}
```

{% endtab %}
{% endtabs %}

See Examples Below

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

```javascript
// Define the endpoint and the token
const endpoint = 'https://api.krezypay.com/v1/sandbox/card/card_status';
const bearerToken = 'your_bearer_token_here'; // Replace this with your actual Bearer token

// Define the request body
const requestBody = {
    card_id: "c451ad689f414827abb0b6dc6ea96edb",
    card_status: "active"
};

// Send an HTTP POST request
fetch(endpoint, {
    method: 'POST', // The request method
    headers: {
        'Content-Type': 'application/json',  // Tell the server the format of the body
        'Authorization': `Bearer ${bearerToken}` // Add the Bearer token to the request headers
    },
    body: JSON.stringify(requestBody) // Convert the body object to a JSON string
})
.then(response => {
    // Check if the response status is OK (2xx)
    if (!response.ok) {
        return response.json().then(errorData => {
            throw new Error(`Error: ${errorData.message}`);
        });
    }
    return response.json(); // Parse the JSON response
})
.then(data => {
    console.log(JSON.stringify(data, null, 2)); // Log the response as formatted JSON
})
.catch((error) => {
    console.error('Error:', error); // Handle any errors during the request
});

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
// Define the endpoint URL and the Bearer token
$endpoint = "https://api.krezypay.com/v1/sandbox/card/card_status";
$bearerToken = "your_bearer_token_here"; // Replace with your actual Bearer token

// Define the request body
$requestBody = [
    "card_id" => "c451ad689f414827abb0b6dc6ea96edb",
    "card_status" => "active"
];

// Initialize cURL session
$ch = curl_init();

// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);

// Set the headers, including the Authorization Bearer token
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer $bearerToken",
    "Content-Type: application/json"
]);

// Attach the JSON-encoded body to the request
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestBody));

// Execute the request
$response = curl_exec($ch);

// Check if there was an error with the request
if (curl_errno($ch)) {
    echo 'Curl error: ' . curl_error($ch);
    exit;
}

// Get the HTTP response status code
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// Close the cURL session
curl_close($ch);

// Handle the response
if ($httpCode === 200) {
    // Decode the JSON response if it's successful
    $responseData = json_decode($response, true);
    echo json_encode($responseData, JSON_PRETTY_PRINT); // Output the response as formatted JSON
} else {
    // Handle error responses
    $responseData = json_decode($response, true);
    echo json_encode([
        "status" => "error",
        "message" => $responseData['message'] ?? "An error occurred.",
        "http_code" => $httpCode
    ], JSON_PRETTY_PRINT);
}

```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

# Define the API endpoint and Bearer token
url = "https://api.krezypay.com/v1/sandbox/card/card_status"
bearer_token = "your_bearer_token_here"  # Replace with your actual Bearer token

# Define the request payload (body)
payload = {
    "card_id": "c451ad689f414827abb0b6dc6ea96edb",
    "card_status": "active"
}

# Define the headers including the Authorization Bearer token
headers = {
    "Authorization": f"Bearer {bearer_token}",
    "Content-Type": "application/json"
}

# Make the POST request
response = requests.post(url, headers=headers, json=payload)

# Handle the response
if response.status_code == 200:
    # If the request was successful, parse the JSON response
    response_data = response.json()
    print(json.dumps(response_data, indent=4))  # Pretty-print the JSON response
else:
    # If an error occurred, print the status code and the response message
    print(json.dumps({
        "status": "error",
        "message": response.json().get("message", "An error occurred"),
        "http_code": response.status_code
    }, indent=4))

```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.krezypay.com/card/freeze-unfreeze.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
