### cURL GET Request Example Source: https://docs.wistia.com/reference/search This snippet demonstrates how to make a GET request to the Wistia API's search endpoint using cURL. It includes the necessary URL, request method, and accept header for JSON responses. This example is useful for testing API calls directly from the command line. ```shell curl --request GET \ --url https://api.wistia.com/v1/search \ --header 'accept: application/json' ``` -------------------------------- ### GET Wistia Media - cURL Request Example Source: https://docs.wistia.com/reference/media Example of how to make a GET request to the Wistia API to retrieve media information using cURL. This request includes the necessary URL and header for JSON content negotiation. ```Shell curl --request GET \ --url https://api.wistia.com/v1/medias \ --header 'accept: application/json' ``` -------------------------------- ### Handle Load Start Event in HTML/JS and React Source: https://docs.wistia.com/docs/player-events This snippet illustrates how to capture the 'load-start' event, which signifies the beginning of the Wistia player embed loading process. Examples are provided for both HTML/JavaScript and React. ```html ``` ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; export default function App() { function handleLoadStart() { console.log("The player has started loading."); }; return ( ); } ``` -------------------------------- ### Start Video Playback at a Specific Time Source: https://docs.wistia.com/docs/javascript-player-api This example demonstrates how to make a video start playing from a specific time using the `bind` and `time` methods. ```APIDOC ## Start Video Playback at a Specific Time ### Description This endpoint allows you to start video playback at a specific time when the play button is pressed. It utilizes the `bind on play` functionality. ### Method JavaScript API ### Endpoint N/A (JavaScript interaction) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```html
 
