### Get Family Image - Python Example Source: https://yoto.dev/api/getafamilyimage Example of how to retrieve a family image using Python. This demonstrates using the 'requests' library to make a GET request to the media endpoint with specified width and height query parameters. ```python import requests url = "https://api.yotoplay.com/media/family/images/1afea16db1aeb62f8ba84cdb191eee7c1dd734d23098b4756717c3e2bded8c6a" params = { "width": 320, "height": 320 } headers = { "Authorization": "Bearer YOUR_TOKEN" } response = requests.get(url, params=params, headers=headers, allow_redirects=False) # Set allow_redirects=False to handle 302 manually if response.status_code == 302: image_url = response.headers.get('Location') print(f"Image URL: {image_url}") # You can then use this URL to fetch the image itself using another requests.get call else: print(f"Error fetching image: Status code {response.status_code}") print(response.text) ``` -------------------------------- ### Get Family Image - PHP Example Source: https://yoto.dev/api/getafamilyimage Example of how to retrieve a family image using PHP. This demonstrates using cURL to make a GET request to the media endpoint with specified width and height query parameters. ```php true and parse the output. ?> ``` -------------------------------- ### Get Content Details (PHP) Source: https://yoto.dev/api/getContent This PHP code provides an example of how to make a GET request to the Yoto API to retrieve content. It illustrates setting the Authorization header and handling the JSON response. ```php ``` -------------------------------- ### Get Family Image - JavaScript Example Source: https://yoto.dev/api/getafamilyimage Example of how to retrieve a family image using JavaScript. This demonstrates an asynchronous fetch request to the media endpoint with specified width and height query parameters. ```javascript fetch('https://api.yotoplay.com/media/family/images/1afea16db1aeb62f8ba84cdb191eee7c1dd734d23098b4756717c3e2bded8c6a?width=320&height=320', { method: 'GET', headers: { 'Authorization': 'Bearer YOUR_TOKEN' } }) .then(response => { if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } // The response will be a 302 redirect, so you might need to handle redirects or follow the Location header const imageUrl = response.headers.get('Location'); console.log('Image URL:', imageUrl); // You can then use this URL to fetch the image itself }) .catch(error => { console.error('Error fetching family image:', error); }); ``` -------------------------------- ### Get Content - Python Source: https://yoto.dev/api/getcontent This Python code snippet illustrates how to fetch content from the Yoto Developer API. It includes setting the authorization token and constructing the URL with query parameters. This is a fundamental example for using the API in Python projects. ```python import requests card_id = '{cardId}' api_url = f'https://api.yotoplay.com/content/{card_id}' token = 'YOUR_TOKEN' headers = { 'Authorization': f'Bearer {token}' } params = { 'timezone': 'Europe/London' } response = requests.get(api_url, headers=headers, params=params) if response.status_code == 200: print(response.json()) elif response.status_code == 400: print('Bad Request - Invalid timezone') elif response.status_code == 404: print('Not Found') else: print(f'Error: {response.status_code}') ``` -------------------------------- ### Get Content - PHP Source: https://yoto.dev/api/getcontent A PHP example for requesting content via the Yoto Developer API. This snippet shows how to set up the request, including authorization headers and query parameters like 'timezone'. It's essential for integrating content retrieval into PHP applications. ```php ``` -------------------------------- ### Get Device Status via Python Source: https://yoto.dev/api/getdevicestatus Example using Python with the 'requests' library to make a GET request to the Yoto API for device status. This code snippet demonstrates authentication and response handling. ```python import requests def get_device_status(device_id, access_token): url = f"https://api.yotoplay.com/device-v2/{device_id}/status" headers = { 'Authorization': f'Bearer {access_token}' } try: response = requests.get(url, headers=headers) response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx) data = response.json() print("Device Status:", data) return data except requests.exceptions.RequestException as e: print(f"Error fetching device status: {e}") return None # Example usage: # device_id = 'YOUR_DEVICE_ID' # access_token = 'YOUR_ACCESS_TOKEN' # status = get_device_status(device_id, access_token) ``` -------------------------------- ### Get Device Configuration using Python Source: https://yoto.dev/api/getDeviceConfig This Python code example shows how to obtain Yoto device configuration using the `requests` library. It sets the required headers, including the bearer token for authentication. ```python import requests device_id = 'YOUR_DEVICE_ID' auth_token = 'YOUR_AUTH_TOKEN' url = f"https://api.yotoplay.com/device-v2/{device_id}/config" headers = { 'accept': 'application/json', 'Authorization': f'Bearer {auth_token}' } response = requests.get(url, headers=headers) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code} - {response.text}") ``` -------------------------------- ### Get Family Images using JavaScript Source: https://yoto.dev/api/getFamilyImages Example of how to retrieve family images using JavaScript's Fetch API. This demonstrates asynchronous request handling for web applications. ```javascript fetch('https://api.yotoplay.com/media/family/images?limit=5', { method: 'GET', headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN' } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Get Devices - JavaScript Request Source: https://yoto.dev/api/getDevices Example JavaScript code to retrieve the list of devices associated with the authenticated user using the Fetch API. This requires bearer token authorization. ```javascript fetch('https://api.yotoplay.com/device-v2/devices/mine', { method: 'GET', headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN' } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### cURL Request to Authorize Browser Client Source: https://yoto.dev/api/get-authorize Example of how to initiate the OAuth2 Authorization Code flow using cURL by sending a GET request to the Yoto API's `/authorize` endpoint. This requires specifying several query parameters like `audience`, `scope`, `response_type`, `client_id`, `redirect_uri`, and `state`. ```shell curl -X GET "https://api.yotoplay.com/authorize?audience=https://api.yotoplay.com&scope=offline_access%20openid%20profile&response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&state=YOUR_STATE" ``` -------------------------------- ### Get Family Image - Python Example Source: https://yoto.dev/api/getAFamilyImage This Python script utilizes the 'requests' library to fetch a family image. It constructs the URL with query parameters for width and height and includes the authorization token in the headers. A successful response will contain the image URL in the 'Location' header. ```python import requests image_id = '1afea16db1aeb62f8ba84cdb191eee7c1dd734d23098b4756717c3e2bded8c6a' width = 320 height = 320 api_url = f'https://api.yotoplay.com/media/family/images/{image_id}' params = { 'width': width, 'height': height } headers = { 'Authorization': 'Bearer YOUR_TOKEN' } try: response = requests.get(api_url, params=params, headers=headers, allow_redirects=False) if response.status_code == 302: image_url = response.headers.get('Location') print(f'Image URL: {image_url}') else: print(f'Error: {response.status_code} - {response.text}') except requests.exceptions.RequestException as e: print(f'Network error: {e}') ``` -------------------------------- ### Get Specific Card Details (Example) Source: https://yoto.dev/api/getusersmyocontent To retrieve full details of a specific MYO card, including its chapters, you need to query the `/content/{cardId}` endpoint. This requires the `cardId` of the desired card and a valid authorization token. The response will contain comprehensive card information. ```plaintext GET /content/{cardId} Example: GET https://api.yotoplay.com/content/abcdef1234567890 ``` -------------------------------- ### Get Family Image - JavaScript Example Source: https://yoto.dev/api/getAFamilyImage This JavaScript code demonstrates how to fetch a family image using the Fetch API. It includes the necessary headers for authorization and query parameters for image dimensions. A successful request returns a 302 redirect. ```javascript fetch('https://api.yotoplay.com/media/family/images/1afea16db1aeb62f8ba84cdb191eee7c1dd734d23098b4756717c3e2bded8c6a?width=320&height=320', { method: 'GET', headers: { 'Authorization': 'Bearer YOUR_TOKEN' } }) .then(response => { if (response.ok) { // Handle 302 redirect const imageUrl = response.headers.get('Location'); console.log('Image URL:', imageUrl); } else { // Handle errors (400, 404) console.error('Error fetching image:', response.status, response.statusText); } }) .catch(error => { console.error('Network error:', error); }); ``` -------------------------------- ### Create Group Request - JavaScript Source: https://yoto.dev/api/createagroup Example JavaScript code using `fetch` to create a new group via the Yoto Developer API. It demonstrates setting headers and the JSON request body. ```javascript const url = 'https://api.yotoplay.com/card/family/library/groups'; const token = 'YOUR_TOKEN'; fetch(url, { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ "imageId": "fp-cards", "items": [ { "contentId": "37KwQ" } ], "name": "My Favourites" }) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Update Device Shortcuts (JavaScript) Source: https://yoto.dev/api/updateshortcutsbeta JavaScript example using the Fetch API to update shortcuts for a Yoto device. It demonstrates constructing the JSON payload and making a PUT request. ```javascript const deviceId = "YOUR_DEVICE_ID"; const token = "YOUR_TOKEN"; const shortcutsData = { "shortcuts": { "modes": { "day": { "content": [ { "cmd": "track-play", "params": { "card": "3nC80", "chapter": "daily", "track": "" } }, { "cmd": "track-play", "params": { "card": "3nC80", "chapter": "radio-day", "track": "01" } } ] }, "night": { "content": [] } } } }; fetch(`https://api.yotoplay.com/device-v2/${deviceId}/shortcuts`, { method: 'PUT', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify(shortcutsData) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Get Public Icons using Python Source: https://yoto.dev/api/getPublicIcons This Python example uses the 'requests' library to make a GET request to the Yoto Developer API for public icons. It demonstrates setting the authorization header. ```python import requests url = "https://api.yotoplay.com/media/displayIcons/user/yoto" headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN" } response = requests.get(url, headers=headers) if response.status_code == 200: data = response.json() print(data) else: print(f"Error: {response.status_code}") print(response.text) ``` -------------------------------- ### Get Public Icons using JavaScript Source: https://yoto.dev/api/getPublicIcons This JavaScript example demonstrates how to make a GET request to the Yoto Developer API to retrieve public icons. It uses the fetch API for the HTTP request. ```javascript fetch('https://api.yotoplay.com/media/displayIcons/user/yoto', { method: 'GET', headers: { 'Authorization': 'Bearer YOUR_ACCESS_TOKEN' } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Get Content Details (Python) Source: https://yoto.dev/api/getContent This Python script demonstrates fetching content from the Yoto API using the `requests` library. It shows how to construct the URL with query parameters and include the necessary Authorization header. ```python import requests card_id = 'YOUR_CARD_ID' token = 'YOUR_TOKEN' timezone = 'Pacific/Auckland' url = f"https://api.yotoplay.com/content/{card_id}" headers = { "Authorization": f"Bearer {token}" } params = { "timezone": timezone } response = requests.get(url, headers=headers, params=params) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") ``` -------------------------------- ### Get Family Group - cURL Request Source: https://yoto.dev/api/getAGroup Example cURL command to fetch a family group using the Yoto Developer API. This demonstrates how to make a GET request to the specified endpoint, including authorization. ```shell curl -X GET \ 'https://api.yotoplay.com/card/family/library/groups/{groupId}' \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' ``` -------------------------------- ### Upload Custom Icon using cURL Source: https://yoto.dev/api/uploadCustomIcon Example using cURL to upload a custom icon. This demonstrates how to send a binary file and optional query parameters to the API endpoint. ```shell curl -X POST \ https://api.yotoplay.com/media/displayIcons/user/me/upload?autoConvert=false&filename=apiTestFile \ -H 'Authorization: Bearer YOUR_TOKEN' \ -H 'Content-Type: image/png' \ --data-binary @/path/to/your/icon.png ``` -------------------------------- ### Get Device Status via cURL Source: https://yoto.dev/api/getdevicestatus Example using cURL to make a GET request to the Yoto API to retrieve the status of a specific device. Requires the deviceId as a path parameter and an authorization token. ```shell curl -X GET \ 'https://api.yotoplay.com/device-v2/{deviceId}/status' \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' ``` -------------------------------- ### Get Family Library Groups using PHP Source: https://yoto.dev/api/getGroups Illustrates how to get family library groups using PHP. This example uses cURL to make the API request and requires a bearer token for authorization. ```php ``` -------------------------------- ### Upload Custom Icon using JavaScript Source: https://yoto.dev/api/uploadCustomIcon Example using JavaScript (fetch API) to upload a custom icon. Shows how to construct the request with file data, headers, and query parameters. ```javascript const url = 'https://api.yotoplay.com/media/displayIcons/user/me/upload?autoConvert=false&filename=apiTestFile'; const token = 'YOUR_TOKEN'; const fileInput = document.querySelector('input[type="file"]'); const file = fileInput.files[0]; const formData = new FormData(); formData.append('file', file); fetch(url, { method: 'POST', headers: { 'Authorization': `Bearer ${token}` // Content-Type is set automatically by FormData }, body: formData }) .then(response => response.json()) .then(data => { console.log('Success:', data); }) .catch((error) => { console.error('Error:', error); }); ``` -------------------------------- ### Upload Icon using Python Source: https://yoto.dev/api/uploadcustomicon Python example using the 'requests' library to upload a custom icon. It demonstrates setting up the headers, files, and making the POST request to the Yoto API. ```python import requests url = "https://api.yotoplay.com/media/displayIcons/user/me/upload" files = {'file': open('/path/to/your/icon.png', 'rb')} headers = { 'Authorization': 'Bearer YOUR_TOKEN' } params = { 'autoConvert': 'false', 'filename': 'apiTestFile' } response = requests.post(url, files=files, headers=headers, params=params) print(response.json()) ``` -------------------------------- ### Get Family Group - Python Request Source: https://yoto.dev/api/getAGroup Example Python code using the 'requests' library to get a family group from the Yoto Developer API. It demonstrates setting the authorization header and parsing the JSON response. ```python import requests group_id = '{groupId}' # Replace with the actual group ID access_token = 'YOUR_ACCESS_TOKEN' # Replace with your access token url = f"https://api.yotoplay.com/card/family/library/groups/{group_id}" headers = { 'Authorization': f'Bearer {access_token}', 'Accept': 'application/json' } response = requests.get(url, headers=headers) if response.status_code == 200: data = response.json() print(data) else: print(f"Error: {response.status_code}") print(response.text) ``` -------------------------------- ### Get Device Configuration (JavaScript) Source: https://yoto.dev/api/getdeviceconfig This JavaScript code snippet shows how to fetch the configuration for a Yoto device using the Fetch API. It includes setting the necessary headers for authentication and content type. ```javascript const deviceId = 'YOUR_DEVICE_ID'; const accessToken = 'YOUR_ACCESS_TOKEN'; fetch(`https://api.yotoplay.com/device-v2/${deviceId}/config`, { method: 'GET', headers: { 'accept': 'application/json', 'Authorization': `Bearer ${accessToken}` } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Get Family Images using PHP Source: https://yoto.dev/api/getFamilyImages Example of how to retrieve family images using PHP with cURL. This is suitable for server-side integrations. ```php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.yotoplay.com/media/family/images?limit=5'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer YOUR_ACCESS_TOKEN')); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } else { echo $response; } curl_close($ch); ``` -------------------------------- ### PHP Request to Authorize Browser Client Source: https://yoto.dev/api/get-authorize Provides a PHP example for initiating the OAuth2 Authorization Code flow. It constructs the authorization URL with required parameters and shows how to redirect the user's browser to the Yoto login page. ```php ``` -------------------------------- ### Get Device Status via PHP Source: https://yoto.dev/api/getdevicestatus Example using PHP with cURL to make a GET request to the Yoto API for device status. This script shows how to set up the request, send it, and process the JSON response. ```php ``` -------------------------------- ### Update Device Shortcuts (Python) Source: https://yoto.dev/api/updateshortcutsbeta Python example using the 'requests' library to update shortcuts for a Yoto device. It shows how to construct the request payload and send a PUT request. ```python import requests import json device_id = "YOUR_DEVICE_ID" token = "YOUR_TOKEN" shortcuts_data = { "shortcuts": { "modes": { "day": { "content": [ { "cmd": "track-play", "params": { "card": "3nC80", "chapter": "daily", "track": "" } }, { "cmd": "track-play", "params": { "card": "3nC80", "chapter": "radio-day", "track": "01" } } ] }, "night": { "content": [] } } } } url = f"https://api.yotoplay.com/device-v2/{device_id}/shortcuts" headers = { "Authorization": f"Bearer {token}", "Content-Type": "application/json" } response = requests.put(url, headers=headers, data=json.dumps(shortcuts_data)) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code} - {response.text}") ``` -------------------------------- ### Get Device Status via JavaScript Source: https://yoto.dev/api/getdevicestatus Example using JavaScript (Node.js with fetch) to make a GET request to the Yoto API for device status. This code demonstrates how to handle the request and parse the JSON response. ```javascript async function getDeviceStatus(deviceId, accessToken) { const url = `https://api.yotoplay.com/device-v2/${deviceId}/status`; try { const response = await fetch(url, { method: 'GET', headers: { 'Authorization': `Bearer ${accessToken}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log('Device Status:', data); return data; } catch (error) { console.error('Error fetching device status:', error); return null; } } // Example usage: // const deviceId = 'YOUR_DEVICE_ID'; // const accessToken = 'YOUR_ACCESS_TOKEN'; // getDeviceStatus(deviceId, accessToken); ``` -------------------------------- ### Get Content Details (JavaScript) Source: https://yoto.dev/api/getContent This JavaScript snippet shows how to fetch content details using the Yoto API. It highlights the use of the `fetch` API and how to set the Authorization header with a bearer token. ```javascript const cardId = 'YOUR_CARD_ID'; const token = 'YOUR_TOKEN'; const timezone = 'Pacific/Auckland'; fetch(`https://api.yotoplay.com/content/${cardId}?timezone=${timezone}`, { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Get Family Group - PHP Request Source: https://yoto.dev/api/getAGroup Example PHP code using cURL to make a GET request to the Yoto Developer API for fetching a family group. It shows how to set the authorization header and process the response. ```php ``` -------------------------------- ### Update Device Configuration (JavaScript) Source: https://yoto.dev/api/updatedeviceconfig Example of updating a Yoto device's configuration using JavaScript's Fetch API. This demonstrates how to construct the PUT request with the necessary headers and JSON body. ```javascript const deviceId = "YOUR_DEVICE_ID"; const token = "YOUR_TOKEN"; const configData = { "config": { "alarms": [], "ambientColour": "#ff3900", "bluetoothEnabled": "1", "btHeadphonesEnabled": true, "clockFace": "digital-sun", "dayDisplayBrightness": "auto", "dayTime": "07:30", "dayYotoDaily": "3nC80/daily/", "dayYotoRadio": "3nC80/radio-day/01", "displayDimBrightness": "0", "displayDimTimeout": "60", "headphonesVolumeLimited": false, "hourFormat": "24", "locale": "en", "maxVolumeLimit": "16", "nightAmbientColour": "#ff0000", "nightDisplayBrightness": "auto", "nightMaxVolumeLimit": "16", "nightTime": "22:01", "nightYotoDaily": "3nC80/daily/", "nightYotoRadio": "3nC80/radio-night/01", "repeatAll": false, "shutdownTimeout": "3600", "volumeLevel": "safe" }, "name": "V2 player" }; fetch(`https://api.yotoplay.com/device-v2/${deviceId}/config`, { method: 'PUT', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify(configData) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Get Devices - cURL Request Source: https://yoto.dev/api/getDevices Example cURL command to retrieve the list of devices associated with the authenticated user. This endpoint requires bearer token authorization. ```shell curl -X GET \ 'https://api.yotoplay.com/device-v2/devices/mine' \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' ``` -------------------------------- ### Get Family Library Groups using PHP Source: https://yoto.dev/api/getgroups Provides a PHP script to retrieve all family library groups. This example utilizes cURL within PHP to make the GET request and handle the JSON response. ```php ``` -------------------------------- ### Initialize Device Authorization Flow (cURL) Source: https://yoto.dev/api/post-oauth-device-code Initiates the OAuth2 Device Authorization flow using cURL. Requires client_id, scope, and audience. Returns device verification codes and a verification URI. ```bash curl -X POST \ https://api.yotoplay.com/oauth/device/code \ -H 'Content-Type: application/x-www-form-urlencoded' \ -d 'client_id=YOUR_CLIENT_ID&scope=profile%20offline_access%20openid&audience=https://api.yotoplay.com' ``` -------------------------------- ### Initialize Device Authorization Flow (JavaScript) Source: https://yoto.dev/api/post-oauth-device-code Initiates the OAuth2 Device Authorization flow using JavaScript's fetch API. Requires client_id, scope, and audience. Returns device verification codes and a verification URI. ```javascript fetch('https://api.yotoplay.com/oauth/device/code', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: new URLSearchParams({ 'client_id': 'YOUR_CLIENT_ID', 'scope': 'profile offline_access openid', 'audience': 'https://api.yotoplay.com' }) }) .then(response => response.json()) .then(data => console.log(data)); ``` -------------------------------- ### Get Family Group via cURL Source: https://yoto.dev/api/getagroup Example of how to retrieve a family group using cURL. This demonstrates the HTTP method, endpoint, and necessary authorization headers. ```shell curl -X GET "https://api.yotoplay.com/card/family/library/groups/{groupId}" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" ``` -------------------------------- ### Get Device Configuration using JavaScript Source: https://yoto.dev/api/getDeviceConfig This JavaScript code snippet shows how to fetch a Yoto device's configuration using the Fetch API. It includes setting the appropriate headers for authentication and content type. ```javascript const deviceId = 'YOUR_DEVICE_ID'; const authToken = 'YOUR_AUTH_TOKEN'; fetch(`https://api.yotoplay.com/device-v2/${deviceId}/config`, { method: 'GET', headers: { 'accept': 'application/json', 'Authorization': `Bearer ${authToken}` } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Get Family Images using cURL Source: https://yoto.dev/api/getfamilyimages Example cURL command to retrieve family images from the Yoto API. This includes the endpoint and authorization header. ```bash curl -X GET \ https://api.yotoplay.com/media/family/images \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ -H 'Content-Type: application/json' ``` -------------------------------- ### Get Devices - PHP Request Source: https://yoto.dev/api/getDevices Example PHP code to retrieve the list of devices associated with the authenticated user using cURL. This requires bearer token authorization. ```php ``` -------------------------------- ### Get Family Images using cURL Source: https://yoto.dev/api/getFamilyImages Example of how to retrieve family images using a cURL command. This method is useful for quick testing and scripting. ```bash curl -X GET "https://api.yotoplay.com/media/family/images?limit=5" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" ``` -------------------------------- ### Upload Cover Image using Python Source: https://yoto.dev/api/uploadCoverImage Example of uploading a cover image using Python's `requests` library. This shows how to send multipart/form-data with image files or URLs and associated parameters to the Yoto API. ```python import requests url = "https://api.yotoplay.com/media/coverImage/user/me/upload" headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN" } files = { 'image': open('/path/to/your/image.jpg', 'rb') } # Alternatively, if using imageUrl: # files = {} # data = { # 'imageUrl': 'https://example.com/image.jpg', # 'autoconvert': 'true', # 'coverType': 'music', # 'filename': 'my_custom_name.jpg' # } data = { 'imageUrl': 'https://example.com/image.jpg', 'autoconvert': 'true', 'coverType': 'music', 'filename': 'my_custom_name.jpg' } response = requests.post(url, headers=headers, files=files, data=data) print(response.json()) ``` -------------------------------- ### Get Devices - Python Request Source: https://yoto.dev/api/getDevices Example Python code to retrieve the list of devices associated with the authenticated user using the 'requests' library. This requires bearer token authorization. ```python import requests url = "https://api.yotoplay.com/device-v2/devices/mine" headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN" } response = requests.get(url, headers=headers) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") ``` -------------------------------- ### Upload Cover Image using cURL Source: https://yoto.dev/api/uploadCoverImage Example using cURL to upload a cover image. This demonstrates how to send the image file or URL along with query parameters like `autoconvert` and `coverType` to the Yoto API. ```shell curl -X POST \ https://api.yotoplay.com/media/coverImage/user/me/upload \ -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ -F 'image=@/path/to/your/image.jpg' \ -F 'imageUrl=https://example.com/image.jpg' \ -F 'autoconvert=true' \ -F 'coverType=music' \ -F 'filename=my_custom_name.jpg' ``` -------------------------------- ### Send Device Command using Python Source: https://yoto.dev/api/senddevicecommand Example of sending an MQTT command to a Yoto device using Python. This uses the 'requests' library to execute the HTTP POST request. ```python import requests def send_device_command(device_id: str, access_token: str): url = f"https://api.yotoplay.com/device-v2/{device_id}/command/status" headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } payload = {} response = requests.post(url, headers=headers, json=payload) return response.json() ``` -------------------------------- ### Get Family Images using Python Source: https://yoto.dev/api/getFamilyImages Example of how to retrieve family images using Python's 'requests' library. This is a common approach for backend services. ```python import requests url = "https://api.yotoplay.com/media/family/images" params = { "limit": 5 } headers = { "Authorization": "Bearer YOUR_ACCESS_TOKEN" } response = requests.get(url, params=params, headers=headers) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") ``` -------------------------------- ### Upload Custom Icon (JSON Response Example) Source: https://yoto.dev/api/uploadCustomIcon Example JSON response when a new custom icon is successfully uploaded. Includes details like media ID, user ID, display icon ID, URL, and a flag indicating it's a new upload. ```json { "displayIcon": { "mediaId": "XBkuY6DBFn5iRfFS6nV6CTWaCrEvBOOX8nzV9Y64h8I", "userId": "auth0|userHash", "displayIconId": "683736c62fd7c5cd177d206f", "url": "https://media-secure.aws.com/icons/mlWc6s-JG", "new": true } } ``` -------------------------------- ### Get Family Group via PHP Source: https://yoto.dev/api/getagroup Provides a PHP example for retrieving a family group using cURL. This showcases how to construct the request and set authorization headers in PHP. ```php ``` -------------------------------- ### Send Device Command using JavaScript Source: https://yoto.dev/api/senddevicecommand Example of sending an MQTT command to a Yoto device using JavaScript. This utilizes the fetch API to make a POST request to the device command endpoint. ```javascript async function sendDeviceCommand(deviceId, accessToken) { const url = `https://api.yotoplay.com/device-v2/${deviceId}/command/status`; const response = await fetch(url, { method: 'POST', headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json' }, body: JSON.stringify({}) }); return await response.json(); } ``` -------------------------------- ### Create Group Request - Python Source: https://yoto.dev/api/createagroup Example Python code using the `requests` library to create a new group via the Yoto Developer API. It includes setting headers and the JSON request body. ```python import requests import json url = "https://api.yotoplay.com/card/family/library/groups" token = "YOUR_TOKEN" data = { "imageId": "fp-cards", "items": [ { "contentId": "37KwQ" } ], "name": "My Favourites" } headers = { "Authorization": f"Bearer {token}", "Content-Type": "application/json" } response = requests.post(url, headers=headers, data=json.dumps(data)) print(response.status_code) print(response.json()) ``` -------------------------------- ### Get Family Library Groups using cURL Source: https://yoto.dev/api/getgroups Example of how to retrieve all family library groups using a cURL command. This is useful for testing API endpoints directly from the command line. ```shell curl -X GET https://api.yotoplay.com/card/family/library/groups \ -H "Authorization: Bearer YOUR_API_TOKEN" ```