Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Dynamic Ingest API Tester</h1>
<p>Note that you must first create a video object, so other operations are disabled until you do that.</p>
<div class="buttonBlock">
  <p><strong>Ingest Video</strong></p>
  <p>
    <button id="createVideo" class="bcls-button">Create video object</button>
    <button id="ingestVideo" disabled="disabled" class="bcls-button">Ingest Video</button>
  </p>
</div>
<div class="buttonBlock">
  <p><strong>Transcode or Replace Video</strong></p>
  <p>
    <button id="retranscode" class="bcls-button" disabled="disabled">Retranscode video</button>
    <button id="replace" class="bcls-button" disabled="disabled">Replace</button>
  </p>
</div>
<div class="buttonBlock">
  <p><strong>Ingest Media Assets</strong></p>
  <p>
    <button id="addImages" class="bcls-button" disabled="disabled">Add images</button>
    <button id="addTextTracks" class="bcls-button" disabled="disabled">Add text tracks</button>
  </p>
</div>
<p><strong>API request:</strong></p>
<pre id="apiRequest" class="bcls-code" style="height:30px;min-height:30px;"></pre>
<p><strong>Input data for write requests:</strong></p>
<pre id="apiData" class="bcls-code"></pre>
<p><strong>Request method:</strong></p>
<pre id="apiMethod" class="bcls-code" style="height:20px;min-height:20px;"></pre>
<p><strong>Response data</strong></p>
<pre id="responseData" class="bcls-code"></pre>
              
            
!

CSS

              
                /* * The body style is just for the
 * background color of the codepen.
 * Do not include in your code.
 */
body {
  background-color: #111;
  color: #f5f5f5;
  font-family: sans-serif;
  margin: 2em;
}
/*
 * Styles essential to the sample
 * are below
 */
.bcls-code {
  color: #111;
  font-family: 'Source Code Pro',monospace;
  padding: 1em;
  width: 90%;
  min-height: 5em;
  background-color: #cfcfcf;
  font-size: 1rem;
}
.bcls-button {
  padding: .5em;
  background-color: #333;
  border: 1px yellow solid;
  border-radius: .5em;
  color: yellow;
  cursor: pointer;
}
fieldset {
  color: #64AAB2;
  border: 1px #64AAB2 solid;
  border-radius: .5em;
}
.buttonBlock {
  display: inline-block;
  padding: 1em;
  border-right: 1px white solid;
}

              
            
!

