buyVoucher

Last Updated 11th May, 2025

The buyVoucher mutation allows users to purchase game or service vouchers in desired quantities using their account balance. The system will deduct the total amount from the user, reduce stock from the product database, log the transaction, and send a Telegram notification.


๐Ÿ”— Endpoint URL: https://api.vscgames.com/graphql Method: POST Content-Type: application/json


๐Ÿ“‚ Mutation Structure

mutation BuyVoucher($productId: Int!, $quantity: Int!) {
  buyVoucher(productId: $productId, quantity: $quantity) {
    code
    message
    codes
    productId
    categoryId
    name
    description
    price
    quantity
    totalCost
    status
    type
    timestamp
    orderId
  }
}

๐Ÿ“ฅ Headers Required

  • apikey: Your valid API key.


๐Ÿ“ฆ Parameters

Name
Type
Required
Description

productId

Int

โœ…

ID of the product to purchase

quantity

Int

โœ…

Number of codes to buy


โœ… Successful Response

{
  "data": {
    "buyVoucher": {
      "code": 200,
      "message": "Voucher purchase successful",
      "codes": ["XXXX-YYYY-ZZZZ"],
      "productId": 1005,
      "categoryId": 2,
      "name": "FREE FIRE 110 DIAMONDS",
      "description": "Codes are stackable...",
      "price": 2,
      "quantity": 1,
      "totalCost": 2,
      "status": "completed",
      "type": "purchase",
      "timestamp": "2025-05-10T14:00:00.000Z",
      "orderId": "10112"
    }
  }
}

โ›” Error Codes

Code
Description

401

API key missing or invalid

402

Insufficient balance

403

Invalid API key

404

Product not found

409

Insufficient product stock

500

Code pool corrupted or internal


๐Ÿ”ฎ Code Examples

Python

import requests

url = "https://api.vscgames.com/graphql"
headers = {
    "Content-Type": "application/json",
    "apikey": "your-api-key"
}

query = """
mutation BuyVoucher($productId: Int!, $quantity: Int!) {
  buyVoucher(productId: $productId, quantity: $quantity) {
    code
    message
    codes
    orderId
  }
}
"""

variables = {"productId": 1005, "quantity": 1}

response = requests.post(url, json={"query": query, "variables": variables}, headers=headers)
print(response.json())

JavaScript (Node.js)

const fetch = require("node-fetch");

const query = `
mutation BuyVoucher($productId: Int!, $quantity: Int!) {
  buyVoucher(productId: $productId, quantity: $quantity) {
    code
    message
    codes
    orderId
  }
}`;

const variables = {
  productId: 1005,
  quantity: 1
};

fetch("https://api.vscgames.com/graphql", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "apikey": "your-api-key"
  },
  body: JSON.stringify({ query, variables })
})
.then(res => res.json())
.then(data => console.log(data));

Last updated