Return to the Panopto API index page
Before you begin on this page you’ll need the starting code from page 100 and I highly recommend increasing the buffer size of results from page 101. You can expect queries that return more than a couple of results to crash without it.
On this page we are going to produce the same type of list we made for folders, but this time for sessions.
Paste the following code in the // PUT YOUR AUTHENTICATION DETAILS HERE section
1 2 3 4 5 |
PanoptoSessionManagement.AuthenticationInfo sessionAuthInfo = new PanoptoSessionManagement.AuthenticationInfo() { UserKey = "api", Password = "s2ezupajePhasaP5" }; |
The rest of the code goes under // START WRITING CODE HERE. First of all we’ll make some pages, just like we did for folders
1 |
PanoptoSessionManagement.Pagination pagination = new PanoptoSessionManagement.Pagination { MaxNumberResults = 100, PageNumber = 0 }; |
You’ll notice that I’ve changed the maximum number of results to 100.
Leave a blank line and paste the following code (we’re going to fill in the blank link once I’ve explained what were doing)
1 2 |
ISessionManagement sessionMgr = new SessionManagementClient(); ListSessionsResponse response = sessionMgr.GetSessionsList(sessionAuthInfo, request, null); |
You’ll notice that the first line is exactly the same as when we searched for folders. The list commands are part of SessionManagementClient so we need to make an object to do the searching from.
The second line is what differs from the folder query. We’re using the command GetSessionsList, which requires us to send the AuthenticationInfo as normal, then a ListSessionsRequest and finally a search query (string, can be null).
So the preceding two lines are likely to be very re-usable. Now we’ll make the request variable.
Take a look at http://support.panopto.com/…bbf226d518f8.htm for everything you can put into the request, but for my example I’m going to return all the sessions for a particular folder ID.
Pro tip: Match this code with page 102 to find the folder ID of a folder by name, then list the sessions in it with this code.
Paste this code above ISessionManagement,,,
1 |
PanoptoSessionManagement.ListSessionsRequest request = new PanoptoSessionManagement.ListSessionsRequest {FolderId = Guid.Parse("76083047-7ccd-494f-8f8a-0f01a1101876")}; |
The four lines should look like this now
1 2 3 4 |
PanoptoSessionManagement.Pagination pagination = new PanoptoSessionManagement.Pagination { MaxNumberResults = 5, PageNumber = 0 }; PanoptoSessionManagement.ListSessionsRequest request = new PanoptoSessionManagement.ListSessionsRequest { Pagination = pagination, FolderId = Guid.Parse("76083047-7ccd-494f-8f8a-0f01a1101876")}; ISessionManagement sessionMgr = new SessionManagementClient(); ListSessionsResponse response = sessionMgr.GetSessionsList(sessionAuthInfo, request, null); |
So out of the many things I can request, I’ve just told it pick sessions with the folder ID 7608…
We can return the sessions in the same way as with folders, but instead of Folder folder we’ll use Session session
1 2 3 4 5 6 7 8 9 10 11 |
if (response.Results.Length > 0) { foreach (Session session in response.Results) { Console.WriteLine(session.Id + ": " + session.Name); } } else { Console.WriteLine("No sessions found"); } |
All sessions are returned. You could build your own RSS feed or video listings page just from this information.
Full code below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Security.Cryptography.X509Certificates; using ConsolePanoptoAPI.PanoptoAccessManagement; using ConsolePanoptoAPI.PanoptoAuth; using ConsolePanoptoAPI.PanoptoRemoteRecorderManagement; using ConsolePanoptoAPI.PanoptoSessionManagement; using ConsolePanoptoAPI.PanoptoUsageReporting; using ConsolePanoptoAPI.PanoptoUserManagement; // ANY NEW NAMESPACES SHOULD BE ADDED HERE // END OF NAMESPACES namespace ConsolePanoptoAPI { class Program { static bool hasBeenInitialized = false; static void Main(string[] args) { // PUT YOUR AUTHENTICATION DETAILS HERE PanoptoSessionManagement.AuthenticationInfo sessionAuthInfo = new PanoptoSessionManagement.AuthenticationInfo() { UserKey = "api", Password = "s2ezupajePhasaP5" }; // END OF AUTHENTICATION DETAILS // START WRITING CODE HERE PanoptoSessionManagement.Pagination pagination = new PanoptoSessionManagement.Pagination { MaxNumberResults = 5, PageNumber = 0 }; PanoptoSessionManagement.ListSessionsRequest request = new PanoptoSessionManagement.ListSessionsRequest { Pagination = pagination, FolderId = Guid.Parse("76083047-7ccd-494f-8f8a-0f01a1101876")}; ISessionManagement sessionMgr = new SessionManagementClient(); ListSessionsResponse response = sessionMgr.GetSessionsList(sessionAuthInfo, request, null); if (response.Results.Length > 0) { foreach (Session session in response.Results) { Console.WriteLine(session.Id + ": " + session.Name); } } else { Console.WriteLine("No sessions found"); } // STOP WRITING CODE HERE Console.WriteLine("Press Enter to exit"); Console.ReadLine(); } /// /// Ensures that our custom certificate validation has been applied /// public static void EnsureCertificateValidation() { if (!hasBeenInitialized) { ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(CustomCertificateValidation); hasBeenInitialized = true; } } /// /// Ensures that server certificate is authenticated /// private static bool CustomCertificateValidation(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error) { return true; } /// /// Creates an auth code. Used when we want to authenticate a user, but don't know their password. /// ///The instance name as set in Panopto > System > Identity Providors ///Username as defined by Panopto ///The full server name as defined by Panopto > System > Settings > General site settings > Web server FQDN ///The key produced through Panopto > System > Identity Providors /// private static string CreateAuthCode(string identityProviderInstanceName, string username, string serverFqdn, string applicationKey) { string payload = identityProviderInstanceName + "\\" + username + "@" + serverFqdn.ToLower() + "|" + applicationKey.ToLower(); var data = Encoding.ASCII.GetBytes(payload); var hashData = new System.Security.Cryptography.SHA1Managed().ComputeHash(data); var hash = string.Empty; foreach (var b in hashData) hash += b.ToString("X2"); return hash; } } } |
Return to the Panopto API index page