JS

              
                var BCLS = (function(window, document) {
  var baseURL = 'https://cms.api.brightcove.com/v1/accounts/57838016001',
    ingestURL = 'https://ingest.api.brightcove.com/v1/accounts/57838016001',
    ingestURLsuffix = '/ingest-requests',
    proxyURL = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php',
    dd_profile = 'multi-platform-standard-static',
    dd_retranscode_profile = 'multi-platform-extended-static',
    callback_url = 'https://solutions.brightcove.com/bcls/di-api/di-callback-app.php',
    newVideo_id = '',
    allButtons = document.getElementsByTagName('button'),
    createVideo = document.getElementById('createVideo'),
    ingestVideo = document.getElementById('ingestVideo'),
    retranscode = document.getElementById('retranscode'),
    replace = document.getElementById('replace'),
    addImages = document.getElementById('addImages'),
    addTextTracks = document.getElementById('addTextTracks');
  /**
   * disables all buttons so user can't submit new request until current one finishes
   */
  function disableButtons() {
      var i,
        iMax = allButtons.length;
      for (i = 0; i < iMax; i++) {
        allButtons[i].setAttribute('disabled', 'disabled');
      }
    }
    /**
     * re-enables all buttons
     */
  function enableButtons() {
      var i,
        iMax = allButtons.length;
      for (i = 0; i < iMax; i++) {
        allButtons[i].removeAttribute('disabled');
      }
    }
    /**
     * sets up the data for the API request
     * @param {String} id the id of the button that was clicked
     */
  function createRequest(id) {
      var endPoint = '',
        options = {},
        requestBody = {};
      // disable buttons to prevent a new request before current one finishes
      disableButtons();
      options.account_id = '57838016001';
      options.proxyURL = proxyURL;
      switch (id) {
        case 'createVideo':
          endPoint = '/videos';
          options.url = baseURL + endPoint;
          options.requestType = 'POST';
          requestBody.name = 'New Video from Dynamic Ingest API Quick Start';
          options.requestBody = JSON.stringify(requestBody);
          apiRequest.textContent = options.url;
          apiData.textContent = JSON.stringify(requestBody, null, '  ');
          apiMethod.textContent = options.requestType;
          makeRequest(options, function(response){
            var parsedData;
            parsedData = JSON.parse(response);
            newVideo_id = parsedData.id;
            responseData.textContent = JSON.stringify(parsedData, null, '  ');
            // re-enable the buttons
            enableButtons();
          });
          break;
        case 'ingestVideo':
          endPoint = '/videos/' + newVideo_id;
          options.url = ingestURL + endPoint + ingestURLsuffix;
          options.requestType = 'POST';
          requestBody.master = {};
          requestBody.master.url = 'https://learning-services-media.brightcove.com/videos/mp4/greatblueheron.mp4';
          requestBody.profile = dd_profile;
          requestBody.callbacks = [callback_url];
          options.requestBody = JSON.stringify(requestBody);
          apiRequest.textContent = options.url;
          apiData.textContent = JSON.stringify(requestBody, null, '  ');
          apiMethod.textContent = options.requestType;
          makeRequest(options, function(response){
            var parsedData;
            parsedData = JSON.parse(response);
            responseData.textContent = JSON.stringify(parsedData, null, '  ');
            // re-enable the buttons
            enableButtons();
          });
          break;
        case 'retranscode':
          endPoint = '/videos/' + newVideo_id;
          options.url = ingestURL + endPoint + ingestURLsuffix;
          options.requestType = 'POST';
          requestBody.master = {};
          requestBody.master.use_archived_master = true;
          requestBody.profile = dd_retranscode_profile;
          requestBody['capture-images'] = true;
          requestBody.callbacks = [callback_url];
          options.requestBody = JSON.stringify(requestBody);
          apiRequest.textContent = options.url;
          apiData.textContent = JSON.stringify(requestBody, null, '  ');
          apiMethod.textContent = options.requestType;
          makeRequest(options, function(response){
            var parsedData;
            parsedData = JSON.parse(response);
            responseData.textContent = JSON.stringify(parsedData, null, '  ');
            // re-enable the buttons
            enableButtons();
          });
          break;
        case 'replace':
          endPoint = '/videos/' + newVideo_id;
          options.url = ingestURL + endPoint + ingestURLsuffix;
          options.requestType = 'POST';
          options.master = {};
          options.master.url = 'https://learning-services-media.brightcove.com/videos/mp4/greathornedowl.mp4';
          options.profile = dd_profile;
          requestBody['capture-images'] = true;
          requestBody.callbacks = [callback_url];
          options.requestBody = JSON.stringify(requestBody);
          apiRequest.textContent = options.url;
          apiData.textContent = JSON.stringify(requestBody, null, '  ');
          apiMethod.textContent = options.requestType;
          makeRequest(options, function(response){
            var parsedData;
            parsedData = JSON.parse(response);
            responseData.textContent = JSON.stringify(parsedData, null, '  ');
            // re-enable the buttons
            enableButtons();
          });
          break;
        case 'addImages':
          endPoint = '/videos/' + newVideo_id;
          options.url = ingestURL + endPoint + ingestURLsuffix;
          options.requestType = 'POST';
          requestBody.poster = {};
          requestBody.poster.url = 'https://learning-services-media.brightcove.com/images/for_video/Water-In-Motion-poster.png';
          requestBody.poster.width = 640;
          requestBody.poster.height = 360;
          requestBody.thumbnail = {};
          requestBody.thumbnail.url = 'https://learning-services-media.brightcove.com/images/for_video/Water-In-Motion-thumbnail.png';
          requestBody.thumbnail.width = 160;
          requestBody.thumbnail.height = 90;
          requestBody.profile = dd_profile;
          requestBody.callbacks = [callback_url];
          options.requestBody = JSON.stringify(requestBody);
          apiRequest.textContent = options.url;
          apiMethod.textContent = options.requestType;
          apiData.textContent = JSON.stringify(requestBody, null, '  ');
          makeRequest(options, function(response){
            var parsedData;
            parsedData = JSON.parse(response);
            responseData.textContent = JSON.stringify(parsedData, null, '  ');
            // re-enable the buttons
            enableButtons();
          });
          break;
        case 'addTextTracks':
          endPoint = '/videos/' + newVideo_id;
          options.url = ingestURL + endPoint + ingestURLsuffix;
          options.requestType = 'POST';
          requestBody.profile = dd_profile;
          requestBody.text_tracks = [];
          requestBody.text_tracks[0] = {};
          requestBody.text_tracks[0].url = 'https://learning-services-media.brightcove.com/captions/for_video/Water-in-Motion.vtt';
          requestBody.text_tracks[0].srclang = 'en';
          requestBody.text_tracks[0].kind = 'captions';
          requestBody.text_tracks[0].label = 'EN';
          requestBody.text_tracks[0].default = true;
          requestBody.callbacks = [callback_url];
          options.requestBody = JSON.stringify(requestBody);
          apiRequest.textContent = options.url;
          apiMethod.textContent = options.requestType;
          apiData.textContent = JSON.stringify(requestBody, null, '  ');
          makeRequest(options, function(response){
            var parsedData;
            parsedData = JSON.parse(response);
            responseData.textContent = JSON.stringify(parsedData, null, '  ');
            // re-enable the buttons
            enableButtons();
          });
          break;
      }
    }

    /**
     * send API request to the proxy
     * @param  {Object} options for the request
     * @param  {String} options.url the full API request URL
     * @param  {String="GET","POST","PATCH","PUT","DELETE"} requestData [options.requestType="GET"] HTTP type for the request
     * @param  {String} options.proxyURL proxyURL to send the request to
     * @param  {String} options.client_id client id for the account (default is in the proxy)
     * @param  {String} options.client_secret client secret for the account (default is in the proxy)
     * @param  {JSON} [options.requestBody] Data to be sent in the request body in the form of a JSON string
     * @param  {Function} [callback] callback function that will process the response
     */
    function makeRequest(options, callback) {
      var httpRequest = new XMLHttpRequest(),
        response,
        proxyURL = options.proxyURL,
        // response handler
        getResponse = function() {
          try {
            if (httpRequest.readyState === 4) {
              if (httpRequest.status >= 200 && httpRequest.status < 300) {
                response = httpRequest.responseText;
                // some API requests return '{null}' for empty responses - breaks JSON.parse
                if (response === '{null}') {
                  response = null;
                }
                // return the response
                callback(response);
              } else {
                alert('There was a problem with the request. Request returned ' + httpRequest.status);
              }
            }
          } catch (e) {
            alert('Caught Exception: ' + e);
          }
        };
      /**
       * set up request data
       * the proxy used here takes the following request body:
       * JSON.stringify(options)
       */
      // set response handler
      httpRequest.onreadystatechange = getResponse;
      // open the request
      httpRequest.open('POST', proxyURL);
      // set headers if there is a set header line, remove it
      // open and send request
      httpRequest.send(JSON.stringify(options));
    }

    // event listeners
  createVideo.addEventListener('click', function() {
    createRequest('createVideo');
  });
  ingestVideo.addEventListener('click', function() {
    createRequest('ingestVideo');
  });
  retranscode.addEventListener('click', function() {
    createRequest('retranscode');
  });
  replace.addEventListener('click', function() {
    createRequest('replace');
  });
  addImages.addEventListener('click', function() {
    createRequest('addImages');
  });
  addTextTracks.addEventListener('click', function() {
    createRequest('addTextTracks');
  });
})(window, document);

              
            
!
999px

Console