Create new Video Project using API

This article explains how you can create a video project using DynTube API.

The first step is to make sure that you use Bearer authentication in your API request as explained here.

To create a project, you need to make a HTTP POST request with JSON data to following URL if you are using version 1 of API.
Make sure to set "Content-Type" of request to "application/json".


https://api.dyntube.com/v1/projects

Here is a JSON sample to create a project in US East using a standard plan. See explanation of fields below.


    {
        
        "name": "Wow Videos",
        "description": "This is a demo project",
        "region": "use-s",
        "planType": 1,
        "options": {
            "hlsEncrypt": false,
            "do240p": true,
            "do360p": true,
            "do540p": true,
            "do720p": true,
            "do1080p": true
        }
    }

If the project is successfully created, you should receive a response with status code of 200. The body will contain the Id of the newly created project.

If you are wondering what region code & plan type you should specify for the project. You can find list of region codes & plan types here.

  • PlanType: It should be "1" for standard plans and "2" for edge plans.
  • hlsEncrypt: Use this parameter if you want to turn ON HLS encryption on videos.
  • do240p -to- do1080p: Use to enable to disable certain video qualities.

Here are some code examples

Remember to replace {{token}} with actual value.

cURL
    

        curl --location --request POST 'https://api.dyntube.com/v1/projects' \
        --header 'Authorization: Bearer {{token}}' \
        --header 'Content-Type: application/json' \
        --data-raw '    {

        "name": "My Videos",
        "description": "This is my project",
        "region": "use-s", // you can change it for edge plans if needed
        "planType": 1, // 1 for standard plans, 2 for edge plans
        "options": {
        "blockedCountries": [], //2 letter country codes
        "hlsEncrypt": false,
        "do240p": true,
        "do360p": true,
        "do540p": true,
        "do720p": true,
        "do1080p": true,
        "do1440p": false,
        "do2160p": false,
        "do4320p": false
        }
        }'

    
C# - using RestSharp Library
    
        var client = new RestClient("https://api.dyntube.com/v1/projects");
        client.Timeout = -1;
        var request = new RestRequest(Method.POST);
        request.AddHeader("Authorization", "Bearer {{token}}");
        request.AddHeader("Content-Type", "application/json");
        request.AddParameter("application/json", "    {\r\n        \r\n        \"name\": \"My Videos\",\r\n        \"description\": \"This is my project\",\r\n        \"region\": \"use-s\", // you can change it for edge plans if needed \r\n        \"planType\": 1, // 1 for standard plans, 2 for edge plans \r\n        \"options\": {\r\n            \"blockedCountries\": [], //2 letter country codes \r\n            \"hlsEncrypt\": false,\r\n            \"do240p\": true,\r\n            \"do360p\": true,\r\n            \"do540p\": true,\r\n            \"do720p\": true,\r\n            \"do1080p\": true,\r\n            \"do1440p\": false,\r\n            \"do2160p\": false,\r\n            \"do4320p\": false\r\n        }\r\n    }",  ParameterType.RequestBody);
        IRestResponse response = client.Execute(request);
        Console.WriteLine(response.Content);


    
NodeJs - using Axios
    

        var axios = require('axios');
        var data = '{\r\n    "name": "My Videos",\r\n    "description": "This is my project",\r\n    "region": "use-s", // you can change it for edge plans if needed \r\n    "planType": 1, // 1 for standard plans, 2 for edge plans \r\n    "options": {\r\n        "blockedCountries": [], //2 letter country codes \r\n        "hlsEncrypt": false,\r\n        "do240p": true,\r\n        "do360p": true,\r\n        "do540p": true,\r\n        "do720p": true,\r\n        "do1080p": true,\r\n        "do1440p": false,\r\n        "do2160p": false,\r\n        "do4320p": false\r\n    }\r\n}';

        var config = {
        method: 'post',
        url: 'https://api.dyntube.com/v1/projects',
        headers: {
        'Authorization': 'Bearer {{token}}',
        'Content-Type': 'application/json'
        },
        data : data
        };

        axios(config)
        .then(function (response) {
        console.log(JSON.stringify(response.data));
        })
        .catch(function (error) {
        console.log(error);
        });




    
PHP - HTTP_Request2
    


        setUrl('https://api.dyntube.com/v1/projects');
        $request->setMethod(HTTP_Request2::METHOD_POST);
        $request->setConfig(array(
        'follow_redirects' => TRUE
        ));
        $request->setHeader(array(
        'Authorization' => 'Bearer {{token}}',
        'Content-Type' => 'application/json'
        ));
        $request->setBody('{
        \n    "name": "My Videos",
        \n    "description": "This is my project",
        \n    "region": "use-s", // you can change it for edge plans if needed
        \n    "planType": 1, // 1 for standard plans, 2 for edge plans
        \n    "options": {
        \n        "blockedCountries": [], //2 letter country codes
        \n        "hlsEncrypt": false,
        \n        "do240p": true,
        \n        "do360p": true,
        \n        "do540p": true,
        \n        "do720p": true,
        \n        "do1080p": true,
        \n        "do1440p": false,
        \n        "do2160p": false,
        \n        "do4320p": false
        \n    }
        \n}');
        try {
        $response = $request->send();
        if ($response->getStatus() == 200) {
        echo $response->getBody();
        }
        else {
        echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
        $response->getReasonPhrase();
        }
        }
        catch(HTTP_Request2_Exception $e) {
        echo 'Error: ' . $e->getMessage();
        }

    
