{"openapi":"3.1.0","info":{"title":"MGRAM API","version":"1","description":"Monetize Telegram bots and Mini Apps: paid force-subscribe tasks (POST /tasks, /tasks/check), Reply Ads (POST /reply-ads/show), webhooks, stats and the Partner API for bot builders. Guide with code: https://mgram.biz/en/developers. Reference: https://api.mgram.biz/. Python SDK: pip install mgram-sdk (https://pypi.org/project/mgram-sdk/). JavaScript SDK: npm i mgram-sdk (https://www.npmjs.com/package/mgram-sdk). Open source: https://github.com/mgram-web/mgram-sdk","contact":{"name":"MGRAM","url":"https://t.me/mgram"}},"servers":[{"url":"https://api.mgram.biz"}],"externalDocs":{"description":"Open-source SDK and bot templates (aiogram 3, python-telegram-bot, grammY, Telegraf, Mini App)","url":"https://github.com/mgram-web"},"security":[{"bearer":[]}],"components":{"securitySchemes":{"bearer":{"type":"http","scheme":"bearer","description":"Bot API key (@mgram → bot stats → Settings → API access) or Partner API key"}},"schemas":{"Envelope":{"type":"object","properties":{"ok":{"type":"boolean"},"data":{"type":"object"},"error":{"type":"object","properties":{"code":{"type":"string"},"message":{"type":"string"}}}}}}},"paths":{"/bot":{"get":{"summary":"Bot information","description":"Current safe state of the connected bot plus current-owner earnings. The full bot token and API key are never returned.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — id, username, display_name, status, reject_reason?, category?, speed?, send_times[], transport_mode, tg_bot_id?, participates_in_mailing, mailing_supported, is_public, show_own_orders, price_per_letter_rub, reply_ads_enabled, services{broadcasts,reply_ads}, audience{total,premium,ru,en,quality}, total_earned, total_earned_usd, api_key_prefix, api_enabled, api_key_created_at?, api_key_last_used_at?, created_at?","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}}}},"/bot/settings":{"post":{"summary":"Update bot settings","description":"Updates owner-editable settings only. The individual catalog price accepts only values supported by the MGRAM UI.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — updated:string[]","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"send_times":{"type":"array","items":{"type":"string"}},"is_public":{"type":"boolean"},"show_own_orders":{"type":"boolean"},"participates_in_mailing":{"type":"boolean"},"price_per_letter_rub":{"type":"number"},"reply_ads_enabled":{"type":"boolean"}},"required":["send_times","is_public","show_own_orders","participates_in_mailing","price_per_letter_rub","reply_ads_enabled"]}}}}}},"/bot/time_slots":{"get":{"summary":"Broadcast time slots","description":"Returns available broadcast slots and the current selection.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — supported:boolean, available:string[], selected:string[]","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}}}},"/bot/stop_mailing":{"post":{"summary":"Stop new broadcasts","description":"Stops the bot from joining new broadcasts; already assigned orders continue.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — participates_in_mailing:false, send_times:string[]","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}}}},"/bot/token":{"post":{"summary":"Update Telegram token","description":"Replaces the Telegram bot token after verifying that it belongs to the same Telegram bot.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — updated, username, status, recovery_queued","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"token":{"type":"string"}},"required":["token"]}}}}}},"/audience":{"get":{"summary":"Bot audience","description":"Audience aggregates without user IDs. Geography uses geo_country first, with a legacy geo fallback for rows not normalized yet.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — total, premium, verified, has_avatar, has_bio, has_gifts, quality_good, blocked, geo{}","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}}}},"/orders":{"get":{"summary":"Broadcast orders","description":"Broadcast orders in which this bot participated.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — Normal order: items[{id,status,category,requested_count,bot_sent_count,...}]. Commercial-volume order: items[{id,status,category,commercial_volume:true,paid_letters,paid_letter_rate_rub,...}]. Always: total, limit, offset.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"parameters":[{"name":"limit","in":"query","required":true,"schema":{"type":"integer","description":"1…100 (default 20)"}},{"name":"offset","in":"query","required":true,"schema":{"type":"integer","description":"≥0"}}]}},"/orders/{id}":{"get":{"summary":"Broadcast order details","description":"Broadcast order details and metrics scoped to this bot.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — Always: id, status, category, created_at?, started_at?, finished_at?. Normal order: requested_count, total_sent_count, bot{sent_count,assigned_count,premium_sent,geo{}}. For commercial volume: commercial_volume, paid_letters, paid_letter_rate_rub; technical delivery is not part of the public contract.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}},{"name":"id","in":"query","required":true,"schema":{"type":"string"}}]}},"/orders/{id}/report":{"get":{"summary":"Broadcast delivery report","description":"Global aggregate report for a normal broadcast. For a commercial-volume order, only the current bot settlement volume is returned; technical delivery is not exposed.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — id, status, category, total_requested, total_sent, premium_sent, geo{}, blocked, bots_count, duration_sec?, created_at?, started_at?, finished_at?","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}},{"name":"id","in":"query","required":true,"schema":{"type":"string"}}]}},"/reply-ads/orders":{"get":{"summary":"ReplyAds orders","description":"Bot-scoped ReplyAds orders with this bot’s aggregates only; recipient IDs, other bots and platform margin are never exposed.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — items[{id,status,currency,requested_count,bot_delivered_count,bot_confirmed_count,bot_failed_count,bot_cancelled_count,bot_earned,created_at?,starts_at?,ends_at?,settled_at?}], total, limit, offset","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"parameters":[{"name":"limit","in":"query","required":true,"schema":{"type":"integer","description":"1…100 (default 20)"}},{"name":"offset","in":"query","required":true,"schema":{"type":"integer","description":"≥0"}}]}},"/reply-ads/orders/{id}":{"get":{"summary":"ReplyAds order details","description":"ReplyAds details are available only to a bot that was assigned to or participated in the order.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — id, status, currency, requested_count, created_at?, starts_at?, ends_at?, settled_at?, bot{delivered_count,confirmed_count,failed_count,cancelled_count,earned,currency}","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}},{"name":"id","in":"query","required":true,"schema":{"type":"string"}}]}},"/stats/reply-ads":{"get":{"summary":"ReplyAds statistics","description":"Daily ReplyAds delivery aggregates. Money is intentionally separate; use /stats/income for credited earnings.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — period, days[{date,delivered,confirmed,failed,cancelled}], total_delivered, total_confirmed, total_failed, total_cancelled","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"parameters":[{"name":"period","in":"query","required":true,"schema":{"type":"string","description":"| 7d | 30d (default 30d)"}}]}},"/stats/mailings":{"get":{"summary":"Broadcasts by day","description":"Broadcast delivery statistics by Europe/Moscow calendar date.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — period, days[{date,sent}], total","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"parameters":[{"name":"period","in":"query","required":true,"schema":{"type":"string","description":"| 7d | 30d (default 30d)"}}]}},"/stats/mailings/today":{"get":{"summary":"Broadcasts today","description":"Hourly completed broadcast sends for today in Europe/Moscow.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — hours[{hour,sent}], total","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}}}},"/stats/income":{"get":{"summary":"Income by day","description":"Actually credited income by service: mailings, ReplyAds shows, subscribers and bot starts (tasks and the subscription gate, RUB only, net of unsubscribe penalties), the Emoji bonus. RUB and USD keep their frozen historical currency and are never mixed.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — period, currency, days[{date,income,sources{mailings,reply_ads,subscribers,bot_starts,emoji_bonus}}], total, sources{…}","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"parameters":[{"name":"period","in":"query","required":true,"schema":{"type":"string","description":"| 7d | 30d (default 30d)"}}]}},"/stats/income/today":{"get":{"summary":"Income today","description":"Actually credited hourly income today in the selected historical payout currency, subscribers and bot starts included (RUB).","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — currency, hours[{hour,income}], total","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}}}},"/earnings":{"get":{"summary":"Bot earnings","description":"Credited today, pending active-order estimate and current-owner lifetime earnings in the selected historical currency.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — currency, today, pending, total_earned","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}}}},"/balance":{"get":{"summary":"Owner balance","description":"canonical_balance_rub is the source of truth. Owner balance is blocked for a factory-held bot key when the bot belongs to a factory client; use earnings/statistics.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — balance(compat RUB), held_balance(compat RUB), canonical_balance_rub, display_amount, display_currency, display_rate_status, canonical_fallback_amount, display_unavailable_message","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}}}},"/key/regenerate":{"post":{"summary":"Regenerate Bot API key","description":"Creates a new Bot API key. The full key is returned only in this response.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — api_key, warning","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}}}},"/tasks":{"post":{"summary":"Get tasks","description":"Tasks for the user who is talking to your bot now. Show them as buttons — the link and button text are in the response. A repeated call returns the same list. A task is not issued to a user who is banned in a channel or chat of the advertiser. We pay only for an action Telegram confirmed: a subscription, a join, a bot start. Not paid: the person was already subscribed; farms and bots (anti-fraud check); the same task a second time — even through another bot; after the order is stopped or the list expired; a volley of completions in one bot. If the anti-fraud check does not know the person yet, the payout waits ~3 min (payout = verifying). Left within 24 h — the money goes back to the advertiser and the payout is cancelled (task.refunded).","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — status (tasks · completed · no_tasks), skip, tasks[{id,type,title,username,link,button_text,reward,currency,status,payout,earned,reward_usd,earned_usd}], reward_pending, earned, earned_verifying, reward_pending_usd, earned_usd, earned_verifying_usd, usd_rub_rate","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"user_id":{"type":"integer"},"limit":{"type":"integer","description":"1…10 (default from gate settings, 3)"},"language_code":{"type":"string"},"is_premium":{"type":"boolean"},"first_name":{"type":"string"},"username":{"type":"string"},"init_data":{"type":"string"}},"required":["user_id"]}}}}}},"/tasks/check":{"post":{"summary":"Check completion","description":"Fresh task statuses. Call it on a “Check” button: skip = true — all done, let the user through. Repeated and parallel calls are safe: every completion is paid once.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — Same as /tasks: status, skip, tasks[], earned","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"user_id":{"type":"integer"},"task_ids":{"type":"array","items":{"type":"integer"}},"language_code":{"type":"string"}},"required":["user_id"]}}}}}},"/reply-ads/show":{"post":{"summary":"Show an ad","description":"You pick the moment — after a useful action of the user, not on a payment or sign-up screen. MGRAM picks the ad and sends it from your bot itself. Paid per impression as usual Reply Ads: only if Telegram accepted the message. Not shown and not paid: a user the bot has not seen in the last minutes; farms and bots; more often than the frequency cap; right after a broadcast. One call per user per second, more often — 429.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — shown, reason, delivery_id, message_id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"user_id":{"type":"integer"},"message_id":{"type":"integer"},"language_code":{"type":"string"},"first_name":{"type":"string"},"username":{"type":"string"},"is_premium":{"type":"boolean"},"init_data":{"type":"string"}},"required":["user_id"]}}}}}},"/tasks/webhook":{"post":{"summary":"Events to your server","description":"An event to your server as soon as the user completes a task or leaves — no polling of /tasks/check. Empty body — current settings, url: \"\" — turn off.","tags":["bot"],"responses":{"200":{"description":"{ok: true, data: {...}} — url, secret, events[], test","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"requestBody":{"required":false,"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string"},"rotate_secret":{"type":"boolean"}}}}}}}},"/register/bot":{"post":{"summary":"Register a bot","description":"Registers a bot by token; owner_id defaults to the authenticated partner.","tags":["partner"],"responses":{"200":{"description":"{ok: true, data: {...}} — bot_id, username, status, category, category_source, api_key(one-time), partner_id, owner_id, owner_created","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"token":{"type":"string"},"partner_id":{"type":"string","description":"int"},"owner_id":{"type":"string","description":"int"},"referrer_id":{"type":"string","description":"int"}},"required":["token"]}}}}}},"/register/bots":{"get":{"summary":"Factory bots","description":"Returns all bots registered by this Partner API identity, including client-owned, pending and rejected bots. Manual and foreign-partner bots are excluded.","tags":["partner"],"responses":{"200":{"description":"{ok: true, data: {...}} — items[{bot_id,username,display_name,owner_id,status,reject_reason?,category,mailings_enabled,reply_ads_enabled,mailing_supported,service_mode,created_at?}], next_cursor?","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"parameters":[{"name":"cursor","in":"query","required":false,"schema":{"type":"string","description":"int"}},{"name":"status","in":"query","required":false,"schema":{"type":"string","description":"|pending|rejected"}},{"name":"mailings","in":"query","required":false,"schema":{"type":"string","description":"|disabled"}},{"name":"reply_ads","in":"query","required":false,"schema":{"type":"string","description":"|disabled"}}]}},"/register/bots/settings":{"post":{"summary":"Bulk bot settings","description":"Atomically enables or disables broadcasts and ReplyAds for an array of this factory’s bots. If any ID is outside the factory scope, no bot is changed.","tags":["partner"],"responses":{"200":{"description":"{ok: true, data: {...}} — updated_count, items[{bot_id,mailings_enabled,reply_ads_enabled,mailing_supported,service_mode}]","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"bot_ids":{"type":"string","description":"int[] (1…500)"},"mailings_enabled":{"type":"boolean"},"reply_ads_enabled":{"type":"boolean"}},"required":["bot_ids"]}}}}}},"/register/bot/reply-ads":{"post":{"summary":"Enable / disable ReplyAds","description":"Canonical Partner API method for ReplyAds state on a bot created by this Partner API identity.","tags":["partner"],"responses":{"200":{"description":"{ok: true, data: {...}} — bot_id, reply_ads_enabled","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"bot_id":{"type":"string","description":"int"},"enabled":{"type":"boolean"}},"required":["bot_id","enabled"]}}}}}},"/register/bot/shows":{"post":{"summary":"Deprecated ReplyAds alias","description":"Compatibility path for old clients. Use /register/bot/reply-ads for new integrations.","tags":["partner"],"responses":{"200":{"description":"{ok: true, data: {...}} — bot_id, reply_ads_enabled, shows_enabled(legacy)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"deprecated":true,"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"bot_id":{"type":"string","description":"int"},"enabled":{"type":"boolean"}},"required":["bot_id","enabled"]}}}}}},"/register/webhook/test":{"post":{"summary":"Test webhook URL","description":"Sends one webhook.test event to a public HTTPS URL. The URL is not saved.","tags":["public"],"responses":{"200":{"description":"{ok: true, data: {...}} — delivery_ok, status?, elapsed_ms, delivery_id, event, response_preview","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Envelope"}}}},"4XX":{"description":"{ok: false, error: {code, message}}"}},"security":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"url":{"type":"string","description":"string"}},"required":["url"]}}}}}}}}