Tokenization - Create
curl --request POST \
--url https://sandbox.hyperswitch.io/v2/tokenize \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"customer_id": "0a_cus_0196d94b9c207333a297cbcf31f2e8c8",
"token_request": {
"payment_method_data": {
"card": {
"card_holder_name": "test name"
}
}
}
}
'import requests
url = "https://sandbox.hyperswitch.io/v2/tokenize"
payload = {
"customer_id": "0a_cus_0196d94b9c207333a297cbcf31f2e8c8",
"token_request": { "payment_method_data": { "card": { "card_holder_name": "test name" } } }
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customer_id: '0a_cus_0196d94b9c207333a297cbcf31f2e8c8',
token_request: {payment_method_data: {card: {card_holder_name: 'test name'}}}
})
};
fetch('https://sandbox.hyperswitch.io/v2/tokenize', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://sandbox.hyperswitch.io/v2/tokenize",
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([
'customer_id' => '0a_cus_0196d94b9c207333a297cbcf31f2e8c8',
'token_request' => [
'payment_method_data' => [
'card' => [
'card_holder_name' => 'test name'
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://sandbox.hyperswitch.io/v2/tokenize"
payload := strings.NewReader("{\n \"customer_id\": \"0a_cus_0196d94b9c207333a297cbcf31f2e8c8\",\n \"token_request\": {\n \"payment_method_data\": {\n \"card\": {\n \"card_holder_name\": \"test name\"\n }\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
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))
}HttpResponse<String> response = Unirest.post("https://sandbox.hyperswitch.io/v2/tokenize")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"customer_id\": \"0a_cus_0196d94b9c207333a297cbcf31f2e8c8\",\n \"token_request\": {\n \"payment_method_data\": {\n \"card\": {\n \"card_holder_name\": \"test name\"\n }\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://sandbox.hyperswitch.io/v2/tokenize")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customer_id\": \"0a_cus_0196d94b9c207333a297cbcf31f2e8c8\",\n \"token_request\": {\n \"payment_method_data\": {\n \"card\": {\n \"card_holder_name\": \"test name\"\n }\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "0a_tok_01926c58bc6e77c09e809964e72af8c8",
"created_at": "2024-02-24T11:04:09.922Z",
"flag": "enabled"
}Tokenization
Tokenization - Create
Create a token with customer_id
POST
/
v2
/
tokenize
Tokenization - Create
curl --request POST \
--url https://sandbox.hyperswitch.io/v2/tokenize \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"customer_id": "0a_cus_0196d94b9c207333a297cbcf31f2e8c8",
"token_request": {
"payment_method_data": {
"card": {
"card_holder_name": "test name"
}
}
}
}
'import requests
url = "https://sandbox.hyperswitch.io/v2/tokenize"
payload = {
"customer_id": "0a_cus_0196d94b9c207333a297cbcf31f2e8c8",
"token_request": { "payment_method_data": { "card": { "card_holder_name": "test name" } } }
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
customer_id: '0a_cus_0196d94b9c207333a297cbcf31f2e8c8',
token_request: {payment_method_data: {card: {card_holder_name: 'test name'}}}
})
};
fetch('https://sandbox.hyperswitch.io/v2/tokenize', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://sandbox.hyperswitch.io/v2/tokenize",
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([
'customer_id' => '0a_cus_0196d94b9c207333a297cbcf31f2e8c8',
'token_request' => [
'payment_method_data' => [
'card' => [
'card_holder_name' => 'test name'
]
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://sandbox.hyperswitch.io/v2/tokenize"
payload := strings.NewReader("{\n \"customer_id\": \"0a_cus_0196d94b9c207333a297cbcf31f2e8c8\",\n \"token_request\": {\n \"payment_method_data\": {\n \"card\": {\n \"card_holder_name\": \"test name\"\n }\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<api-key>")
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))
}HttpResponse<String> response = Unirest.post("https://sandbox.hyperswitch.io/v2/tokenize")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"customer_id\": \"0a_cus_0196d94b9c207333a297cbcf31f2e8c8\",\n \"token_request\": {\n \"payment_method_data\": {\n \"card\": {\n \"card_holder_name\": \"test name\"\n }\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://sandbox.hyperswitch.io/v2/tokenize")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"customer_id\": \"0a_cus_0196d94b9c207333a297cbcf31f2e8c8\",\n \"token_request\": {\n \"payment_method_data\": {\n \"card\": {\n \"card_holder_name\": \"test name\"\n }\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"id": "0a_tok_01926c58bc6e77c09e809964e72af8c8",
"created_at": "2024-02-24T11:04:09.922Z",
"flag": "enabled"
}Authorizations
Format: api-key=<api_key>
Use the API key created under your merchant account from the HyperSwitch dashboard. API key is used to authenticate API requests from your merchant server only. Don't expose this key on a website or embed it in a mobile application.
Body
application/json
Response
Token created successfully
Was this page helpful?
⌘I