Show Menu
TOPICS×

Obtaining a session ID

This code snippet from the Reference Player shows one way of coding a Sessions request, along with extracting the Session ID (and the Media Collection API version) from the Location header in the response:
var sessionData = { ... "media.contentType": "VOD", "media.channel": "sample-channel", ... } }; ... const SESSION_ID_EXTRACTOR = /^\/api\/(.*)\/sessions\/(.*)/; ... apiClient.request({ "baseUrl": config.apiBaseUrl, // The endpoint "path": config.apiSessionsPath, // api/v1/sessions/ "method": "POST", // (Always POST) "data": sessionData // Mandatory params }).then((response) => { // Extract Session ID (and API version) const [, apiVersion, sessionId] = response.headers.Location.match(SESSION_ID_EXTRACTOR); this.sessionId = sessionId; // Session ID obtained this._sessionStarted = true; // Session started. ...