``` ### Response #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### Fetch Wistia Video Customizations (Ruby) Source: https://docs.wistia.com/reference/customizations Illustrates fetching Wistia video customizations using Ruby. This example assumes the 'wistia-ruby-sdk' gem is installed and an API token is provided. ```ruby # Assumes wistia-ruby-sdk gem is installed and configured with your API token # require 'wistia_ruby_sdk' # client = WistiaRubySdk::Client.new(api_token: 'YOUR_API_TOKEN') # client.media.get_customizations(media_id: 'your_media_id') ``` -------------------------------- ### Handle Can Play Event - HTML/JavaScript and React Source: https://docs.wistia.com/docs/player-events This snippet demonstrates how to use the 'can-play' event, which signifies that the browser can start playing the media, though buffering might still be necessary. It includes examples for both HTML/JavaScript and React. ```html ``` ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; export default function App() { function handleCanPlay() { console.log("The media can be played, but it will probably have to stop to buffer."); }; return ( ); } ``` -------------------------------- ### Fetch Wistia Video Customizations (Node.js) Source: https://docs.wistia.com/reference/customizations Example of fetching Wistia video customizations using Node.js with the 'wistia-api' library. Assumes the library is installed and an API token is available. ```javascript // Assumes wistia-api library is installed and configured with your API token // const wistia = require('wistia-api')(YOUR_API_TOKEN); // async function getCustomizations(mediaId) { // try { // const customizations = await wistia.medias.getCustomizations(mediaId); // console.log(customizations); // return customizations; // } catch (error) { // console.error('Error fetching customizations:', error); // } // } // Example usage: // getCustomizations('your_media_id'); ``` -------------------------------- ### Upload Video to Wistia using Ruby Gem Source: https://docs.wistia.com/reference/examples-using-ruby Demonstrates how to upload a video file to Wistia using Ruby's 'multipart-post' gem. This method requires the gem to be installed and involves opening a file and constructing a multipart POST request to the Wistia upload endpoint. ```ruby # upload_ruby_gem.rb require 'net/http' require 'net/http/post/multipart' def post_video_to_wistia(name, path_to_video) uri = URI('https://upload.wistia.com/') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true # Construct the request. request = Net::HTTP::Post::Multipart.new uri.request_uri, { 'access_token' => '', 'contact_id' => '', # Optional. 'project_id' => '', # Optional. 'name' => '', # Optional. 'file' => UploadIO.new( File.open(path_to_video), 'application/octet-stream', File.basename(path_to_video) ) } # Make it so! response = http.request(request) return response end ``` -------------------------------- ### Initialize Wistia Player with HTML Source: https://docs.wistia.com/docs/player-attributes-and-properties Demonstrates how to initialize a Wistia player using HTML and the Wistia player script. It sets the media ID and disables player controls. ```html ``` -------------------------------- ### Retrieve Project Stats (Python) Source: https://docs.wistia.com/reference/statsprojects Python example using the 'requests' library to get project statistics from Wistia API. Requires installation of the 'requests' library and a valid API token. ```python import requests url = "https://api.wistia.com/v1/stats/projects/projectId" headers = { "accept": "application/json", } response = requests.get(url, headers=headers) print(response.json()) ``` -------------------------------- ### Player Initialization Source: https://docs.wistia.com/docs/player-attributes-and-properties Demonstrates how to initialize a Wistia player with specific media and player color options using HTML and React. ```APIDOC ## Initialize Player with Value ### Description Initialize a Wistia player with a specified media ID and player color. ### Method Not Applicable (Client-side configuration) ### Endpoint Not Applicable ### Parameters #### HTML Attributes - **media-id** (string) - Required - The ID of the media to play. - **player-color** (string) - Optional - The hex code for the player's color. #### React Props - **mediaId** (string) - Required - The ID of the media to play. - **playerColor** (string) - Optional - The hex code for the player's color. ### Request Example ```html ``` ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; ``` ### Response #### Success Response (200) Player is initialized and ready for playback. #### Response Example Not Applicable ``` -------------------------------- ### Embed Wistia Player using React Component Source: https://docs.wistia.com/docs/player-quick-start This snippet shows how to integrate the Wistia player into a React application using the `@wistia/wistia-player-react` npm package. It details the installation process and how to import and use the `WistiaPlayer` component with a `mediaId` prop. ```shell npm install @wistia/wistia-player-react ``` ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; export default function App() { return ( ); } ``` -------------------------------- ### Player Initialization and Updates Source: https://docs.wistia.com/docs/player-attributes-and-properties Examples of how to initialize and update the Wistia player using HTML/JavaScript and React. ```APIDOC ## Initialize Player ### Description Initializes the Wistia player with specified media and configuration options. ### Method N/A (Element attribute/Component prop) ### Endpoint N/A ### Parameters #### HTML Attributes / React Props - **id** (string) - Required - The unique identifier for the player element. - **media-id** (string) / **mediaId** (string) - Required - The ID of the Wistia media to load. - **volume-control** (boolean) / **volumeControl** (boolean) - Optional - Controls the visibility of the volume control. Defaults to `true`. ### Request Example (HTML) ```html ``` ### Request Example (React) ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; ``` ## Update Player Property ### Description Updates a player property after initialization. ### Method JavaScript property assignment ### Endpoint N/A ### Parameters #### HTML Attributes / React Props - **volume-control** (boolean) / **volumeControl** (boolean) - Sets the volume control visibility. ### Request Example (HTML + JavaScript) ```html ``` ``` -------------------------------- ### Initialize Wistia Player Source: https://docs.wistia.com/docs/player-attributes-and-properties Demonstrates initializing a Wistia player with a specific media ID and preload setting. This basic setup ensures the player is ready to display content. It requires including the Wistia player script. ```html ``` ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; ``` -------------------------------- ### Embed Wistia Player using npm and JavaScript Source: https://docs.wistia.com/docs/player-quick-start This snippet demonstrates how to install and use the `@wistia/wistia-player` npm package in a JavaScript application. It covers importing the web component and then rendering it either declaratively in JSX-like syntax or programmatically by creating and appending the element. ```shell npm install @wistia/wistia-player ``` ```javascript import '@wistia/wistia-player'; // Render declaratively: // // Render programmatically: const player = document.createElement('wistia-player'); player.mediaId = 'abc123'; document.body.append(player); ``` -------------------------------- ### Initialize Wistia Player with media-id (HTML) Source: https://docs.wistia.com/docs/player-attributes-and-properties This example shows the basic initialization of a Wistia player using the required `media-id` attribute in HTML. The `media-id` is essential for identifying the specific video to be played. The `id` attribute is also included for referencing the player element in JavaScript. ```html ``` -------------------------------- ### Get Wistia Player Plugin (React) Source: https://docs.wistia.com/docs/player-methods This React example shows how to get a Wistia player plugin. It uses `useRef` and `onApiReady` to access the player instance and call `getPlugin()` once the API is ready. Requires the `@wistia/wistia-player-react` library. ```jsx import { useRef } from "react"; import { WistiaPlayer } from "@wistia/wistia-player-react"; export default function App() { const player = useRef(null); // As soon as the player embed has an api, get an existing plugin. function handleApiReady() { if (player.current === null) { return; } player.current.getPlugin("turnstile"); } return ( ); } ``` -------------------------------- ### Initialize Wistia Player with Audio Description Control Source: https://docs.wistia.com/docs/player-attributes-and-properties Illustrates how to enable the audio description control for a Wistia player during initialization. This feature allows users to toggle audio descriptions, enhancing accessibility for visually impaired viewers. Note that the control only appears if alternate audio tracks are available. ```html ``` ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; ``` -------------------------------- ### GET /live_stream_events Source: https://docs.wistia.com/reference/get_live-stream-events Retrieves a list of Live Stream Events from your Wistia account. Supports paging, sorting, and filtering by ID, start status, and more. ```APIDOC ## GET /live_stream_events ### Description Use this endpoint to request a list of Live Stream Events in your Wistia account. This request supports paging and sorting. ## Requires api token with one of the following permissions ``` Read, update & delete anything Read all data Read all folder and media data ``` ### Method GET ### Endpoint /live_stream_events ### Parameters #### Query Parameters - **page** (integer) - Optional - Page number to retrieve - **per_page** (integer) - Optional - Number of events per page (maximum 100) - **sort_by** (string) - Optional - Field to sort by. Allowed values: `scheduled_for`, `id` - **sort_direction** (string) - Optional - Sort direction. Allowed values: `1` (ascending), `-1` (descending) - **hashed_ids[]** (array of strings) - Optional - Filter by specific event IDs - **started** (string) - Optional - Filter by whether the event has started. Allowed values: `true`, `false` ### Response #### Success Response (200) - **id** (string) - The hashed ID of the live stream event - **title** (string) - The title of the live stream event - **description** (string | null) - The description of the live stream event - **scheduled_for** (string | null) - The scheduled start time in W3C format with timezone - **event_duration** (integer | null) - Duration of the event in minutes - **lifecycle_status** (string) - Current lifecycle status of the event #### Response Example ```json [ { "id": "abc123def456", "title": "Wellness Session: Coping with Outie Memories", "description": "A comprehensive session on managing work-life balance", "scheduled_for": "2024-03-20T15:30:00-05:00", "event_duration": 60, "lifecycle_status": "scheduled" } ] ``` ``` -------------------------------- ### Initialize Wistia Player with React Source: https://docs.wistia.com/docs/player-attributes-and-properties Shows how to initialize a Wistia player within a React application using the `@wistia/wistia-player-react` library. This example also disables player controls. ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; ``` -------------------------------- ### Drop-in Uploader Configuration in HTML/JavaScript Source: https://docs.wistia.com/docs/uploader This example shows how to create a simple, self-contained Wistia Uploader using the `dropIn` option. It requires the Wistia API and CSS, a container element, and JavaScript to initialize the Uploader with the `dropIn` option specified. ```html
``` -------------------------------- ### Get Project Sharings List - PHP Source: https://docs.wistia.com/reference/project-sharings Example PHP code to fetch project sharings from the Wistia API. This script uses cURL to make the HTTP GET request and decodes the JSON response. ```php ``` -------------------------------- ### Get Project Sharings List - Node.js Source: https://docs.wistia.com/reference/project-sharings Example Node.js code to fetch a list of sharings for a Wistia project. It utilizes the 'node-fetch' library to make an HTTP GET request to the Wistia API and handles the JSON response. ```javascript const fetch = require('node-fetch'); const options = { method: 'GET', headers: { 'accept': 'application/json' } }; fetch('https://api.wistia.com/v1/projects/projectId/sharings', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err)); ``` -------------------------------- ### Retrieve Video Stats using Ruby Source: https://docs.wistia.com/reference/statsmedia This Ruby example shows how to get video statistics from Wistia's API. It utilizes the 'httparty' gem to perform an HTTP GET request, passing the media ID and API token for authentication. ```ruby require 'httparty' media_id = 'YOUR_MEDIA_ID' api_token = 'YOUR_API_TOKEN' url = "https://api.wistia.com/v1/stats/medias/#{media_id}" response = HTTParty.get(url, headers: { 'Authorization' => "Bearer #{api_token}", 'Accept' => 'application/json' }) if response.success? puts response.parsed_response else puts "Error: #{response.code} - #{response.message}" end ``` -------------------------------- ### Set Video Quality for Wistia Player (React) Source: https://docs.wistia.com/docs/player-attributes-and-properties Initializes a Wistia player and sets the video quality using a React prop. Requires the @wistia/wistia-player-react library. Accepts quality levels as numbers or the string 'auto'. ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; ``` -------------------------------- ### Retrieve Account Stats via PHP Source: https://docs.wistia.com/reference/statsaccount This PHP example shows how to get account-wide video statistics using cURL. It sets the request method to GET, specifies the Wistia API URL, and includes the 'accept: application/json' header. ```php ``` -------------------------------- ### Get Project Sharings List - Ruby Source: https://docs.wistia.com/reference/project-sharings Example Ruby code to retrieve a list of sharings for a Wistia project. This snippet uses the built-in 'net/http' library to send a GET request to the Wistia API and parse the JSON response. ```ruby require 'net/http' require 'uri' uri = URI.parse("https://api.wistia.com/v1/projects/projectId/sharings") request = Net::HTTP::Get.new(uri) request["accept"] = "application/json" response = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == 'https') do |http| http.request(request) end puts JSON.parse(response.body) ``` -------------------------------- ### Initialize Wistia Player with Value (HTML) Source: https://docs.wistia.com/docs/player-attributes-and-properties Initializes a Wistia player with specified attributes in HTML. Requires the Wistia player script. Sets player ID, media ID, and transparent letterbox setting. ```html ``` -------------------------------- ### Get Project Sharings List - cURL Source: https://docs.wistia.com/reference/project-sharings Example cURL request to retrieve a list of sharings for a specific Wistia project. This command uses the GET method and specifies the API endpoint URL and the expected JSON response format. ```shell curl --request GET \ --url https://api.wistia.com/v1/projects/projectId/sharings \ --header 'accept: application/json' ``` -------------------------------- ### Access Media Assets with Wistia Data API Ruby Gem Source: https://docs.wistia.com/docs/working-with-images This example demonstrates how to use the Wistia Data API Ruby Gem to retrieve media assets. It shows how to select the 'OriginalFile' asset and construct a modified URL with a '.jpg' extension and resize parameters. ```ruby m = Wistia::Media.first asset = m.assets.select{ |a| a.attributes["type"] == "OriginalFile" }.first url = asset.attributes["url"] # => "https://embed-ssl.wistia.com/deliveries/b300126144f62ba2942ec4a4f29e949a47e16f12.bin" name = url.chomp(File.extname(url)) + ".jpg?image_crop_resized=640x360" # => "https://embed-ssl.wistia.com/deliveries/b300126144f62ba2942ec4a4f29e949a47e16f12.jpg?image_crop_resized=640x360" ``` -------------------------------- ### Get Wistia Projects List (Node.js) Source: https://docs.wistia.com/reference/projects This Node.js example shows how to fetch a list of Wistia projects using the 'node-fetch' library. It constructs the GET request to the Wistia API, including the necessary 'accept' header. You'll need to manage your API token securely. ```javascript const fetch = require('node-fetch'); const options = { method: 'GET', headers: { 'accept': 'application/json' } }; fetch('https://api.wistia.com/v1/projects', options) .then(response => response.json()) .then(response => console.log(response)) .catch(err => console.error(err)); ``` -------------------------------- ### Path Routing Example Rules Source: https://docs.wistia.com/docs/channel-embeds Illustrates example server-side routing rules required when using `routeStrategy=path`. These rules help direct traffic to the correct Wistia channel or media based on URL patterns. ```regex /my/blog/* -> /my/blog /(.*?)/channel-(.*) -> $1 ``` -------------------------------- ### Get Wistia Video Handle with JavaScript (Iframe Embeds) Source: https://docs.wistia.com/docs/javascript-player-api This example shows how to get a Wistia video handle for iframe embeds using the `window._wq` queue and the `onReady` event. This is functionally equivalent to using standard embeds for obtaining the player API handle. ```html ``` -------------------------------- ### Get Wistia Visitors List (Node.js) Source: https://docs.wistia.com/reference/statsvisitors This Node.js example utilizes the `axios` library to make a GET request to the Wistia visitors API. It sets the necessary headers and handles the JSON response. Remember to replace `YOUR_API_TOKEN` with your valid Wistia API token. ```javascript const axios = require('axios'); const apiToken = 'YOUR_API_TOKEN'; const url = 'https://api.wistia.com/v1/stats/visitors'; const headers = { 'accept': 'application/json' }; axios.get(url, { headers }) .then(response => { const visitors = response.data; visitors.forEach(visitor => { console.log(visitor); }); }) .catch(error => { console.error(`Error: ${error.response.status}`); console.error(error.response.data); }); ``` -------------------------------- ### Set Video Quality for Wistia Player (HTML) Source: https://docs.wistia.com/docs/player-attributes-and-properties Initializes a Wistia player and sets the video quality using an HTML attribute. Requires the Wistia player script. Supports specific quality levels or 'auto' for adaptive streaming. ```html ``` -------------------------------- ### Initialize Wistia Player with Value (HTML) Source: https://docs.wistia.com/docs/player-attributes-and-properties Initializes a Wistia player in HTML using the `` tag. Requires the Wistia Player JavaScript SDK. Sets player ID, media ID, and player color. ```html ``` -------------------------------- ### Get Wistia Projects List (PHP) Source: https://docs.wistia.com/reference/projects This PHP example demonstrates fetching a list of Wistia projects using cURL. It sets the request method to GET, includes the 'accept' header, and targets the Wistia API endpoint for projects. Ensure your cURL extension is enabled and your API token is handled securely. ```php ``` -------------------------------- ### Handle API Ready Event - HTML/JavaScript and React Source: https://docs.wistia.com/docs/player-events This snippet demonstrates how to listen for the 'api-ready' event, which fires when the Wistia player's API is initialized and ready for interaction. It includes examples for both direct DOM manipulation in HTML/JavaScript and using the React component. ```html ``` ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; export default function App() { function handleApiReady() { console.log("This player's api is ready for interaction."); }; return ( ); } ``` -------------------------------- ### Fetch Channel Episodes (Python) Source: https://docs.wistia.com/reference/channel-episodes A Python example for accessing the Wistia API to get channel episodes. This code uses the `requests` library to perform the HTTP GET request and includes placeholders for API token and query parameters for filtering and sorting. Error handling is recommended for robust applications. ```python import requests api_token = 'YOUR_API_TOKEN' base_url = 'https://api.wistia.com/v1/channel_episodes' headers = { 'accept': 'application/json' } params = { # Example: filter by hashed_id # 'hashed_id[]': ['hashed_id_1', 'hashed_id_2'], # Example: sort by position ascending # 'sort_by': 'position', # 'sort_direction': 1 # 1 for asc, 0 for desc } try: response = requests.get(base_url, headers=headers, params=params, auth=('api_token', api_token)) response.raise_for_status() # Raise an exception for bad status codes episodes = response.json() print(episodes) except requests.exceptions.RequestException as e: print(f'Error fetching channel episodes: {e}') ``` -------------------------------- ### Read Wistia Player Ready State (HTML + JavaScript) Source: https://docs.wistia.com/docs/player-attributes-and-properties This snippet demonstrates how to read the ready state of a Wistia player using HTML and JavaScript. It requires the Wistia player script and a wistia-player element. The `readyState` property returns an integer representing the player's current state. ```html ``` -------------------------------- ### GET /websites/wistia/projects/{project_id} Source: https://docs.wistia.com/reference/get_projects-id Retrieves a single project, including a paginated list of its media. By default, it returns up to 500 media items per project. For projects with more media, pagination parameters can be used. ```APIDOC ## GET /websites/wistia/projects/{project_id} ### Description Retrieves details of a single Wistia project. This endpoint returns the first 500 media items by default. To access subsequent pages of media, use the `page` query parameter. ### Method GET ### Endpoint `/websites/wistia/projects/{project_id}` ### Parameters #### Path Parameters - **project_id** (string) - Required - The unique identifier of the project. #### Query Parameters - **page** (integer) - Optional - Specifies the page number of media to retrieve. Defaults to 1. ### Request Example ``` GET /websites/wistia/projects/your_project_id?page=2 # Requires an API token with appropriate permissions (e.g., Read all data) ``` ### Response #### Success Response (200) - **name** (string) - The name of the project. - **media_count** (integer) - The total number of media items in the project. - **media** (array) - A list of media items (up to 500 per page). - **id** (string) - The media item ID. - **name** (string) - The name of the media item. - ... (other media properties) #### Response Example ```json { "name": "My Awesome Project", "media_count": 750, "media": [ { "id": "media1_id", "name": "Intro Video", "created_at": "2023-10-27T10:00:00Z" }, { "id": "media2_id", "name": "Tutorial Part 1", "created_at": "2023-10-27T10:05:00Z" } // ... up to 500 media items ] } ``` ``` -------------------------------- ### Retrieve Project Stats (Node.js) Source: https://docs.wistia.com/reference/statsprojects Node.js example using fetch to get project statistics from Wistia API. Ensure you have a valid API token and project ID. ```javascript fetch('https://api.wistia.com/v1/stats/projects/projectId', { "method": "GET", "headers": { "accept": "application/json" } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error)); ``` -------------------------------- ### Initialize Wistia Player with Custom Poster Image Source: https://docs.wistia.com/docs/player-attributes-and-properties Illustrates how to set a custom thumbnail image for a Wistia player before it starts playing. This is achieved using the `poster` attribute in HTML, a prop in React, or by updating the JavaScript property dynamically. ```html ``` ```jsx import { WistiaPlayer } from "@wistia/wistia-player-react"; ``` ```html ``` -------------------------------- ### Initialize Wistia Players with HTML Attributes Source: https://docs.wistia.com/docs/player-attributes-and-properties This snippet demonstrates how to initialize Wistia players using HTML attributes directly on the `` tag. Attributes like `media-id` and `player-color` can be set to customize the player's appearance and behavior. Multiple attributes can be combined on a single element. ```html ``` -------------------------------- ### Retrieve Wistia Tags List (Ruby) Source: https://docs.wistia.com/reference/tags This Ruby example demonstrates how to fetch tags from the Wistia API using the built-in 'Net::HTTP' library. It constructs the GET request and processes the JSON response. ```ruby require 'uri' require 'net/http' require 'json' uri = URI.parse("https://api.wistia.com/v1/tags") request = Net::HTTP::Get.new(uri) request["accept"] = "application/json" response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http| http.request(request) end puts JSON.parse(response.body) ```