Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              <fieldset class="bcls-fieldset"><legend>Inputs for Dynamic Ingest</legend>

<p>Account: (defaults to Brightcove sample account) <input id="account_id" type="text" value="" name="account_id" /></p>

<p>Client id: (defaults to Brightcove sample account) <input id="client_id" type="text" value="" name="client_id" /></p>

<p>Client secret: (defaults to Brightcove sample account) <input id="client_secret" type="text" value="" name="client_secret" /></p>

<p>Ingest profile: <select id="ingest_profile_display"></select><br />
or Custom Profile: <input id="custom_profile_display" type="text" value="" name="custom_profile_display" /> (you must use the name exactly as it appears in the Video Cloud system, or the request will fail)</p>

<p>Video name: <input id="video_name" type="text" value="" name="video_name" /> (if left blank, file name will be used)</p>

<p>Video source file URL: <input id="video_url" type="text" value="" name="video_url" /> (if left blank, a sample video will be used)</p>

<p>Start date: <input id="fromDatePicker" size="30" /> (default: now)</p>

<p>End: <input id="toDatePicker" size="30" /> (default: never)</p>

<p>Full request body for the CMS API call:</p>

<textarea class="bcls-code" id="cms_url">Request data will appear here....</textarea>
(automatically generated - for information only)

<p>Full request body for the DI API call:</p>

<textarea class="bcls-code" id="di_url">Request data will appear here....</textarea>
(automatically generated - for information only)

<p><button class="bcls-button" id="di_submit">Start Ingest</button></p>
<section class="bcls-section">
<h2 id="logger">Results Log</h2>

<pre class="line-numbers">
<code id="responseEl" class="language-json">Response will appear here...</code></pre>
              /* * 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: #fff;
  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;
code {
  color: #E4B842;
  font-family: 'Source Code Pro',monospace;
              var BCLS = (function(window, document) {
  var fromDatePicker = document.getElementById('fromDatePicker'),
    toDatePicker = document.getElementById('toDatePicker'),
    account_id = document.getElementById('account_id'),
    client_id = document.getElementById('client_id'),
    client_secret = document.getElementById('client_secret'),
    ingest_profile_display = document.getElementById('ingest_profile_display'),
    custom_profile_display = document.getElementById('custom_profile_display'),
    video_url = document.getElementById('video_url'),
    video_name = document.getElementById('video_name'),
    di_url = document.getElementById('di_url'),
    cms_url = document.getElementById('cms_url'),
    di_submit = document.getElementById('di_submit'),
    responseEl = document.getElementById('responseEl'),
    profilesArray = ['multi-platform-extended-static', 'multi-platform-standard-static'],
    default_video = 'http://learning-services-media.brightcove.com/videos/mp4/greatblueheron.mp4',
    now = new Date(),
    // get the date part of the date-time string
    nowISO = now.toISOString().substr(0, 10);

   * tests for all the ways a variable might be undefined or not have a value
   * @param {*} x the variable to test
   * @return {Boolean} true if variable is defined and has a value
  function isDefined(x) {
    if (x === '' || x === null || x === undefined) {
      return false;
    return true;

   * get selected value for single select element
   * @param {htmlElement} e the select element
   * @return {Object} object containing the `value`, text, and selected `index`
  function getSelectedValue(e) {
    var selected = e.options[e.selectedIndex],
      val = selected.value,
      txt = selected.textContent,
      idx = e.selectedIndex;
    return {
      value: val,
      text: txt,
      index: idx

   * createRequest sets up requests, send them to makeRequest(), and handles responses
   * @param  {string} type the request type
  function createRequest(type) {
    var options = {},
      cmsBaseURL = 'https://cms.api.brightcove.com/v1/accounts/' + account,
      diBaseURL = 'https://ingest.api.brightcove.com/v1/accounts/' + account,
      requestBody = {},

    // set credentials
    options.account_id = account;
    if (isDefined(cid) && isDefined(csec)) {
      options.client_id = cid;
      options.client_secret = csec;
    options.proxyURL = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php';

    switch (type) {
      case 'createVideo':
        endpoint = '/videos';
        options.url = cmsBaseURL + endpoint;
        options.requestType = 'POST';
        requestBody.name = name;
        requestBody.schedule = {};
        requestBody.schedule.starts_at = starts_at;
        if (isDefined(ends_at)) {
          requestBody.schedule.ends_at = ends_at;
        options.requestBody = JSON.stringify(requestBody);
        cms_url.textContent = JSON.stringify(requestBody, null, '  ');
        makeRequest(options, function(response) {
          responseDecoded = JSON.parse(response);
          responseEl.textContent = JSON.stringify(responseDecoded, null, '  ');
          video_id = responseDecoded.id;
        // additional cases
      case 'ingestVideo':
        endpoint = '/videos/' + video_id + '/ingest-requests';
        options.url = diBaseURL + endpoint;
        options.requestType = 'POST';
        requestBody.master = {};
        requestBody.master.url = video;
        requestBody.profile = profile;
        requestBody.callbacks = ['http://solutions.brightcove.com/bcls/dynamic-delivery/di-callbacks.php'];
        options.requestBody = JSON.stringify(requestBody);
        di_url.textContent = JSON.stringify(requestBody, null, '  ');

console.log('di options', options);
        makeRequest(options, function(response) {
          responseDecoded = JSON.parse(response);
          responseEl.textContent = 'Your request has been submitted - your Job ID is ' + responseDecoded.id;
        console.log('Should not be getting to the default case - bad request type sent');

   * 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(),
      proxyURL = options.proxyURL,
      // response handler
      getResponse = function() {
        try {
          if (httpRequest.readyState === 4) {
            if (httpRequest.status >= 200 && httpRequest.status < 300) {
              response = httpRequest.responseText;
              // return the response
console.log('response', response);
            } else {
              alert('There was a problem with the request. Request returned ' + httpRequest.status);
        } catch (e) {
          alert('Caught Exception: ' + e);
console.log('options', options);
     * 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);
    // open and send request

  // initialize
  function init() {
    var i,
      iMax = profilesArray.length,
    // add date pickers to the date input fields
    fromPicker = new Pikaday({
      field: fromDatePicker,
      format: 'YYYY-MM-DD'
    toPicker = new Pikaday({
      field: toDatePicker,
      format: 'YYYY-MM-DD'
    // set initial from value
    fromDatePicker.value = nowISO;
    // add options for standard ingest profiles
    for (i = 0; i < iMax; i++) {
      newOpt = new Option(profilesArray[i]);
    // add event listener for the submit button
    di_submit.addEventListener('click', function() {
      account = (isDefined(account_id.value)) ? account_id.value : '57838016001';
      cid = client_id.value;
      csec = client_secret.value;
      starts_at = fromDatePicker.value;
      ends_at = toDatePicker.value;
      if (isDefined(custom_profile_display.value)) {
        profile = custom_profile_display.value;
      } else {
        profile = getSelectedValue(ingest_profile_display).text;
      video = (isDefined(video_url.value)) ? video_url.value : default_video;
      name = (isDefined(video_name.value)) ? video_name.value : video.substr(video.lastIndexOf('/') + 1);
  // call init to set things up

})(window, document);

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.