Page cover

GraphQL API for Developers

1.1 API Overview

The GraphQL API allows developers to specify only the data they need, minimizing payload sizes and improving performance for both client and server. All requests to the GraphQL API require an API Key and Authorization Token in the headers.

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:

Sample Request (cURL):

Sample Response:

1.3.2 Query: Get Asset Price

Description: Fetches the current price and 24-hour change percentage of a specified asset.

Query:

Variables:

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, choose JSON, and add:

Sample Response:


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:

Variables:

Sample Response:


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:

Variables:

Sample Response:

Last updated