getProductById
Last Updated 11th May, 2025
The getProductById
query fetches a single product using its unique productid
. If the product does not exist, it throws an error.
🔗 Endpoint
URL: https://api.vscgames.com/graphql
Method: POST
Content-Type: application/json
🔍 Query Structure
query getProductById($productid: String!) {
getProductById(productid: $productid) {
_id
name
price
categoryid
}
}
📥 Parameters
Name
Type
Required
Description
productid
String
✅ Yes
The unique ID of the product
✅ Successful Response
{
"data": {
"getProductById": {
"_id": "prd123",
"name": "Free Fire 110 Diamonds",
"price": 1.99,
"categoryid": "cat001"
}
}
}
🚫 Error Response
If the product ID is not found in the database:
{
"errors": [
{
"message": "Product not found",
"path": ["getProductById"]
}
]
}
🧪 Code Examples
Python
import requests
url = "https://api.vscgames.com/graphql"
headers = {"Content-Type": "application/json"}
query = """
query getProductById($productid: String!) {
getProductById(productid: $productid) {
_id
name
price
categoryid
}
}
"""
variables = {
"productid": "prd123"
}
response = requests.post(url, json={"query": query, "variables": variables}, headers=headers)
print(response.json())
JavaScript
const fetch = require("node-fetch");
const query = `
query getProductById($productid: String!) {
getProductById(productid: $productid) {
_id
name
price
categoryid
}
}`;
const variables = {
productid: "prd123"
};
fetch("https://api.vscgames.com/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ query, variables })
})
.then(res => res.json())
.then(data => console.log(data));
Last updated