RecipesIssue and manage cards
Issue and manage cards
- 01Create a customer
Before issuing a card, you need to create a customer record in Gravv. This section sends a POST request to the "customers" endpoint with the individual's personal information, including their name, contact details, and address.
The API returns a customer object containing a unique ID that you'll need for all subsequent operations. We extract this ID on line 32 and store it in the "customerId" variable for use in later steps.
const API_KEY = '<Api Key>';const BASE_URL = 'https://api.gravv.xyz';async function issueAndManageCard() {try {// Step 1: Create a customerconst customerResponse = await fetch(`${BASE_URL}/v1/customers`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({first_name: "Sarah",last_name: "Johnson",email: "sarah.johnson@example.com",phone: "+14155552345",type: "individual",gender: "female",date_of_birth: "1990-03-15",address: {address_line1: "123 Market Street",city: "San Francisco",postal_code: "94102",state: "US-CA",country: "US"}})});const customerData = await customerResponse.json();const customerId = customerData.data.id; - 02Verify the customer with KYC
Card issuance requires intermediate-level KYC verification. This section initiates the verification process by submitting the customer's identification documents. The request includes the "customer_id" from step 1, the KYC level, and an array of documents with their metadata. The document URL should point to where you've uploaded the customer's passport or ID.
The API will process these documents and update the verification status. You must wait for approval before proceeding to card creation.
// Step 2: Verify the customer with KYCconst kycResponse = await fetch(`${BASE_URL}/v1/risk/start-kyc`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({kyc_level: "intermediate",customer_id: customerId,documents: [{doc_type: "PASSPORT",country: "USA",url: "https://example.com/documents/passport.pdf",metadata: {firstName: "Sarah",lastName: "Johnson",number: "P123456789",issuedDate: "2019-03-10",validUntil: "2029-03-10",dob: "1990-03-15",placeOfBirth: "San Francisco, CA"}}]})});const kycResult = await kycResponse.json(); - 03Create an account for card withdrawals
This section creates an account that will receive all funds when you withdraw from customer cards.
The code creates a regular USD account on the Polygon blockchain network, which serves as your business's collection point for card withdrawals. By using a descriptive label like "Card Withdrawals Master Account", you can easily identify this account's purpose.
Line 93 extracts the "masterAccountId". You pass it as the
account_idwhen you activate the card feature, so the card is backed by this account.// Step 3: Create a master account for card withdrawalsconst accountResponse = await fetch(`${BASE_URL}/v1/accounts`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({currency: "USD",type: "regular",blockchain_network: "polygon",label: "Card Withdrawals Master Account",customer_id: customerId})});const accountData = await accountResponse.json();const masterAccountId = accountData.data.id; - 04Activate the card feature
There's no separate "submit application" call. Activating the
virtual_cardsfeature creates the card application for you. This step sends the customer's annual income (annual_remuneration), expected monthly spending (estimated_monthly_limit), their IP address for fraud prevention, and the account_id from step 3, all insideprovider_data.The response returns the new
application_id. If it returns awebsdk_urlinstead, the customer still needs to finish their liveness check: send them to that URL, then call this endpoint again before continuing.// Step 4: Activate the card feature (this creates the card application)const activationResponse = await fetch(`${BASE_URL}/v1/risk/features/activate`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({customer_id: customerId,feature_id: "virtual_cards",provider_data: {annual_remuneration: 75000,estimated_monthly_limit: 2000,ip_address: "192.168.1.100",account_id: masterAccountId}})});const activationResult = await activationResponse.json();// If the response carries a websdk_url, send the customer there to finish// their liveness check, then call this endpoint again before continuing.const applicationId = activationResult.data.data.application_id; - 05Wait for approval
A card application has to be approved before you can create the card. This section defines a helper that polls Get card application using the
application_id, reading theapplication_statusfield. Wait until it readsapproved.// Step 5: Wait for the application to be approvedconst checkStatus = async (applicationId) => {const statusResponse = await fetch(`${BASE_URL}/v1/cards/applications/${applicationId}`,{headers: {'Api-Key': API_KEY}});const statusData = await statusResponse.json();return statusData.data.application_status;};let applicationStatus = await checkStatus(applicationId); - 06Create the card
Once the application is approved, this section creates the card, specifying the spending limit (card_limit of 500 USD), the name to display, and the card type. The create response returns the new card, and we read its
idfor the funding step that follows.The card is automatically backed by the account you set during activation.
// Step 6: Create the card once the application is approvedconst cardResponse = await fetch(`${BASE_URL}/v1/cards`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({customer_id: customerId,card_limit: 500,name_on_card: "Sarah Johnson",card_type: "virtual"})});const cardData = await cardResponse.json();const cardId = cardData.data.id; - 07Fund the card
This step initiates a transfer from one of your internal accounts to the card (destination). The source account ID should be an account you've previously funded. By setting destination_type to "card" and providing the card ID, the funds are transferred directly to the card's balance.
// Step 7: Fund the cardconst fundResponse = await fetch(`${BASE_URL}/v1/transfer`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({source: {source_type: "internal_account",id: "b9c2cb0d-e09a-496f-8655-d8c4b7aaf2f8" // Your funding account},destination: {destination_type: "card",id: cardId},amount: 250,description: "Initial card funding",customer_id: customerId,client_reference: "card_fund_001"})});const fundResult = await fundResponse.json();console.log('Card funded successfully'); - 08Withdraw funds from the card
This step withdraws a specified amount back to your business. The withdrawal endpoint only requires the card_id and the amount to withdraw. The funds automatically transfer to the account that backs the card, set during activation in step 4.
// Step 8: Withdraw funds from the cardconst withdrawResponse = await fetch(`${BASE_URL}/v1/cards/withdraw`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({card_id: cardId,amount: 100})});const withdrawResult = await withdrawResponse.json();} catch (error) {console.error('Error:', error);}}// Run the functionissueAndManageCard();
const API_KEY = '<Api Key>';const BASE_URL = 'https://api.gravv.xyz';async function issueAndManageCard() {try {// Step 1: Create a customerconst customerResponse = await fetch(`${BASE_URL}/v1/customers`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({first_name: "Sarah",last_name: "Johnson",email: "sarah.johnson@example.com",phone: "+14155552345",type: "individual",gender: "female",date_of_birth: "1990-03-15",address: {address_line1: "123 Market Street",city: "San Francisco",postal_code: "94102",state: "US-CA",country: "US"}})});const customerData = await customerResponse.json();const customerId = customerData.data.id;// Step 2: Verify the customer with KYCconst kycResponse = await fetch(`${BASE_URL}/v1/risk/start-kyc`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({kyc_level: "intermediate",customer_id: customerId,documents: [{doc_type: "PASSPORT",country: "USA",url: "https://example.com/documents/passport.pdf",metadata: {firstName: "Sarah",lastName: "Johnson",number: "P123456789",issuedDate: "2019-03-10",validUntil: "2029-03-10",dob: "1990-03-15",placeOfBirth: "San Francisco, CA"}}]})});const kycResult = await kycResponse.json();// Step 3: Create a master account for card withdrawalsconst accountResponse = await fetch(`${BASE_URL}/v1/accounts`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({currency: "USD",type: "regular",blockchain_network: "polygon",label: "Card Withdrawals Master Account",customer_id: customerId})});const accountData = await accountResponse.json();const masterAccountId = accountData.data.id;// Step 4: Activate the card feature (this creates the card application)const activationResponse = await fetch(`${BASE_URL}/v1/risk/features/activate`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({customer_id: customerId,feature_id: "virtual_cards",provider_data: {annual_remuneration: 75000,estimated_monthly_limit: 2000,ip_address: "192.168.1.100",account_id: masterAccountId}})});const activationResult = await activationResponse.json();// If the response carries a websdk_url, send the customer there to finish// their liveness check, then call this endpoint again before continuing.const applicationId = activationResult.data.data.application_id;// Step 5: Wait for the application to be approvedconst checkStatus = async (applicationId) => {const statusResponse = await fetch(`${BASE_URL}/v1/cards/applications/${applicationId}`,{headers: {'Api-Key': API_KEY}});const statusData = await statusResponse.json();return statusData.data.application_status;};let applicationStatus = await checkStatus(applicationId);// Step 6: Create the card once the application is approvedconst cardResponse = await fetch(`${BASE_URL}/v1/cards`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({customer_id: customerId,card_limit: 500,name_on_card: "Sarah Johnson",card_type: "virtual"})});const cardData = await cardResponse.json();const cardId = cardData.data.id;// Step 7: Fund the cardconst fundResponse = await fetch(`${BASE_URL}/v1/transfer`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({source: {source_type: "internal_account",id: "b9c2cb0d-e09a-496f-8655-d8c4b7aaf2f8" // Your funding account},destination: {destination_type: "card",id: cardId},amount: 250,description: "Initial card funding",customer_id: customerId,client_reference: "card_fund_001"})});const fundResult = await fundResponse.json();console.log('Card funded successfully');// Step 8: Withdraw funds from the cardconst withdrawResponse = await fetch(`${BASE_URL}/v1/cards/withdraw`, {method: 'POST',headers: {'Api-Key': API_KEY,'Content-Type': 'application/json'},body: JSON.stringify({card_id: cardId,amount: 100})});const withdrawResult = await withdrawResponse.json();} catch (error) {console.error('Error:', error);}}// Run the functionissueAndManageCard();