Subscriptions

Attach Plan To Member

To Assign a Plan to a Member

Attach an existing plan to an existing member to grant the access defined by that plan. Save the returned member-plan ID for later status checks and lifecycle actions.

POST https://api.dyntube.com/v1/member-plans

Send the request body as application/json. The example below shows the expected payload.

Headers

Name / Type / Description
NameTypeDescription
AuthorizationStringBearer YOUR_API_KEY
Content-TypeStringapplication/json

Sample Request Body

Here is a sample JSON request to create a member-plan.

json
{
  "memberId": "memberId1",
  "name": "Premium Access",
  "planId": "planId1",
  "status": 1
}

Code Samples

C\#

csharp
using System;
using System.Net.Http;
using System.Text;
using Newtonsoft.Json;

//Note: You will need to add the Newtonsoft.Json package from NuGet to use the `JsonConvert.SerializeObject` method.

namespace CreateMemberPlanExample
{
    class Program
    {
        static async System.Threading.Tasks.Task Main(string[] args)
        {
            string url = "https://api.dyntube.com/v1/member-plans";

            var data = new
            {
                memberId = "memberId1",
                name = "Premium Access",
                planId = "planId1",
                status = 1
            };

            using (var httpClient = new HttpClient())
            {
                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
                var content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
                var response = await httpClient.PostAsync(url, content);

                if (response.IsSuccessStatusCode)
                {
                    Console.WriteLine("Member plan created successfully.");
                }
                else
                {
                    Console.WriteLine($"Failed to create member plan. Status code: {response.StatusCode}");
                }
            }
        }
    }
}

Node.js

javascript
const axios = require('axios');

const data = {
    memberId: 'memberId1',
    name: 'Premium Access',
    planId: 'planId1',
    status: 1
};

axios.post('https://api.dyntube.com/v1/member-plans', data, {
    headers: { Authorization: 'Bearer YOUR_API_KEY' }
})
    .then((response) => {
        console.log('Member plan created successfully.');
    })
    .catch((error) => {
        console.log(`Failed to create member plan. Status code: ${error.response?.status}`);
    });

Python

python
import requests
import json

url = "https://api.dyntube.com/v1/member-plans"

payload = {
    "memberId": "memberId1",
    "name": "Premium Access",
    "planId": "planId1",
    "status": 1
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_API_KEY"
}

response = requests.post(url, data=json.dumps(payload), headers=headers)

if response.status_code == 200:
    print("Member-plan created successfully.")
else:
    print(f"Failed to create member-plan. Status code: {response.status_code}")

PHP

php
$url = 'https://api.dyntube.com/v1/member-plans';

$data = array(
    "memberId" => "memberId1",
    "name" => "Premium Access",
    "planId" => "planId1",
    "status" => 1
);
$data_json = json_encode($data);

$headers = array(
    'Content-Type: application/json',
    'Authorization: Bearer YOUR_API_KEY'
);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($http_code == 200) {
    echo "Member-plan created successfully.";
} else {
    echo "Failed to create member-plan. Status code: " . $http_code;
}
  • Create a plan if the plan does not exist yet.
  • Create a member if the member does not exist yet.
  • Get a member plan to verify the assigned plan.
  • Manage member plan lifecycle to pause, resume, or cancel access.

Something missing or wrong here? Tell us and we will correct it. New to DynTube? Start with uploading and embedding.