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
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
- First, connect your wallet and authorize through Telegram on fragment.com
- Install the Cookie-Editor extension for your browser
- Visit Fragment.com again
- Click on the Cookie-Editor extension icon in your browser
- Export your cookies (preferably in Header String format)
- Use these cookies in your API requests
Stars Purchase
Send Telegram Stars to any Telegram user.
Endpoint
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
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
{
"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
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
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
{
"success": true,
"data": {
"address": "EQAJgLBs8xqFAqFmswDPVlfrmeoDMGi-1up4HzzqYxqrC1Fs",
"balance": {
"value": 12.345,
"currency": "TON"
},
"timestamp": 1747948357
}
}
Error Handling
The API uses standard HTTP status codes and returns detailed error messages in case of failure.
Error Response Format
{
"success": false,
"error": {
"type": "ERROR_TYPE",
"code": 400,
"message": "Human-readable error message"
}
}
Common Error Examples
Bad Request Errors Status: 400
Missing Required Fields
{
"success": false,
"error": {
"type": "INVALID_REQUEST",
"code": 400,
"message": "Missing required fields: cookies, seed, hash"
}
}
Invalid Amount (Stars)
{
"success": false,
"error": {
"type": "INVALID_REQUEST",
"code": 400,
"message": "Stars amount must be at least 50"
}
}
Invalid Seed Phrase
{
"success": false,
"error": {
"type": "INVALID_REQUEST",
"code": 400,
"message": "Invalid seed phrase: Mnemonic length should be equal to 24"
}
}
Wallet Not Found
{
"success": false,
"error": {
"type": "INVALID_REQUEST",
"code": 400,
"message": "No wallet found for the provided seed/address"
}
}
Missing Parameters (GetBalance)
{
"success": false,
"error": {
"type": "INVALID_REQUEST",
"code": 400,
"message": "At least one of these fields must be provided: seed, address"
}
}
Authentication Failed Status: 401
{
"success": false,
"error": {
"type": "AUTHENTICATION_FAILED",
"code": 401,
"message": "Authentication failed"
}
}
Insufficient Funds Status: 402
{
"success": false,
"error": {
"type": "INSUFFICIENT_FUNDS",
"code": 402,
"message": "Insufficient balance: 0.1 TON available, 9.17 TON required"
}
}
User Not Found Status: 404
{
"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)
{
"success": false,
"error": {
"type": "INTERNAL_ERROR",
"code": 500,
"message": "Failed to retrieve wallet balance"
}
}
Blockchain Transaction Error (502)
{
"success": false,
"error": {
"type": "BLOCKCHAIN_ERROR",
"code": 502,
"message": "Transaction failed: external message was not accepted"
}
}