As a member of the TGmembership family, you can use the API to automate your memberships' management. For example, you can connect your Telegram bot directly to your website
and give your customers access to your Telegram chats automatically.
The TGmembership API uses API keys to authenticate requests. You can view and manage your API key from your bot's settings menu.
All queries to the TGmembership API must be served over HTTPS, using GET, POST or DELETE HTTP methods, and need to be presented in this form:
https://api.tgmembership.com/{{VERSION}}/bot{{BOT_ID}}/{{API_KEY}}/{{METHOD_NAME}}
Calls made over plain HTTP will fail. API requests without authentication will also fail. All methods in the TGmembership API are case-insensitive.
The response contains a JSON object, which always has a Boolean field "ok", Integer field "code" and may have an optional String field "description" with a human-readable description of the result. If "ok" equals true, the request was successful and the result of the query can be found in the "result" field. In case of an unsuccessful request, "ok" equals false and the error is explained in the "description".
[POST] /affiliate
POST/v1/bot{{BOT_ID}}/{{API_KEY}}/affiliate
This API method allows you to register new affiliates remotely.
Request Body
Name
Type
Description
member_id*
Integer, required
The unique identifier of a member who has previously interacted with the bot and has not blocked it.
affiliate_id
String, optional
A user-chosen string that identifies the affiliate. It must start with a letter, be at least 3 characters long, no more than 12, and be unique (not used by anyone else).
{"ok":false,"request_id":"123456789","method":"POST","path":"/affiliate","code":400,"description":"Bad request: 'affiliate_id' must match pattern \"^[a-zA-Z][a-zA-Z0-9]{2,19}$\""}
Reason: The affiliate_id provided is invalid.
Solution: The affiliate_id must start with a letter and be 3 to 20 characters long, consisting of letters and numbers only.
{"ok":false,"request_id":"123456789","method":"POST","path":"/affiliate","code":401,"description":"Unauthorized: Affiliate API is not available for this bot"}
Solution: Install the affiliate add-on using the /affiliate command in your bot on Telegram.
{"ok":false,"request_id":"123456789","method":"POST","path":"/affiliate","code":404,"description":"Not Found: Member with this ID has not been found."}
Reason: The member_id provided does not belong to someone who has previously interacted with the bot or they have blocked the bot.
Solution: Ensure the member_id is correct and belongs to someone who has interacted with the bot.
{"ok":false,"request_id":"123456789","method":"POST","path":"/affiliate","code":409,"description":"Conflict: Affiliate with this ID already exists."}
Reason: The affiliate_id provided is already in use by another affiliate.
Solution: Provide a different affiliate_id that is unique.
[POST] /bot
POST/v1/bot{{BOT_ID}}/{{API_KEY}}/bot
This endpoint allows you to register a new bot. The owner of the bot that owns the API key used for this call will also be registered as the owner and billpayer for the new bot.
Body
Name
Type
Description
bot_token*
String, required
The API token generated from @BotFather in Telegram.
This API method creates a unique access token that allows users to activate memberships without payment. For more information on access tokens, please check out our help article.
Request Body
Name
Type
Description
plan_id*
Integer, required
The unique identifier of an existing plan. Must be a positive number.
member_id
Integer, optional
The unique identifier of a member who has previously interacted with the bot and has not blocked it.
{"ok":false,"request_id":"123456789","method":"POST","path":"/members/access_token","code":401,"description":"Unauthorized: Access tokens are not available for this bot."}
Reason: One reason could be that you haven't installed a payment method in your bot, or it is in test mode.
Solution: Open Telegram, open your bot, type /settings -> Test mode and switch it off. Then, go to /settings -> Payment Methods and install a payment method.
Solution: After accepting a certain number of real payments, you may be eligible to have access tokens reactivated. This may take some time. Alternatively, you can upgrade your plan to any of our Pay Monthly options, which offer unlimited access token usage for a fixed monthly fee.
{"ok":false,"request_id":"123456789","method":"POST","path":"/members/access_token","code":404,"description":"Not Found: Member with this ID has not been found"}
Reason: The member_id provided is invalid, or belongs to someone who hasn't previously interacted with the bot, or the person has blocked the bot.
Solution: Double-check the member_id provided. Ensure it's correct and that the user has previously interacted with the bot and hasn't blocked it.
[GET] /orders/:order_key
GET/orders/:order_key
This endpoint fetches a specific order based on the provided order key.
Path Parameters
Name
Type
Description
order_key
String, required
The unique key identifying the specific order to be fetched.
{"ok":false,"request_id":"123456789","method":"GET","path":"/orders/ABCD123","code":404,"description":"Not Found: The requested resource could not be found."}
Reason: The ID provided doesn't match any orders in your bot's database.
Solution: Double-check the order_key provided.
[GET] /orders
GET/v1/bot{{BOT_ID}}/{{API_KEY}}/orders
This endpoint returns the orders in the bot. If no query parameters are provided, it will return the last 100 orders in descending order. Query parameters allow customisation of the returned list.
Query Parameters
Name
Type
Description
member_id
Integer, optional
The unique identifier of a member who has previously interacted with the bot and has not blocked it.
plan_id
Integer, optional
The unique identifier of an existing plan. Must be a positive number.
project_id
Integer, optional
The unique identifier of an existing project. Must be a positive number.
order_status
String, optional
The status of the order.
currency
String, optional
Specifies the currency for converting the amounts.
limit
Integer, optional
Limits the number of results returned by the API. Must be an integer between 1 and 100. Default is 100.
offset
Integer, optional
Specifies the number of results to skip before starting to return results. Must be an integer greater than or equal to 0. Default is 0.
The unique identifier of an existing plan. Must be a positive number.
payment_gateway*
String, required
Choose the payment method for this invoice, such as "PayPal," "Stripe," "CryptoNoKYC," or any other installed method. The selected method must be installed in the bot. If unsure about available options, retrieve a list of installed payment methods using the GET /paymentMethods API request.
member_id
Integer, optional
The unique identifier of a member who has previously interacted with the bot and has not blocked it.
email
String, conditional
Required for specific payment methods, such as Paystack. Otherwise, this parameter is optional.
token
String, conditional
Needed for specific payment methods, such as crypto. For BinancePay, pass the token name, e.g., "USDT." For CryptoNoKYC, include both the token name and the network, formatted as "TOKEN.NETWORK," e.g., "USDT.MATIC."
return_url
String, optional
The URL to which the user will be redirected after successful payment. If not provided, the default TGmembership return URL will be used. Applicable only for payment methods that support custom return URLs, such as Stripe.
cancel_url
String, optional
Similar to return_url, but used if the payment process is canceled.
{"ok":false,"request_id":"123456789","method":"POST","path":"/orders","code":400,"description":"Payment gateway 'xyz' is not installed"}
Reason: The payment gateway you are trying to use to create an order is not installed in your bot.
Solution: Open your bot, type /settings -> Payment Methods and install the payment method.
{"ok":false,"request_id":"123456789","method":"POST","path":"/orders","code":400,"description":"Pre-checkout data is missing or invalid. Token needs to be selected."}
Reason: You're trying to create a crypto order without providing the token/network for the payment.
Solution: Review the token parameter; it is required when using crypto payments. Ensure the token and network are correctly specified.
[GET] /orders/count
GET/v1/bot{{BOT_ID}}/{{API_KEY}}/orders/count
This endpoint returns a list of daily, monthly, or yearly revenue and sales data.
Query Parameters
Name
Type
Description
interval_unit
Enum, optional
Specifies the unit of time for the interval. Valid values are 'day', 'month', or 'year'. Default is 'month'.
interval_count
Integer, optional
Specifies the number of intervals. Must be an integer greater than or equal to 1. Default is 1.
currency
Enum, optional
Specifies the currency for the revenue data. If not provided, the preferred currency for the bot will be used, or 'eur' if no preferred currency is set.
This API method returns a list of the most popular payment methods used for sales, along with the number of sales made using each payment method.
Query Parameters
Name
Type
Description
currency
String, optional
Specifies the currency for the revenue data. If not provided, the preferred currency for the bot will be used, or 'eur' if no preferred currency is set.
This method returns a list of all available plans, including their names, prices, and durations. It provides more detailed information about each plan and can be used for various purposes.
Query Parameters
Name
Type
Description
plan_id
Integer, optional
The unique identifier of an existing plan. Must be a positive number.
project_id
Integer, optional
The unique identifier of an existing project. Must be a positive number.
limit
Integer, optional
Limits the number of results returned by the API. Must be an integer between 1 and 100. Default is 100.
offset
Integer, optional
Specifies the number of results to skip before starting to return results. Must be an integer greater than or equal to 0. Default is 0.
This endpoint allows you to create a new subscription plan in the bot.
Request Body
Name
Type
Description
plan_name*
String, required
The name of the subscription plan. The name must be between 3 and 24 characters long, and start with a letter.
plan_duration*
String, required
The duration of the subscription plan. This is typically specified in a format like "1 month" or "1 year".
plan_price*
String, required
The price of the subscription plan. This should include the amount without currency code.
plan_currency*
String, required
The currency in which the plan price is specified, e.g., "USD".
plan_trial
String, optional
The duration of the trial period for the subscription plan, if any. This is typically specified in a format like "1 month" or "1 year".
plan_project_id
Integer, optional
The project ID associated with the subscription plan. This must be a positive integer.
options
Object, optional
A set of additional options for the subscription plan.
Options Object
Name
Type
Description
recurring
Boolean, optional
Indicates whether the subscription plan is recurring.
newcomers
Integer, optional
Specifies the availability of the plan based on user status:
0: The plan is available to everyone.
1: The plan is available to newcomers only.
2: The plan is available to returning users (those who previously held a membership or currently hold one).
singleuse
Integer, optional
Specifies the purchase limitations for the plan:
0: The plan can be purchased multiple times by a user.
1: The plan can be purchased only one time by a specific user.
2: The plan can be purchased only if the user currently holds a membership.
3: The plan can be purchased only if the user had a membership before but does not currently have an active one.
token_only
Boolean, optional
Indicates whether the plan is available for token payment only.
credit_only
Boolean, optional
Indicates whether the plan is available for credit payment only.
invitee_only
Integer, optional
Specifies the availability of the plan based on invitation status:
0: Everyone can purchase this plan.
1: Only users invited by an affiliate can purchase this plan.
2: Only users who haven't been invited by an affiliate can purchase this plan.
Response
{"request_id":"123456789","method":"POST","path":"/plans","code":201,"result": {"plan_id":77,"plan_name":"Name of the plan","duration":"1 week","price":"100","currency":"USD","options": {"recurring":false,"newcomers":0,"singleuse":0,"token_only":false,"credit_only":false,"invitee_only":0,"is_hidden":false },"max_customers":0,"sort_order":0,"enabled":true }}
[GET] /plans/report
GET/v1/bot{{BOT_ID}}/{{API_KEY}}/plans/report
This API method returns the revenue and number of sales for each subscription plan offered by your service on a monthly basis for the last 6 months.
Query Parameters
Name
Type
Description
currency
String, optional
Specifies the currency for the revenue data. If not provided, the preferred currency for the bot will be used, or 'eur' if no preferred currency is set.
{"ok":false,"request_id":"123456789","method":"GET","path":"/projects","code":401,"description":"Unauthorized: Projects API is not available for this bot"}
Reason: No projects are available in the bot's database.
Solution: Ensure that there are projects created and available in the bot.
[GET] /revenue
GET/v1/bot{{BOT_ID}}/{{API_KEY}}/revenue
This API method returns the total revenue generated and the number of sales for a specific period of time.
Query Parameters
Name
Type
Description
from*
Integer, required
UNIX timestamp indicating the start of the time period for which revenue and sales data should be retrieved. Only data generated after this time will be included in the results. If not specified, the API will default to the earliest timestamp available.
to*
Integer, required
UNIX timestamp indicating the end of the time period for which revenue and sales data should be retrieved. Only data generated before this time will be included in the results. If not specified, the API will default to the latest timestamp available.
currency
String, optional
Specifies the currency for the revenue data. If not provided, the preferred currency for the bot will be used, or 'eur' if no preferred currency is set.
This method allows you to remove an existing webhook associated with your Telegram bot. Provide the endpoint URL for the webhook you wish to delete, and the webhook will be removed from your bot.
Request Body
Name
Type
Description
url*
String
The URL of your webhook. It must be a valid URL starting with https://.
Response
{"ok":true,"code":204}
{"ok":false,"request_id":"123456789","method":"POST","path":"/webhook","code":400,"description":"Bad request: 'url' must match pattern \"^https?://\""}
Reason: The url provided is invalid.
Solution: Ensure the url starts with "https://".
{"ok":true,"request_id":"123456789","method":"DELETE","path":"/webhook","code":404,"description":"Not Found: The requested resource could not be found"}
Reason: You are trying to delete a webhook that doesn't exist in your bot's database.
Solution: N/A
[POST] /webhook
POST/v1/bot{{BOT_ID}}/{{API_KEY}}/webhook
This API method allows you to register a webhook endpoint to receive notifications for events related to your account. Once you have registered a webhook endpoint, we will send HTTP POST requests to that endpoint whenever an event of interest occurs.
Request Body
Name
Type
Description
url*
String, required
The URL of your webhook. It must be a valid URL starting with https:// and responding with HTTP 200 to requests, particularly POST.
{"ok":false,"request_id":"123456789","method":"POST","path":"/webhook","code":400,"description":"Bad request: 'url' must match pattern \"^https?://\""}
Reason: The url provided is invalid.
Solution: Ensure the url starts with "https://".
{"ok":false,"request_id":"123456789","method":"POST","path":"/webhook","code":409,"description":"You have already set a webhook for this bot."}
Reason: TGmembership only allows one webhook per bot, and you currently have one installed.
Solution: You can delete the current webhook and add a new one.