TGmembership API Reference

Integrate your Telegram bot with your website and sell subscriptions quickly and efficiently.


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. To get an API key, open the settings menu of your bot and select the API sub-menu.


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 HTTP method, 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".


Available Methods


Sample Request

curl https://api.tgmembership.com\
/bot1234567890\
/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN\
/getPlans?plan_id=1
                    
Sample Response
{
  "ok": true,
  "code": 200,
  "result": [
    {
      "plan_id": 1,
      "plan_name": "Weekly plan",
      "duration": "1 week",
      "cost": 9.99,
      "currency": "USD",
      "recurring": 0
    },
    {
      "plan_id": 2,
      "plan_name": "Monthly plan",
      "duration": "1 month",
      "cost": 35,
      "currency": "EUR",
      "recurring": 0
    },
    {
      "plan_id": 3,
      "plan_name": "Quarterly  plan",
      "duration": "3 months",
      "cost": 125,
      "currency": "GBP",
      "recurring": 0
    }
  ]
}
GET /getPlans 

Returns a list of your plans.

 
ParameterTypeRequired?Description
plan_idIntegerNoFilters the response by plan_id.
If not provided, all results will be displayed.
limitIntegerNoA limit on the number of objects to be returned. Limit can range between 1 and 100.
If not provided, all results will be displayed.

To create a new plan, use the /plans command of your TGmembership bot. The new plan will be immediately available in the API.

Sample Request

curl https://api.tgmembership.com\
/bot1234567890\
/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN\
/addMember?plan_id=1
                    
Sample Response
{
  "ok":true,
  "code":200,
  "result":{
    "bot_username":"yourbotname",
    "access_token":"abcdefghijklmnopqrstuvwxyz",
    "link":"https:\/\/t.me\/yourbotname?start=accesstoken_abcdefghijklmnopqrstuvwxyz"
  }
}
GET /addMember 

Adds a new member.

 
ParameterTypeRequired?Description
plan_idIntegerYesThe ID of the plan you want to bond with this access token.

Using this method, you will be able to create access tokens that can later be shared with your subscribers. When the access token is used, your bot will activate the plan you selected when creating the code (plan_id parameter).

Sample Request

curl https://api.tgmembership.com\
/bot1234567890\
/abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMN\
/getSubscribers
                    
Sample Response
{
  "ok": true,
  "code": 200,
  "result": {
    "12345678": {
      "plan_id": 1
    },
    "123456789": {
      "plan_id": 2
    },
    "1234567890": {
      "plan_id": 1
    }
  }
}
GET /getSubscribers 

Lists all active subscribers

 

Using this method, you can retrieve a list of all customers who have active subscriptions. The key of each object in the response from the API server indicates the Telegram ID of your subscriber.