Home / Documentation

API Documentation

Welcome to the Fragment API documentation. Here you'll find comprehensive guides and references to help you integrate our API for purchasing Telegram Stars and Premium subscriptions.

Getting Started

The Fragment API allows you to programmatically purchase Telegram Stars and Premium subscriptions for Telegram users. The API is designed to be simple and straightforward to use.

Base URL

https://api.bohd4n.dev/api/v1

Authentication

The API uses Fragment cookies, account hash, and seed phrase for authentication. These credentials are used to make purchases on Fragment on your behalf.

Required Credentials

  • Fragment Cookies: These are the cookies from your Fragment session
  • Account Hash: The hash of your Fragment account
  • Seed Phrase: The seed phrase for your TON wallet (W5) from which the payment will be made

How to Extract Your Fragment Cookies

  1. First, connect your wallet and authorize through Telegram on fragment.com
  2. Install the Cookie-Editor extension for your browser
  3. Visit Fragment.com again
  4. Click on the Cookie-Editor extension icon in your browser
  5. Export your cookies (preferably in Header String format)
  6. Use these cookies in your API requests
Important: Never share your Fragment cookies or seed phrase with unauthorized parties.

Stars Purchase

Send Telegram Stars to any Telegram user.

Endpoint

POST /BuyStars
Parameter Type Required Description
username string Yes Target Telegram username (with or without @)
amount integer Yes Number of stars to send (minimum 50)
hash string Yes Your Fragment account hash
cookies string Yes Your Fragment cookies for authentication
seed string Yes Your TON wallet seed phrase (W5)

Example Request

python
import requests

# Send Telegram Stars to a username
response = requests.post(
    'https://api.bohd4n.dev/api/v1/BuyStars',
    json={
        'username': '@bohd4nx',  # Target username
        'amount': 50,            # Amount of stars to send (minimum 50)
        'hash': '',              # Fragment account hash
        'cookies': '',           # Your Fragment cookies
        'seed': ''               # Seed phrase for purchase
    }
)
print(response.json())

Response

json
{
    "success": true,
    "message": "50 stars sent to @bohd4nx. They will receive them within a minute.",
    "data": {
        "transaction_id": "8f7e32a19c5694bb72d7b7b30139902e55e2ffab30c5b37bc36770e25a1e89a1",
        "username": "@bohd4nx",
        "amount": 50,
        "timestamp": 1694792445
    }
}

Wallet Information

Retrieve TON wallet balance directly from the blockchain using either a seed phrase or wallet address.

Endpoint

POST /GetBalance
Parameter Type Required Description
seed string No* Your TON wallet seed phrase (W5)
address string No* TON wallet address to check balance

* At least one of these parameters must be provided

Example Request

python
import requests

# Check balance using seed phrase
response = requests.post(
    'https://api.bohd4n.dev/api/v1/GetBalance',
    json={
        'seed': 'your_wallet_seed_phrase_here'
    }
)
print(response.json())

# Alternative: Check balance using wallet address
"""
response = requests.post(
    'https://api.bohd4n.dev/api/v1/GetBalance',
    json={
        'address': 'EQAJgLBs8xqFAqFmswDPVlfrmeoDMGi-1up4HzzqYxqrC1Fs'
    }
)
"""

Response

json
{
    "success": true,
    "data": {
        "address": "EQAJgLBs8xqFAqFmswDPVlfrmeoDMGi-1up4HzzqYxqrC1Fs",
        "balance": {
            "value": 12.345,
            "currency": "TON"
        },
        "timestamp": 1747948357
    }
}

Premium Purchase

Gift Telegram Premium subscriptions to any Telegram user.

Endpoint

POST /BuyPremium
Parameter Type Required Description
username string Yes Target Telegram username (with or without @)
duration integer Yes Duration in months (3, 6, or 12)
hash string Yes Your Fragment account hash
cookies string Yes Your Fragment cookies for authentication
seed string Yes Your TON wallet seed phrase (W5)

Example Request

python
import requests

# Gift Telegram Premium subscription to a user
response = requests.post(
    'https://api.bohd4n.dev/api/v1/BuyPremium',
    json={
        'username': '@bohd4nx',  # Target username
        'duration': 3,           # Duration in months (3, 6, or 12)
        'hash': '',              # Fragment account hash
        'cookies': '',           # Your Fragment cookies
        'seed': ''               # Seed phrase for purchase
    }
)
print(response.json())

Response

json
{
    "success": true,
    "message": "3 months premium sent to @bohd4nx. They will receive it within a minute.",
    "data": {
        "transaction_id": "6a9d37f1c32e507b7d4b5c6a90a45c7f8e12d6ba31f98c43e56b9ca7d11e47ab",
        "username": "@bohd4nx",
        "duration": 3,
        "timestamp": 1694792522
    }
}

Error Handling

The API uses standard HTTP status codes and returns detailed error messages in case of failure.

Error Response Format

json
{
    "success": false,
    "error": {
        "type": "ERROR_TYPE",
        "code": 400,
        "message": "Human-readable error message"
    }
}

Common Error Examples

Bad Request Errors Status: 400

Missing Required Fields

json
{
    "success": false,
    "error": {
        "type": "INVALID_REQUEST",
        "code": 400,
        "message": "Missing required fields: cookies, seed, hash"
    }
}

Invalid Amount (Stars)

json
{
    "success": false,
    "error": {
        "type": "INVALID_REQUEST",
        "code": 400,
        "message": "Stars amount must be at least 50"
    }
}

Invalid Seed Phrase

json
{
    "success": false,
    "error": {
        "type": "INVALID_REQUEST",
        "code": 400,
        "message": "Invalid seed phrase: Mnemonic length should be equal to 24"
    }
}

Wallet Not Found

json
{
    "success": false,
    "error": {
        "type": "INVALID_REQUEST",
        "code": 400,
        "message": "No wallet found for the provided seed/address"
    }
}

Missing Parameters (GetBalance)

json
{
    "success": false,
    "error": {
        "type": "INVALID_REQUEST",
        "code": 400,
        "message": "At least one of these fields must be provided: seed, address"
    }
}
Authentication Failed Status: 401
json
{
    "success": false,
    "error": {
        "type": "AUTHENTICATION_FAILED",
        "code": 401,
        "message": "Authentication failed"
    }
}
Insufficient Funds Status: 402
json
{
    "success": false,
    "error": {
        "type": "INSUFFICIENT_FUNDS",
        "code": 402,
        "message": "Insufficient balance: 0.1 TON available, 9.17 TON required"
    }
}
User Not Found Status: 404
json
{
    "success": false,
    "error": {
        "type": "USER_NOT_FOUND",
        "code": 404,
        "message": "Invalid recipient: User not found or cannot receive stars"
    }
}
Server Errors Status: 500+

Internal Server Error (500)

json
{
    "success": false,
    "error": {
        "type": "INTERNAL_ERROR",
        "code": 500,
        "message": "Failed to retrieve wallet balance"
    }
}

Blockchain Transaction Error (502)

json
{
    "success": false,
    "error": {
        "type": "BLOCKCHAIN_ERROR",
        "code": 502,
        "message": "Transaction failed: external message was not accepted"
    }
}
Note: Always handle API errors properly in your application and display user-friendly messages to your users.

© 2025 Fragment API. All rights reserved.

Built with by @bohd4nx

Not affiliated with Telegram or Fragment.