API
Get Started
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.
Before you can use the TGmembership API, you must have a bot and an API key created. If you don't have one yet, create your Telegram bot and connect it to TGmembership.
Generate API Endpoint
To learn how to generate an API key, please refer to our guide on creating an API key.
Authentication
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/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".
/addMember
POST
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}/addMember
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 | The "plan_id" parameter is a required input when creating an access token via the API. It should be set to the positive integer value that corresponds to the plan you want the access token to be linked to. |
member_id | Integer | This parameter allows for easy activation or extension of memberships for existing members without requiring additional user input or interaction. It represents the Telegram ID of a member who has previously interacted with the bot and has not blocked it. |
/affiliate
POST
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}affiliate
This API method allows you to register new affiliates remotely.
Request Body
Name | Type | Description |
---|---|---|
member_id* | Integer | The ID of the affiliate you want to register. This must be a user that has previously interacted with the bot. |
/countOrders
GET
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}countOrders
This method returns a list of daily/monthly/yearly revenue and sales.
Query Parameters
Name | Type | Description |
---|---|---|
interval_unit | Enum | This parameter specifies the time unit to use when retrieving revenue and sales data. The accepted values are 'day', 'week', and 'month'. |
interval_count | Integer | This parameter specifies how many intervals to look back when retrieving revenue and sales data. The value must be a positive integer. |
/countUsers
GET
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}countUsers
This API method returns the number of known users, leads, churned customers, and paying members.
/getPlans
GET
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}/getPlans
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 | An optional positive integer parameter that specifies the ID of the plan to be returned. If this parameter is not provided, all available plans will be returned. |
limit | Integer | An optional positive integer parameter that limits the number of results returned by the API. The valid range of this parameter is from 1 to 100. If this parameter is not provided, the API will return all available plans or the plan matching the 'plan_id' parameter if specified. |
/getRevenue
GET
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}/getRevenue
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 | 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 | 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. |
/getSubscribers
GET
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}/getSubscribers
Fetch all subscribers
Query Parameters
Name | Type | Description |
---|---|---|
user_id | Integer | ID of the user you are searching for. |
/mostPopularPaymentMethods
GET
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}/mostPopularPaymentMethods
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.
/order
POST
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}/order
Create a new invoice
Request Body
Name | Type | Description |
---|---|---|
plan_id* | Integer | The "plan_id" parameter is a required input when creating an invoice via the API. It should be set to the positive integer value that corresponds to the plan you want the invoice to be linked to. |
payment_gateway* | String | Choose the payment method for this invoice, such as "PayPal," "Stripe," "CryptoNoKYC," or any other installed method. Remember, the selected method must be installed in the bot to work. If you're uncertain about the available options, you can retrieve a list of installed payment methods using the GET /paymentMethods API request. |
member_id | Integer | This parameter represents the Telegram ID of a member that will be granted membership privileges upon successful completion of the order. |
String | This parameter is optional. It's only needed for specific payment methods, such as Paystack, for instance. | |
token | String | This parameter is optional. It's only needed for specific payment methods, such as crypto. When using BinancePay, pass the name of the token, e.g. "USDT." For CryptoNoKYC, include both the token name and the network, formatted as "TOKEN.NETWORK," for example, "USDT.MATIC." |
/paymentMethods
GET
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}/paymentMethods
Check your bot's payment methods
/plansPerformance
GET
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}/plansPerformance
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.
/webhook
POST
https://api.tgmembership.com/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 | The URL for your webhook endpoint. |
/webhook
DELETE
https://api.tgmembership.com/bot{{BOT_ID}}/{{API_KEY}}/webhook
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 for your webhook endpoint. |
Last updated