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":"My first plan",
      "duration":"1 month",
      "cost":"9.99",
      "currency":"EUR",
      "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 /addplan 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\
/chatsGrowth?chat_id=-1000000000000&start_date=2021-03-01limit=3&order=ASC
                    
Sample Response
{
  "ok":true,
  "code":200,
  "result":{
    "-1000000000000":{
      "0":{
        "date":"2021-03-01",
        "members":"100"
      },
      "1":{
        "date":"2021-03-02",
        "members":"116"
      },
      "2":{
        "date":"2021-03-03",
        "members":"144"
      }
    }
  }
}
GET /chatsGrowth 

Track the growth of your chats

 
ParameterTypeRequired?Description
chat_idIntegerNoFilters the response by Chat ID.
If not provided, all results will be displayed.
start_dateStringNoFilters the response by a record date. Use format YYYY-mm-dd. E.g. 2021-03-01 (1st of March 2021)
If not provided, all results will be displayed.
limitIntegerNoA limit on the number of objects to be returned. Limit can range between 1 and 31.
If not provided, 7 results will be displayed.
orderEnumNoThe objects for each chat are sorted by the date they were recorded. You can arrange them in ascending or descending order. DESC is used by default.
The possible values are:
ASC. Ascending order
DESC. Descending order

The number of users in your chats is updated once a day. Your bot only tracks the number of users in the chats it manages. If you want to add an additional chat, use the /addchat command.