Giveaways

Create a giveaway

Changed on

Create a classic giveaway as a draft on one of your registered chats: the prize (Stars, Premium months or one star gift per winner), the number of winners, how long it runs once it opens, and up to three entry conditions. Nothing is public until it is funded; a draft you never fund is cancelled 72 hours after its creation (giveaway.cancelled, reason draft_expired), which frees its place under the cap on live giveaways. The answer carries entry_url (the link entrants open) and proof_url (the public provably-fair page).

Conditions. At most one membership gate (chat_member: the entrant must be a member of the listed registered chats) and up to two attestation conditions you assert per entrant with POST /v1/giveaways/{id}/attestations — your own logic, for example an action in your app. MyStars applies an attestation as you send it and does not verify it; the proof page says so. entry_and_close makes entry wait for a satisfied attestation; close_only admits the entrant and filters anyone still un-attested when the giveaway closes.

Anti-bot. shadow (default) scores entrants and flags likely bots without removing anyone; enforce filters entrants scoring at or above threshold. Conditions and the anti-bot policy are fixed once the giveaway is committed and are shown on the proof page. Attestation conditions, enforce mode and gift prizes are enabled on request (503 partner_conditions_unavailable / antibot_enforce_unavailable / prize_type_unavailable until then).

Idempotency. Idempotency-Key is required. The key stays bound to the giveaway it created: the same key with the same body always returns that giveaway, a different body is 409 idempotency_conflict. Keys starting with series: (lower case, after trimming) are reserved (400). Live (unfinished) giveaways per tenant are capped (409 limit_reached with limit).

Refusals. Nothing is created on any of these. 400 bad_request — a field problem: message starts with the field (channel_id: …, duration_sec: …) and field names it, with details.code when the refusal has one; a condition refusal starts with its own code instead (duplicate_condition_key, duplicate_condition_chat, condition_needs_a_chat, condition_chat_removed, condition_chat_not_joinable, invalid_partner_condition, too_many_conditions, …). channel_id that is not one of your chats, or a chat your account no longer administers, is a 400 on channel_id. 404 not_found — a conditions[].channel_ids entry that is not one of your registered chats. 409 conflict (message starting channel_not_gateable:) — a condition chat our bot or your account no longer administers. 422 channel_checks_failed with checks — our bot is not an administrator of channel_id. 503 unavailable — Telegram could not be asked to confirm a chat (retry).

post/v1/giveaways

Request

  • Base URL
    https://api.mystars.tg
  • Auth
    API key in header X-Api-Key

Headers

Idempotency-Keystring required

A unique key for this write, at most 255 characters, scoped to your tenant. Retrying with the same key and the same request returns the original answer instead of acting twice; the same key with a different request is 409 idempotency_conflict while the key is held (its first request still running, or its answer kept). On the giveaway and series writes, while the first request with the key is still running, a retry is 409 idempotency_in_flight with Retry-After: 1 — retry with the same key. A campaign create or recipient append retry waits for the first one and gets its answer. Derive the key from your own record id to stay safe across process restarts.

How long a key is remembered: a campaign create or recipient append key stays bound to what it created, and so does a giveaway or series create key. On the other giveaway and series writes (chat register and re-check, fund, cancel, close, auto-post, attestations, the series pause, resume and cancel) only a 2xx answer is remembered, for 7 days; after that the same key runs the request again. Within those 7 days a same-key retry of a write that timed out or answered 503 gets the first 2xx the write produced, as it was, normally instead of a second run of the write or a state refusal caused by the first attempt having landed. In the rare case that 2xx could not be recorded, the retry answers 409 idempotency_in_flight for up to 5 minutes and then runs the write again; if the first attempt stopped answering altogether, or its 2xx could not be stored by the API, that wait is up to 10 minutes. A refusal (any 4xx) and a 5xx are never kept: after one, the same key runs the request again against the state at that moment, so once you have fixed the cause you may send the corrected request with the same key.

An answer replayed from the API's stored copy of an earlier 2xx carries Idempotent-Replayed: true; a first answer recovered after the API answered 503 or timed out comes without it. Do not use the header to decide whether the write was applied; read the body.

Request body

channel_idstring uuid required

A registered chat.

titlestring nullable

At most 80 characters once runs of whitespace (line breaks included) are collapsed to one space; the raw string is capped at 320. May not contain NUL or unpaired surrogate characters. A refusal is 400 on title.

prize_type'stars' | 'premium' | 'gift' required

stars (Stars per winner), premium (Premium months per winner) or gift (one star gift per winner).

prize_quantity_per_winnerinteger required

Stars per winner (50–1,000,000), Premium months per winner (a term on sale: 3, 6 or 12 today), or 1 for a gift. Outside that it is 400 on prize_quantity_per_winner, with details.code stars_per_winner_min / stars_per_winner_max (params.min / params.max) or premium_term_invalid (params.terms, the terms on sale).

winner_countinteger required

At most max_winners (channel list); above it 400 on winner_count with details.code winner_count_max (params.max).

duration_secinteger required

How long the giveaway runs once it opens: at least 60 seconds and at most 7 days (604,800 s); outside that it is 400 on duration_sec.

external_refstring nullable

Your own reference, echoed on every read and event. May not contain NUL or unpaired surrogate characters.

listedboolean

Show it on the public giveaways index (the proof page stays reachable by link).

entries_eventsboolean

Send batched giveaway.entries events.

Response

Idempotent replay — the giveaway this key created.

idstring uuid required
public_idstring required
status'draft' | 'awaiting_funding' | 'open' | 'closed' | 'drawn' | 'settling' | 'settled' | 'cancelled' required

draft → awaiting_funding (the first fund opened its funding order) → open (paid and public) → closed (entrant list frozen) → drawn (winners picked from a TON block beacon) → settling (prizes being delivered) → settled. cancelled only from draft or awaiting_funding: by you, an expired draft (a draft never funded is cancelled 72 hours after its creation), or a funding order that expired unpaid after its 2-hour window or was reversed (giveaway.cancelled reason cancelled, draft_expired or funding_expired). An open giveaway always runs on to settled; it ends with close, never cancel. Fund and cancel apply in draft and awaiting_funding, close in open, attestations in draft, awaiting_funding and open. Terminal: settled, cancelled.

external_refstring nullable required
listedboolean
entries_eventsboolean
titlestring nullable
prize_type'stars' | 'premium' | 'gift' required

stars (Stars per winner), premium (Premium months per winner) or gift (one star gift per winner).

prize_quantity_per_winnerinteger required
winner_countinteger required
channel_idstring uuid nullable
series_idstring uuid nullable
series_indexinteger nullable
duration_secinteger nullable
created_atstring date-time nullable
opens_atstring date-time nullable
closes_atstring date-time nullable
closed_atstring date-time nullable
commit_hashstring nullable

The provably-fair commitment, set when the giveaway opens.

entry_urlstring nullable required

The link entrants open.

proof_urlstring required

The public verification page.

conditions_format'v1' | 'v2' required

v2 when an attestation condition is part of the commitment.

Changes