css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

              <section class="bcls-section">
<h2 id="dataInput">Inputs for the Update</h2>

<fieldset class="bcls-fieldset"><legend>Videos to Update</legend>

<p><button class="bcls-button" id="getVideos">Get Videos</button></p>

<p>Video metadata for update:</p>
  <textarea id="videoData" class="bcls-code" style="height:10em;">Video data for the update will appear here.</textarea>

<p><button id="setRequest" class="bcls-button">Update the videos</button></p>

<section class="bcls-section">
<h2 id="outputLog">Results</h2>

<fieldset class="bcls-fieldset"><legend>Outputs</legend>

<p>API request:</p>
  <textarea id="apiRequest" class="bcls-code" style="height:1em;">API requests will appear here</textarea>
<p>API request body:</p>
<textarea id="apiRequestBody" class="bcls-code">Request bodies will appear here</textarea>
  <p>API Response</p>
<code id="response" class="bcls-code" style="font-size:.8rem">Responses 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%;
  height: 5em;
  background-color: #cfcfcf;
  font-size: 1rem;
.bcls-button {
  padding: .5em;
  background-color: #333;
  border: 1px yellow solid;
  border-radius: .5em;
  color: yellow;
fieldset {
  color: #64AAB2;
  border: 1px #64AAB2 solid;
  border-radius: .5em;
              var BCLS = (function(window, document) {
  var account_id_field = document.getElementById("account_id"),
    account_id = "57838016001",
    setRequest_button = document.getElementById("setRequest"),
    apiRequest = null,
    apiRequest_field = document.getElementById("apiRequest"),
    apiRequestBody = document.getElementById("apiRequestBody"),
    getVideos_button = document.getElementById("getVideos"),
    submit_button = document.getElementById("submit"),
    response_display = document.getElementById("response"),
    totalVideos = 0,
    limit = 5,
    offset = 0,
    callNumber = 0,
    videoData_display = document.getElementById("videoData"),
    videoData = [],
    proxyURL =
   * 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;

  // function to set up request
  function setRequest(type) {
    var responseParsed,
      options = {},
      requestBody = {},
    options.account_id = account_id;
    options.proxyURL = proxyURL;
    switch (type) {
      case "getVideos":
        options.url =
          "https://cms.api.brightcove.com/v1/accounts/" +
          options.account_id +
          "/videos?limit=5&offset=" +
        options.requestType = "GET";
        // display the request URL
        apiRequest_field.textContent = options.url;
        makeRequest(options, function(response) {
          responseParsed = JSON.parse(response);
          response_display.textContent = JSON.stringify(
            "  "
          iMax = responseParsed.length;
          for (i = 0; i < iMax; i++) {
            var o = {},
              video = responseParsed[i],
              date = new Date().toISOString();
            o.id = video.id;
            o.name = video.name;
            o.description = "Updated at: " + date;
          videoData_display.textContent = JSON.stringify(videoData, null, "  ");
      case "updateVideo":
        var currentVideo = videoData[callNumber];
        if (isDefined(currentVideo)) {
          options.url =
            "https://cms.api.brightcove.com/v1/accounts/" +
            options.account_id +
            "/videos/" +
          requestBody = currentVideo;
          // request body must not contain the video id
          delete requestBody.id;
          options.requestBody = JSON.stringify(requestBody);
          options.requestType = "PATCH";
          // display the request URL and body
          apiRequest_field.textContent = options.url;
          apiRequestBody.textContent = JSON.stringify(requestBody, null, "  ");
          makeRequest(options, function(response) {
            responseParsed = JSON.parse(response);
            response_display.textContent = JSON.stringify(
              "  "
            if (callNumber < totalVideos) {

   * 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"} [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;
              // some API requests return '{null}' for empty responses - breaks JSON.parse
              if (response === "{null}") {
                response = null;
              // return the response
            } else {
                "There was a problem with the request. Request returned " +
        } 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

  // init function to set up event listeners
  function init() {
    // event listeners
    getVideos_button.addEventListener("click", function() {
    setRequest_button.addEventListener("click", function() {
      // get and clean up video data
      videoData = JSON.parse(videoData_display.value);
      totalVideos = videoData.length;
      // set up the request
  // initialize - set up data
})(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.
Loading ..................