Skip to content

Sell a single title

This guide shows how to sell one video to a user. There are two types: a rent for a limited time (TVOD) and a purchase without a time limit (DTO). You sell the video in your system. MEGOGO records the purchase.

Before you start

Make sure that:

  • TVOD or DTO is enabled for your keys. Ask your MEGOGO manager.
  • MEGOGO added the IP addresses of your servers to the list of your partner ID. See Credentials.
  • The user exists in the MEGOGO billing and has an access token. See Authorize a user.

Step 1. Get the offers of the video

When the user opens the page of the video, send /video/info with the access_token of the user:

GET https://api.megogo.net/v1/video/info?id={video_id}&lang=en&access_token={access_token}&sign={sign}

The offers are in purchase_info.tvod (rent) and purchase_info.dto (purchase without a time limit). Both have the same structure. Expected response for a rent (shortened):

{
  "data": {
    "id": 12345,
    "is_available": false,
    "delivery_rules": ["tvod"],
    "purchase_info": {
      "tvod": {
        "subscriptions": [
          {
            "subscription_id": 7181,
            "title": "Partner TVOD hd only",
            "currency_code": "uah",
            "is_bought": false,
            "tariffs": [
              {
                "tariff_id": 7211,
                "price": 59,
                "period": 7,
                "quality": { "group": "HD", "title": "Full HD", "bitrate": 1080 },
                "is_bought": false
              },
              {
                "tariff_id": 63835,
                "price": 39,
                "period": 7,
                "quality": { "group": "SD", "title": "SD", "bitrate": 576 },
                "is_bought": false
              }
            ]
          }
        ]
      }
    }
  }
}

Show each item of tariffs as an offer:

Field Use
price, currency_code The price
period The access period in days. For DTO, the value is large (for example 3650). Show it as "forever"
quality.title The maximum quality of the offer
is_bought true: the user already has this offer
tariff_id The ID for the purchase (step 3)

CAUTION

Use the prices and the tariff_id from /video/info only. The prices and the IDs in the XML feed are MEGOGO tariffs. Do not use them.

Step 2. The user pays

The user pays in your system for one offer from step 1.

Step 3. Record the purchase

Send this request from your server:

GET https://billing.megogo.net/partners/{partner_id}/buyMovie?userId={user_id}&videoId={video_id}&serviceId={tariff_id}
Parameter Description
userId The user identifier in your system
videoId The ID of the video
serviceId The tariff_id of the offer from step 1. Do not use subscription_id

CAUTION

The Billing API does not check that the tariff is offered for your key. Send only a tariff_id that /video/info gave for this video and this user.

Expected response:

{"successful": true}

Bill the user only after "successful": true.

Step 4. Let the user watch

Play the video with the access token of the user. See Play a video.

The quality of the offer limits the stream. For example, after the purchase of an SD offer, bitrates contains only the qualities up to 480.

WARNING

The rent period starts when the user starts to watch: at the first /stream response with src. It does not start at the purchase. Send /stream only when the user starts the playback.

Check the purchases of a user

GET https://billing.megogo.net/partners/{partner_id}/user/subscriptions?identifier={user_id}

Expected response (shortened):

{
  "identifier": "user-0001",
  "svod": [],
  "tvod": [
    {
      "serviceId": "7211",
      "serviceName": "Partner TVOD hd only",
      "objectId": 12345,
      "status": "started",
      "dateFinish": 1793958553,
      "dateFinishString": "2026-11-06 09:49:13"
    }
  ]
}
status Meaning
unwatched The user did not start to watch. The rent period did not start. No dateFinish
started The rent period started. dateFinish is the end of the rent

DTO purchases are in a separate dto array. Its items have serviceId, serviceName and objectId, but no status and no dateFinish:

"dto": [
  { "serviceId": "27561", "serviceName": "EST Disney UA 6-9", "objectId": 584181 }
]

If the user has no purchases of a type, the response has no tvod or dto key.

Errors

Response Cause Action
Code 400 The user already bought this video (TVOD or DTO) No action is necessary. The user can watch
Code 40416 serviceId is not a tariff ID of your partner ID. For example, you used subscription_id or an ID from the XML feed Use tariff_id from /video/info
Code 2015, 2029 The video has no offer for sale Do not show the offer
Code 2031 This quality is not in the offer Use a tariff_id from /video/info of this video
HTTP 401, plain text Partner … not found The IP address of your server is not in the list See Credentials
Timeout, HTTP 5xx Temporary problem Check the purchases of the user before you send the request again. Wait 1 minute between the attempts, maximum 6 attempts

For all codes, see the Billing API reference.

Next steps