# Create card

This endpoint allows you to create a new card (virtual or physical) for a customer registered in the KrezyPay system. It ensures the validation of the information provided and checks the uniqueness of the card to avoid duplicates.

## Create a new card

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

**Headers**

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

**Body**

| Name         | Type   | Description                                                   |
| ------------ | ------ | ------------------------------------------------------------- |
| customer\_id | string | The customer\_id of the customer provided during registration |
| card\_type   | string | The type of card "Virtual" or "Physical"                      |
| card\_brand  | string | The brand of card "Visa" or "Mastercard"                      |

**Response**

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

```json

{
    "status": "success",
    "card_id": "6711305d3cc1c6711305d3cc1e",
    "message": "Card created successfully"
}

```

{% endtab %}

{% tab title="400" %}

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

{% endtab %}
{% endtabs %}

See Examples Below

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

```javascript
const endpoint = 'https://api.krezypay.com/v1/sandbox/card/create_card';
const bearerToken = 'YOUR_BEARER_TOKEN'; // Replace with your actual bearer token

const requestBody = {
    customer_id: "67112de111f2667112de111f28",
    card_type: "Virtual",
    card_brand: "Mastercard"
};

fetch(endpoint, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${bearerToken}`
    },
    body: JSON.stringify(requestBody)
})
.then(response => {
    if (!response.ok) {
        throw new Error('Network response was not ok ' + response.statusText);
    }
    return response.json(); // Parse the JSON from the response
})
.then(data => {
    console.log('Success:', data); // Handle the successful response data
})
.catch(error => {
    console.error('Error:', error); // Handle any errors
});

```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
// Set the API endpoint
$endpoint = 'https://api.krezypay.com/v1/sandbox/card/create_card';

// Your Bearer token
$bearerToken = 'YOUR_BEARER_TOKEN'; // Replace with your actual bearer token

// Request body data
$requestBody = [
    'customer_id' => '67112de111f2667112de111f28',
    'card_type' => 'Virtual',
    'card_brand' => 'Mastercard'
];

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

// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string
curl_setopt($ch, CURLOPT_POST, true); // Set the request method to POST
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Authorization: Bearer ' . $bearerToken // Set the Authorization header with Bearer token
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestBody)); // Set the request body as JSON

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

// Check for errors
if (curl_errno($ch)) {
    echo 'cURL error: ' . curl_error($ch);
} else {
    // Decode the JSON response
    $responseData = json_decode($response, true);
    // Handle the response data
    echo 'Response: ';
    print_r($responseData); // Print the response data
}

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

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

# Set the API endpoint
endpoint = 'https://api.krezypay.com/v1/sandbox/card/create_card'

# Your Bearer token
bearer_token = 'YOUR_BEARER_TOKEN'  # Replace with your actual bearer token

# Request body data
request_body = {
    'customer_id': '67112de111f2667112de111f28',
    'card_type': 'Virtual',
    'card_brand': 'Mastercard'
}

# Set the headers
headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {bearer_token}'  # Set the Authorization header with Bearer token
}

# Make the POST request
response = requests.post(endpoint, json=request_body, headers=headers)

# Check if the request was successful
if response.status_code == 200:
    # Print the response data
    print('Response:', response.json())
else:
    # Print the error response
    print(f'Error: {response.status_code}, Message: {response.text}')

```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Don't forget to save your rating's card\_id
{% endhint %}


---

# 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/create-card.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.
