GraphQL API for Developers
1.1 API Overview
Endpoint: https://api.capsurelabs.com/graphql
Authentication Header:
Authorization: Bearer <token>
1.2 Configuration
CapsureLabs’ GraphQL API can be configured to work with any GraphQL client or HTTP client (such as Apollo Client
, Postman
, or curl
). Authentication tokens are required for access to secure endpoints.
Sample Configuration with Apollo Client (JavaScript):
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';
const client = new ApolloClient({
link: new HttpLink({
uri: 'https://api.capsurelabs.com/graphql',
headers: {
Authorization: `Bearer ${token}`
}
}),
cache: new InMemoryCache()
});
1.3 Basic GraphQL Queries
Below are examples of common GraphQL queries and mutations, along with their purpose, structure, and example responses.
1.3.1 Query: Get User Profile
Description: Retrieves the authenticated user’s profile, including information about their assets and preferences.
Query:
query GetUserProfile {
userProfile {
id
username
email
assets {
assetId
name
balance
assetType
}
}
}
Sample Request (cURL):
curl -X POST https://api.capsurelabs.com/graphql \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{"query": "query { userProfile { id username email assets { assetId name balance assetType } } }"}'
Sample Response:
{
"data": {
"userProfile": {
"id": "user123",
"username": "CapsureDev",
"email": "user@capsurelabs.com",
"assets": [
{
"assetId": "0x123abc",
"name": "Ethereum",
"balance": 2.5,
"assetType": "Cryptocurrency"
},
{
"assetId": "0x456def",
"name": "CapsureLabs NFT",
"balance": 1,
"assetType": "NFT"
}
]
}
}
}
1.3.2 Query: Get Asset Price
Description: Fetches the current price and 24-hour change percentage of a specified asset.
Query:
query GetAssetPrice($assetId: String!) {
assetPrice(assetId: $assetId) {
assetId
priceUSD
priceChange24h
}
}
Variables:
{
"assetId": "ethereum"
}
Sample Request (Postman):
Set the method to
POST
.Enter the URL
https://api.capsurelabs.com/graphql
.In the Headers section, add
Authorization: Bearer <token>
.In the Body section, select
raw
, chooseJSON
, and add:
{
"query": "query GetAssetPrice($assetId: String!) { assetPrice(assetId: $assetId) { assetId priceUSD priceChange24h } }",
"variables": { "assetId": "ethereum" }
}
Sample Response:
{
"data": {
"assetPrice": {
"assetId": "ethereum",
"priceUSD": 3500.75,
"priceChange24h": 2.1
}
}
}
1.4 Basic Mutations
Mutations allow developers to perform actions, such as creating NFTs or transferring assets. Each mutation requires specific input fields.
1.4.1 Mutation: Create NFT
Description: Creates a new NFT on the platform with specified metadata.
Mutation:
mutation CreateNFT($input: NFTInput!) {
createNFT(input: $input) {
nftId
status
message
}
}
Variables:
{
"input": {
"name": "CapsureLabs NFT",
"description": "A unique NFT asset",
"metadata": {
"image": "https://cdn.capsurelabs.com/nft-images/nft-image.png",
"attributes": [
{ "trait_type": "Background", "value": "Blue" },
{ "trait_type": "Edition", "value": "Genesis" }
]
}
}
}
Sample Response:
{
"data": {
"createNFT": {
"nftId": "0xabc123def",
"status": "success",
"message": "NFT created successfully."
}
}
}
1.5 Real-Time Data Subscriptions (Using WebSocket)
CapsureLabs supports GraphQL subscriptions for real-time data. Subscriptions are useful for receiving live updates on asset prices, new transfers, or NFT activities.
Real-Time Price Updates
Subscription:
subscription OnPriceUpdate($assetId: String!) {
onPriceUpdate(assetId: $assetId) {
assetId
priceUSD
priceChange24h
}
}
Variables:
{
"assetId": "ethereum"
}
Sample Response:
{
"data": {
"onPriceUpdate": {
"assetId": "ethereum",
"priceUSD": 3550.25,
"priceChange24h": 1.5
}
}
}
Last updated