PHP - cURL
    

         'https://api.dyntube.com/v1/projects',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{
        "name": "My Videos",
        "description": "This is my project",
        "region": "use-s", // you can change it for edge plans if needed
        "planType": 1, // 1 for standard plans, 2 for edge plans
        "options": {
        "blockedCountries": [], //2 letter country codes
        "hlsEncrypt": false,
        "do240p": true,
        "do360p": true,
        "do540p": true,
        "do720p": true,
        "do1080p": true,
        "do1440p": false,
        "do2160p": false,
        "do4320p": false
        }
        }',
        CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer {{token}}',
        'Content-Type: application/json'
        ),
        ));

        $response = curl_exec($curl);

        curl_close($curl);
        echo $response;




    
Python - Requests
    

        import requests
        import json

        url = "https://api.dyntube.com/v1/projects"

        payload = "{\r\n    \"name\": \"My Videos\",\r\n    \"description\": \"This is my project\",\r\n    \"region\": \"use-s\", // you can change it for edge plans if needed \r\n    \"planType\": 1, // 1 for standard plans, 2 for edge plans \r\n    \"options\": {\r\n        \"blockedCountries\": [], //2 letter country codes \r\n        \"hlsEncrypt\": false,\r\n        \"do240p\": true,\r\n        \"do360p\": true,\r\n        \"do540p\": true,\r\n        \"do720p\": true,\r\n        \"do1080p\": true,\r\n        \"do1440p\": false,\r\n        \"do2160p\": false,\r\n        \"do4320p\": false\r\n    }\r\n}"
        headers = {
        'Authorization': 'Bearer {{token}}',
        'Content-Type': 'application/json'
        }

        response = requests.request("POST", url, headers=headers, data=payload)

        print(response.text)





    
Ruby - Net::HTTP
    

        require "uri"
        require "net/http"

        url = URI("https://api.dyntube.com/v1/projects")

        https = Net::HTTP.new(url.host, url.port)
        https.use_ssl = true

        request = Net::HTTP::Post.new(url)
        request["Authorization"] = "Bearer {{token}}"
        request["Content-Type"] = "application/json"
        request.body = "{\r\n    \"name\": \"My Videos\",\r\n    \"description\": \"This is my project\",\r\n    \"region\": \"use-s\", // you can change it for edge plans if needed \r\n    \"planType\": 1, // 1 for standard plans, 2 for edge plans \r\n    \"options\": {\r\n        \"blockedCountries\": [], //2 letter country codes \r\n        \"hlsEncrypt\": false,\r\n        \"do240p\": true,\r\n        \"do360p\": true,\r\n        \"do540p\": true,\r\n        \"do720p\": true,\r\n        \"do1080p\": true,\r\n        \"do1440p\": false,\r\n        \"do2160p\": false,\r\n        \"do4320p\": false\r\n    }\r\n}"

        response = https.request(request)
        puts response.read_body




    
Java - Unirest
    

        Unirest.setTimeouts(0, 0);
        HttpResponse
            response = Unirest.post("https://api.dyntube.com/v1/projects")
            .header("Authorization", "Bearer {{token}}")
            .header("Content-Type", "application/json")
            .body("{\r\n    \"name\": \"My Videos\",\r\n    \"description\": \"This is my project\",\r\n    \"region\": \"use-s\", // you can change it for edge plans if needed \r\n    \"planType\": 1, // 1 for standard plans, 2 for edge plans \r\n    \"options\": {\r\n        \"blockedCountries\": [], //2 letter country codes \r\n        \"hlsEncrypt\": false,\r\n        \"do240p\": true,\r\n        \"do360p\": true,\r\n        \"do540p\": true,\r\n        \"do720p\": true,\r\n        \"do1080p\": true,\r\n        \"do1440p\": false,\r\n        \"do2160p\": false,\r\n        \"do4320p\": false\r\n    }\r\n}")
            .asString();





Dart - http
    

        var headers = {
        'Authorization': 'Bearer {{token}}',
        'Content-Type': 'application/json'
        };
        var request = http.Request('POST', Uri.parse('https://api.dyntube.com/v1/projects'));
        request.body = '''{\r\n    "name": "My Videos",\r\n    "description": "This is my project",\r\n    "region": "use-s", // you can change it for edge plans if needed \r\n    "planType": 1, // 1 for standard plans, 2 for edge plans \r\n    "options": {\r\n        "blockedCountries": [], //2 letter country codes \r\n        "hlsEncrypt": false,\r\n        "do240p": true,\r\n        "do360p": true,\r\n        "do540p": true,\r\n        "do720p": true,\r\n        "do1080p": true,\r\n        "do1440p": false,\r\n        "do2160p": false,\r\n        "do4320p": false\r\n    }\r\n}''';
        request.headers.addAll(headers);

        http.StreamedResponse response = await request.send();

        if (response.statusCode == 200) {
        print(await response.stream.bytesToString());
        }
        else {
        print(response.reasonPhrase);
        }