# Withdraw fund

## Withdraw fund

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

**Headers**

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

**Body**

| Name     | Type   | Description           |
| -------- | ------ | --------------------- |
| card\_id | string | The card identifier   |
| `amount` | string | The withdrawal amount |

**Response**

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

```json

{
    "status": "success",
    "transaction_id": "VC383611797554",
    "amount": 3,
    "fees": "0",
    "message": "Transaction completed successfully"
}

```

{% endtab %}

{% tab title="400" %}

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

{% endtab %}
{% endtabs %}

See Examples Below

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

```javascript
// API URL
const url = "https://api.krezypay.com/v1/sandbox/card/withdraw_fund";

// Data to send in the body of the request
const data = {
  card_id: "c451ad689f414827abb0b6dc6ea96edb",
  amount: "3"
};

// Bearer token
const token = "YOUR_BEARER_TOKEN_HERE";  // Replace with the actual token

// Request options
const options = {
  method: "POST",  // HTTP method
  headers: {
    "Content-Type": "application/json",  // Sending JSON data
    "Authorization": `Bearer ${token}`   // Authorization header with Bearer token
  },
  body: JSON.stringify(data)  // Convert the data object to a JSON string
};

// Execute the HTTP request
fetch(url, options)
  .then(response => {
    if (!response.ok) {
      // If the response status is not OK (200-299), throw an error
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    return response.json();  // Parse the response body as JSON
  })
  .then(result => {
    // Handle success - log the result
    console.log("Success:", result);
  })
  .catch(error => {
    // Handle errors during the request
    console.error("Error:", error);
  });

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
// API URL
$url = "https://api.krezypay.com/v1/sandbox/card/withdraw_fund";

// Data to send in the body
$data = [
    "card_id" => "c451ad689f414827abb0b6dc6ea96edb",
    "amount" => "3"
];

// Bearer token
$token = "YOUR_BEARER_TOKEN_HERE"; // Replace with the actual token

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

// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  // Return the response as a string
curl_setopt($ch, CURLOPT_POST, true);            // Make a POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',           // Content type set to JSON
    "Authorization: Bearer $token"              // Authorization with Bearer token
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));  // JSON-encoded data sent in the body

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

// Error handling
if (curl_errno($ch)) {
    echo 'cURL error: ' . curl_error($ch);
} else {
    // Decode the JSON response
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    
    if ($httpCode === 200) {
        // Successful response
        $result = json_decode($response, true);
        echo json_encode([
            "status" => "success",
            "data" => $result
        ], JSON_PRETTY_PRINT);
    } else {
        // Handle failed response
        echo json_encode([
            "status" => "error",
            "http_code" => $httpCode,
            "message" => "An error occurred during the request."
        ], JSON_PRETTY_PRINT);
    }
}

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

```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

# API URL
url = "https://api.krezypay.com/v1/sandbox/card/withdraw_fund"

# Data to send in the body of the request
data = {
    "card_id": "c451ad689f414827abb0b6dc6ea96edb",
    "amount": "3"
}

# Bearer token
token = "YOUR_BEARER_TOKEN_HERE"  # Replace with the actual token

# Set the headers, including the Authorization Bearer token
headers = {
    "Content-Type": "application/json",  # Data type we're sending
    "Authorization": f"Bearer {token}"   # Bearer token for authorization
}

# Execute the HTTP POST request
response = requests.post(url, headers=headers, data=json.dumps(data))

# Check if the request was successful (status code 200-299)
if response.status_code == 200:
    # Parse the response as JSON and print the result
    result = response.json()
    print("Success:", json.dumps(result, indent=4))
else:
    # Handle any errors during the request
    print(f"Error: {response.status_code}, {response.text}")

```

{% endtab %}
{% endtabs %}
