### Set Events Settings for Device (Node.js Example) Source: https://developer.surfsight.net/openapi/surfsight/operation/putEventConfig Provides a Node.js example using the `axios` library to set device event settings. This code sends a PUT request to the API endpoint with appropriate headers and the JSON payload. Ensure `axios` is installed (`npm install axios`). ```javascript const axios = require('axios'); const imei = "YOUR_IMEI"; const accessToken = "YOUR_ACCESS_TOKEN"; const payload = { "vehicleType": "Private", "events": [ { "eventType": "cellPhoneUse", "dataType": "none", "weight": 3, "speedLimit": 120, "numberOfBeeps": 2, "minimumSpeed": 60, "config": { "headwayAlertDayThreshold": 2000, "headwayAlertNightThreshold": 3000, "headwayAlertTime": 3000, "timeWindow": 0, "numberOfYawns": 1, "assumeMoving": false, "laneWeavingTimes": 3, "laneWeavingDurationSeconds": 30 }, "drivingDuration": 8, "visualAlert": true, "audioAlert": true } ] }; axios.put(`https://api.surfsight.net/v1/devices/${imei}/event-config`, payload, { headers: { 'Authorization': `Bearer ${accessToken}`, 'Content-Type': 'application/json' } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### Create Group Request Sample (Node.js) Source: https://developer.surfsight.net/openapi/surfsight/operation/postOrganizationGroups Example of how to create a group using Node.js with the 'axios' library. This code demonstrates making a POST request to the API, including authentication and the JSON payload. Remember to install axios and replace placeholder values. ```javascript const axios = require('axios'); const orgId = 'YOUR_ORG_ID'; const groupName = 'Cool Name'; const token = 'YOUR_API_TOKEN'; axios.post(`https://api.surfsight.net/v1/organizations/${orgId}/groups`, { name: groupName }, { headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error creating group:', error); }); ``` -------------------------------- ### Retrieve Device Health Reports (Node.js) Source: https://developer.surfsight.net/openapi/surfsight/operation/getDevicesHealth This Node.js example uses the 'axios' library to make a GET request for device health reports. It demonstrates how to include query parameters and the Authorization header. Remember to install axios (`npm install axios`) and replace the placeholder token. ```javascript const axios = require('axios'); const token = ''; const url = 'https://api-prod.surfsight.net/v2/device-health'; const params = { limit: 1, offset: 1, lastConnectedAtStart: '2019-08-24T14:15:22Z', lastConnectedAtEnd: '2019-08-24T14:15:22Z', lastRecordingUpdatedAtStart: '2019-08-24T14:15:22Z', lastRecordingUpdatedAtEnd: '2019-08-24T14:15:22Z', lastRecordingHealth: 1, organizationId: 17, imei: '12345678', name: 'Mike', sort: 'name', order: 'asc', billingStatus: 'pendingActivation' }; axios.get(url, { params: params, headers: { 'Authorization': `Bearer ${token}` } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error fetching device health reports:', error); }); ``` -------------------------------- ### Create User - JavaScript (Fetch API) Example Source: https://developer.surfsight.net/openapi/surfsight/operation/postOrganizationUsers Demonstrates how to create a user using the Fetch API in JavaScript. This asynchronous function sends a POST request to the user creation endpoint, including the necessary headers and JSON body. Error handling for responses is included. ```javascript async function createUser(orgId, email, password, role, groupIds) { const response = await fetch(`https://api.surfsight.net/v1/organizations/${orgId}/users`, { method: 'POST', headers: { 'Authorization': 'Bearer ', 'Content-Type': 'application/json' }, body: JSON.stringify({ email: email, password: password, role: role, groupIds: groupIds }) }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); } // Example usage: createUser(62, 'email@email.com', '123Abcd!', 'restricted', [32]) .then(data => console.log(data)) .catch(error => console.error('Error creating user:', error)); ``` -------------------------------- ### Retrieve Organization Audit Logs using Node.js Source: https://developer.surfsight.net/openapi/surfsight/operation/getAuditLogs This Node.js example utilizes the 'axios' library to make a GET request to retrieve organization audit logs. It demonstrates how to set query parameters and the 'Authorization' header. Ensure you have 'axios' installed (`npm install axios`). Replace with your actual API token. ```javascript const axios = require('axios'); const token = ""; const apiUrl = "https://api-prod.surfsight.net/v2/audit-logs"; const params = { limit: 1, offset: 1, start: "2020-01-01T14:48:00.000Z", end: "2020-01-01T14:48:00.000Z", userId: "32", partnerId: "62", userType: "partnerContact", organizationId: "17", imei: "12345678", entityId: "123456", entityType: "device", entityOrganizationId: "17", entityPartnerId: "62" }; axios.get(apiUrl, { headers: { 'Authorization': `Bearer ${token}` }, params: params }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error fetching audit logs:', error); }); ``` -------------------------------- ### Bulk Device Configuration Request Samples (Node.js) Source: https://developer.surfsight.net/developer-portal/surfsightapi/reference/operation/putBulkDeviceConfig This Node.js code snippet illustrates how to perform a bulk device configuration request using the 'node-fetch' library. It demonstrates setting up the request with the correct method, headers, and JSON body for the API call. ```javascript const fetch = require('node-fetch'); const apiUrl = 'http://localhost:3000/devices/device-config'; const token = ''; // Replace with your actual token const requestBody = { organizationId: 17, groupIds: [ 32 ], config: { adas: { value: true }, distractedDriver: { value: true }, liveVideo: { value: true }, driverCamera: { value: true }, textOverlay: { value: true }, inCabinCameraRecording: { value: true }, driverPosition: { value: "left" }, speedUnits: { value: "mph" }, audioAlarms: { value: true }, notifyLiveStreaming: { value: true }, adminPin: { value: "1234" }, driverPin: { value: "4321" }, brightness: { value: 128 }, dateTimeUnits: { value: "us" }, voiceRecording: { value: true }, standby: { timeout: 10 }, hotSpot: { internetAccess: false, hotspotEnabled: true }, recordingEncryption: { enabled: true, password: "]cTQ0TNJ[sZb{5TKL4J_+(&z4@C7j~+" }, privacy: { gpsEnabled: true, mvaiEnabled: true, liveStreamEnabled: true, allEventsEnabled: true, cameras: [ { cameraId: 1, recordingEnabled: true, eventsEnabled: true } ] }, pinCodeDi: { value: true }, qrDi: { value: true }, driverIdentification: { driverPrompt: true, audioAlert: true, driverPromptDurationSeconds: 30 }, virtualIgnition: { value: true }, screenTimeout: { value: 120 }, passengerLimit: { value: 1 }, wakeupMsg: { enabled: true, timeout: 10 }, ledEnabled: { value: true }, setTimezoneByCloud: { value: true } } }; async function configureDevices() { try { const response = await fetch(apiUrl, { method: 'PUT', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify(requestBody) }); const data = await response.json(); console.log(data); } catch (error) { console.error('Error:', error); } } configureDevices(); ``` -------------------------------- ### Update Device Configuration (JavaScript Example) Source: https://developer.surfsight.net/developer-portal/surfsightapi/reference/operation/putDeviceConfig This JavaScript code snippet shows how to make a PUT request to update device configuration using the `fetch` API. It constructs the request body, sets the appropriate headers, and handles the response. ```javascript const deviceImei = "YOUR_DEVICE_IMEI"; const configData = { "adas": { "value": true }, // ... other configuration options }; fetch(`https://your-api-domain.com/put/devices/${deviceImei}/device-config`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(configData) }) .then(response => response.json()) .then(data => console.log('Success:', data)) .catch((error) => console.error('Error:', error)); ``` -------------------------------- ### Include Bearer Token in API Request (cURL) Source: https://developer.surfsight.net/developer-portal/basic-authentication This example demonstrates how to include the obtained bearer token in the Authorization header when making subsequent requests to the Surfsight API. It shows a GET request to retrieve device events, with the token appended as 'Bearer YOUR_TOKEN'. ```bash curl --request GET https://api-prod.surfsight.net/v2/devices/{imei}/events \ --header 'Content-Type: application/json' \ --header 'Authorization: Bearer ImahFWLZWFdD8VVcUtIED2YuOjPFlZpldQTE5tUqKdv' ``` -------------------------------- ### Bulk Add Devices - Node.js Request Example Source: https://developer.surfsight.net/openapi/surfsight/operation/bulkAssignDevicesToOrganizationForPartner Illustrates a Node.js implementation for bulk device addition using the 'axios' library. This example shows setting up the request with headers and the JSON body. ```javascript const axios = require('axios'); const orgId = '62'; // Replace with your organization ID const devices = [ { "imei": "357660101000198", "name": "Aragorn's car", "groupId": 32 } ]; const url = `https://api.example.com/organizations/${orgId}/partner-bulk-devices`; axios.put(url, devices, { headers: { 'Authorization': 'Bearer bearerAuth', // Replace with your actual token 'Content-Type': 'application/json' } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### Create User - Node.js (Axios) Example Source: https://developer.surfsight.net/openapi/surfsight/operation/postOrganizationUsers Example using the Axios library in Node.js to create a user. This code snippet shows how to configure the POST request with authentication, content type, and the JSON payload. It includes basic error handling. ```javascript const axios = require('axios'); async function createUserNode(orgId, email, password, role, groupIds) { try { const response = await axios.post(`https://api.surfsight.net/v1/organizations/${orgId}/users`, { email: email, password: password, role: role, groupIds: groupIds }, { headers: { 'Authorization': 'Bearer ', 'Content-Type': 'application/json' } }); return response.data; } catch (error) { console.error('Error creating user:', error.response ? error.response.data : error.message); throw error; } } // Example usage: createUserNode(62, 'email@email.com', '123Abcd!', 'restricted', [32]) .then(data => console.log(data)) .catch(error => console.error('Failed to create user.')); ``` -------------------------------- ### Start React Component Development Server Source: https://developer.surfsight.net/developer-portal/components/calibrate-adas Command to run the React component locally after installing dependencies. This command starts the development server, allowing for live previews and debugging. ```bash npm start ``` -------------------------------- ### Update Webhook Settings - Node.js Example Source: https://developer.surfsight.net/developer-portal/surfsightapi/reference/operation/postOrganizationWebhookSettings This Node.js code snippet utilizes the 'axios' library to send a POST request for updating webhook settings. Ensure you have 'axios' installed (`npm install axios`). ```javascript const axios = require('axios'); const orgId = "62"; const payload = { "gpsWebhookUrl": [ "string" ], "eventWebhookUrl": [ "string" ], "eventWebhookConfig": { "notifyMediaAvailable": { "isEnabled": true } }, "alarmsWebhookUrl": [ "string" ], "alarmsWebhookConfig": { "subscribeForAlarmUpdates": { "isEnabled": false } }, "systemMessagesWebhook": [ { "url": "string", "config": { "dataProfile": { "isEnabled": false, "dataProfileLimit": 90 }, "deviceStatus": { "isEnabled": false }, "deviceBillingStatus": { "isEnabled": false }, "deviceRemoved": { "isEnabled": false }, "auxiliaryCamerasConnectionStatus": { "isEnabled": false }, "auxiliaryCamerasPairingStatus": { "isEnabled": false }, "privacyMode": { "isEnabled": false }, "dataUsage": { "isEnabled": true, "dataThresholds": [ 0.5, 1.5 ], "dataPlan": 1 }, "dynamicAdjust": { "isEnabled": false } } } ] }; axios.post(`https://api.example.com/v1/organizations/${orgId}/webhook-settings`, payload, { headers: { 'Authorization': 'Bearer ', 'Content-Type': 'application/json' } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### Update Device Configuration (Node.js Example) Source: https://developer.surfsight.net/developer-portal/surfsightapi/reference/operation/putDeviceConfig This Node.js example uses the `axios` library to send a PUT request for updating device configuration. It includes the request payload and error handling for network requests. ```javascript const axios = require('axios'); const deviceImei = "YOUR_DEVICE_IMEI"; const configData = { "adas": { "value": true }, // ... other configuration options }; axios.put(`https://your-api-domain.com/put/devices/${deviceImei}/device-config`, configData, { headers: { 'Content-Type': 'application/json' } }) .then(response => { console.log('Success:', response.data); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### Example API Request with Pagination Source: https://developer.surfsight.net/developer-portal/pagination This example demonstrates how to make a POST request to create events with pagination parameters. ```APIDOC ## POST /organizations/{orgId}/events with Pagination ### Description Creates events within an organization, utilizing pagination to manage the request. ### Method POST ### Endpoint `https://api-prod.surfsight.net/v2/organizations/{organizationId}/events` ### Parameters #### Path Parameters - **organizationId** (string) - Required - The ID of the organization. #### Query Parameters - **limit** (integer) - Optional - The maximum number of results to retrieve. - **offset** (integer) - Optional - The number of results to omit. #### Request Body - **offset** (integer) - Required - The number of results to omit. - **limit** (integer) - Required - The maximum number of results to retrieve. - **start** (string) - Required - The start date/time for the event range (ISO 8601 format). - **end** (string) - Required - The end date/time for the event range (ISO 8601 format). - **eventTypes** (array of strings) - Required - A list of event types to include. ### Request Example ```json { "offset": 10, "limit": 1, "start": "2021-12-24T09:50:07.485Z", "end": "2021-12-27T09:50:07.485Z", "eventTypes": ["acceleration","button"] } ``` ``` -------------------------------- ### Get Device Recipients (Node.js) Source: https://developer.surfsight.net/openapi/surfsight/operation/getDeviceRecipients This Node.js example utilizes the 'axios' library to make a GET request for retrieving device notification recipients. It demonstrates setting up the request with the device IMEI, event type filter, and authorization token. The JSON response containing recipient details is then logged. ```javascript const axios = require('axios'); const imei = 'YOUR_IMEI_HERE'; const eventType = 'cellPhoneUse'; const token = 'YOUR_TOKEN_HERE'; axios.get(`https://api-prod.surfsight.net/v2/devices/${imei}/notification-recipients?eventType=${eventType}`, { headers: { 'Authorization': `Bearer ${token}` } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error fetching recipients:', error); }); ``` -------------------------------- ### Sample Application Configuration Parameters Source: https://developer.surfsight.net/developer-portal/guides/view-live-video These are the parameters within the 'static.js' file of the sample application that need to be modified with user credentials and camera settings. Correctly setting these parameters is crucial for the sample application to connect to the device and initiate video streaming. ```JavaScript var config = { imei: 'YOUR_IMEI_HERE', cameraType: 1, // 1: road-facing, 2: in-cabin, 51-54: auxiliary cameras email: 'YOUR_EMAIL_HERE', password: 'YOUR_PASSWORD_HERE' }; ``` -------------------------------- ### Get Device Events with Time Constraints Source: https://developer.surfsight.net/developer-portal/changelog/changelog_main Enforces start and end query parameters to retrieve up to 31 days of activity for device events, preventing excessive database load. ```APIDOC ## GET devices/{imei}/events ### Description Retrieves events for a specific device within a 31-day period. Start and end date query parameters are enforced. ### Method GET ### Endpoint `/devices/{imei}/events` ### Parameters #### Path Parameters - **imei** (string) - Required - The IMEI of the device. #### Query Parameters - **start** (string) - Required - Start date for the query (YYYY-MM-DD), up to 31 days prior to the end date. - **end** (string) - Required - End date for the query (YYYY-MM-DD). ### Request Example ```json { "example": "GET /devices/123456789012345/events?start=2024-01-01&end=2024-01-31" } ``` ### Response #### Success Response (200) - **(array)** - List of events for the device. - **event_id** (string) - Unique identifier for the event. - **timestamp** (string) - Timestamp of the event. #### Response Example ```json [ { "event_id": "evt_xyz789", "timestamp": "2024-01-15T11:00:00Z" } ] ``` ``` -------------------------------- ### Create User - cURL Request Example Source: https://developer.surfsight.net/openapi/surfsight/operation/postOrganizationUsers Example of creating a user using cURL. This demonstrates how to send a POST request with the organization ID in the URL and the user data in the JSON payload. Requires appropriate authentication headers. ```bash curl -X POST https://api.surfsight.net/v1/organizations/{orgId}/users \ -H "Authorization: Bearer " \ -H "Content-Type: application/json" \ -d '{ "email": "email@email.com", "password": "123Abcd!", "role": "restricted", "groupIds": [ 32 ] }' ``` -------------------------------- ### Delete ADAS Images using Node.js Source: https://developer.surfsight.net/openapi/surfsight/operation/deleteAdasCalibrationImages This snippet provides a Node.js example for deleting ADAS calibration images. It uses the 'node-fetch' library to make a DELETE request to the Surfsight API. Ensure you have 'node-fetch' installed (`npm install node-fetch`). The device must be online or in standby. ```javascript const fetch = require('node-fetch'); const imei = "YOUR_DEVICE_IMEI"; const token = "YOUR_TOKEN_HERE"; async function deleteAdasImages() { try { const response = await fetch(`https://api-prod.surfsight.net/v2/devices/${imei}/adas-delete-calibration-images`, { method: 'DELETE', headers: { 'Authorization': `Bearer ${token}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log(data); } catch (error) { console.error('Error deleting ADAS images:', error); } } deleteAdasImages(); ``` -------------------------------- ### Retrieve Device Safety Score using Node.js Source: https://developer.surfsight.net/openapi/surfsight/operation/getDeviceScore This Node.js example shows how to get a device's safety score. It uses a common HTTP client library (like 'axios' or the built-in 'https' module) to send a GET request with the necessary parameters and authentication. ```JavaScript const axios = require('axios'); const imei = 'YOUR_IMEI_HERE'; const startDate = '2020-01-01T14:48:00.000Z'; const endDate = '2020-01-01T14:48:00.000Z'; const token = 'YOUR_TOKEN_HERE'; axios.get(`https://api-prod.surfsight.net/v2/devices/${imei}/score`, { params: { start: startDate, end: endDate }, headers: { 'Authorization': `Bearer ${token}` } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### POST /devices/{imei}/virtual-event Source: https://developer.surfsight.net/developer-portal/changelog/changelog_main Creates a virtual event for a device, now returning a 404 if no recordings are found. ```APIDOC ## POST /devices/{imei}/virtual-event ### Description Creates a virtual event for a specified device. This endpoint has been updated to return a `404 Not Found` error if no recordings are found within the requested time range. ### Method POST ### Endpoint /devices/{imei}/virtual-event ### Parameters #### Path Parameters - **imei** (string) - Required - The IMEI number of the device. #### Request Body - **startTime** (string) - Required - The start time for the virtual event. - **endTime** (string) - Required - The end time for the virtual event. ### Response #### Error Response (404) - **code** (integer) - 404 - **message** (string) - 'not found: No recordings were found in the requested time range. Change the range and try again'. ``` -------------------------------- ### Retrieve Organization Details - Node.js Source: https://developer.surfsight.net/openapi/surfsight/operation/getOrganization Example of how to retrieve organization details using Node.js with the 'axios' library. It demonstrates making a GET request with an authorization header. ```javascript const axios = require('axios'); const orgId = ':orgId'; // Replace with the actual organization ID const token = ''; // Replace with your actual token axios.get(`https://api-prod.surfsight.net/v2/organizations/${orgId}`, { headers: { 'Authorization': `Bearer ${token}` } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error fetching organization details:', error); }); ``` -------------------------------- ### Get Organization Devices Billing Status using Node.js Source: https://developer.surfsight.net/openapi/surfsight/operation/getOrganizationDevicesBillingStatus This Node.js example utilizes the 'node-fetch' library to retrieve the billing status of devices for an organization. It demonstrates making a GET request with appropriate headers for authentication. Error handling is implemented to manage potential network or API response issues. ```javascript import fetch from 'node-fetch'; async function getOrganizationDevicesBillingStatusNode(orgId, token) { const url = `https://api-prod.surfsight.net/v2/organizations/${orgId}/devices/billing-status?offset=1&limit=1`; try { const response = await fetch(url, { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); console.log('Billing Status Data:', data); return data; } catch (error) { console.error('Error fetching billing status:', error); } } // Example usage: // const organizationId = 'YOUR_ORG_ID'; // const apiToken = 'YOUR_TOKEN_HERE'; // getOrganizationDevicesBillingStatusNode(organizationId, apiToken); ``` -------------------------------- ### POST Request with Node.js (Axios) for Device Settings Source: https://developer.surfsight.net/openapi/surfsight/operation/postOrganizationDeviceSettings Example Node.js code using the Axios library to send a POST request for updating device settings. This demonstrates how to make asynchronous HTTP requests in a Node.js environment. ```javascript const axios = require('axios'); const orgId = 'YOUR_ORG_ID'; const authToken = 'YOUR_AUTH_TOKEN'; const deviceSettings = { "adas": { "value": true }, "distractedDriver": { "value": true }, "liveVideo": { "value": true }, "driverCamera": { "value": true }, "textOverlay": { "value": true }, "inCabinCameraRecording": { "value": true }, "driverPosition": { "value": "left" }, "speedUnits": { "value": "mph" }, "audioAlarms": { "value": true }, "notifyLiveStreaming": { "value": true }, "adminPin": { "value": "1234" }, "driverPin": { "value": "4321" }, "brightness": { "value": 128 }, "dateTimeUnits": { "value": "us" }, "voiceRecording": { "value": true }, "standby": { "timeout": 10 }, "hotSpot": { "internetAccess": false, "hotspotEnabled": true }, "recordingEncryption": { "enabled": true, "password": "]cTQ0TNJ[sZb{5TKL4J_+(&z4@C7j~+." }, "privacy": { "gpsEnabled": true, "mvaiEnabled": true, "liveStreamEnabled": true, "allEventsEnabled": true, "cameras": [ { "cameraId": 1, "recordingEnabled": true, "eventsEnabled": true } ] }, "pinCodeDi": { "value": true }, "qrDi": { "value": true }, "driverIdentification": { "driverPrompt": true, "audioAlert": true, "driverPromptDurationSeconds": 30 }, "virtualIgnition": { "value": true }, "screenTimeout": { "value": 120 }, "passengerLimit": { "value": 1 }, "wakeupMsg": { "enabled": true, "timeout": 10 }, "ledEnabled": { "value": true }, "setTimezoneByCloud": { "value": true } }; axios.post(`https://your-api-domain.com/organizations/${orgId}/device-settings`, deviceSettings, { headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${authToken}` } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('Error:', error); }); ``` -------------------------------- ### Update Device Settings (Node.js) Source: https://developer.surfsight.net/developer-portal/surfsightapi/reference/operation/postOrganizationDeviceSettings This Node.js example utilizes the 'axios' library to send a POST request to update device settings. It demonstrates how to configure the request with the correct headers and JSON payload. ```javascript const axios = require('axios'); async function updateDeviceSettings(orgId, settings) { try { const response = await axios.post( `/organizations/${orgId}/device-settings`, settings, { headers: { 'Content-Type': 'application/json' } } ); return response.data; } catch (error) { console.error('Error updating device settings:', error.response ? error.response.data : error.message); throw error; } } const deviceSettings = { "adas": { "value": true }, "distractedDriver": { "value": true }, "liveVideo": { "value": true }, "driverCamera": { "value": true }, "textOverlay": { "value": true }, "inCabinCameraRecording": { "value": true }, "driverPosition": { "value": "left" }, "speedUnits": { "value": "mph" }, "audioAlarms": { "value": true }, "notifyLiveStreaming": { "value": true }, "adminPin": { "value": "1234" }, "driverPin": { "value": "4321" }, "brightness": { "value": 128 }, "dateTimeUnits": { "value": "us" }, "voiceRecording": { "value": true }, "standby": { "timeout": 10 }, "hotSpot": { "internetAccess": false, "hotspotEnabled": true }, "recordingEncryption": { "enabled": true, "password": "]cTQ0TNJ[sZb{5TKL4J_+(&z4@C7j~+." }, "privacy": { "gpsEnabled": true, "mvaiEnabled": true, "liveStreamEnabled": true, "allEventsEnabled": true, "cameras": [ { "cameraId": 1, "recordingEnabled": true, "eventsEnabled": true } ] }, "pinCodeDi": { "value": true }, "qrDi": { "value": true }, "driverIdentification": { "driverPrompt": true, "audioAlert": true, "driverPromptDurationSeconds": 30 }, "virtualIgnition": { "value": true }, "screenTimeout": { "value": 120 }, "passengerLimit": { "value": 1 }, "wakeupMsg": { "enabled": true, "timeout": 10 }, "ledEnabled": { "value": true }, "setTimezoneByCloud": { "value": true } }; // Example usage: // updateDeviceSettings('yourOrgId', deviceSettings) // .then(data => console.log('Settings updated:', data)) // .catch(error => console.error('Failed to update settings.')); ``` -------------------------------- ### Retrieve Organization Details - JavaScript Source: https://developer.surfsight.net/openapi/surfsight/operation/getOrganization Example of how to retrieve organization details using JavaScript. This code makes a GET request to the API endpoint, including the necessary authorization header. ```javascript fetch('https://api-prod.surfsight.net/v2/organizations/:orgId', { method: 'GET', headers: { 'Authorization': 'Bearer ' } }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Retrieve Event using Node.js Source: https://developer.surfsight.net/openapi/surfsight/operation/getDeviceEvent A Node.js example using the 'node-fetch' library to retrieve event details. It demonstrates making a GET request with necessary headers for authentication. ```javascript const fetch = require('node-fetch'); async function getEventNode(imei, eventId, token) { const url = `https://api-prod.surfsight.net/v2/devices/${imei}/events/${eventId}`; const options = { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } }; try { const response = await fetch(url, options); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); } catch (error) { console.error('Error fetching event:', error); return null; } } ``` -------------------------------- ### Configure Media for Standby Events (PUT/POST APIs) Source: https://developer.surfsight.net/developer-portal/changelog/changelog_main Allows configuration of video and snapshot media for 'standbyEnter' and 'standbyExit' events. Supports 'none', 'video', and 'snapshot' data types. Video recordings have specific durations relative to the event. ```json { "type": "event", "data": { "id": 7306791, "serialNumber": "357660101039543", "eventType": "cell_phone_use", "time": 1634797394, "lat": 32.1763837, "lon": 34.92067202, "alt": 54.01348876953125, "speed": 32.580000686645505, "other": "", "files": [ { "cameraId": 1, "file": 1634797394, "fileType": "video", "mediaAvailable":true }, { "cameraId": 2, "file": 1634797394, "fileType": "video", "mediaAvailable":false } ] } } ``` -------------------------------- ### Add Lytx Live Video Component to HTML Source: https://developer.surfsight.net/developer-portal/components/reusable-option1 Add the lytx-live-video component to your HTML, providing necessary authentication and identification parameters. Ensure all required parameters are configured before use. ```html ``` -------------------------------- ### Bulk Event Configuration Source: https://developer.surfsight.net/developer-portal/changelog/changelog_firmware Configure event settings for multiple devices in bulk. ```APIDOC ## PUT /devices/event-config ### Description Updates event-specific configurations for multiple devices in bulk. ### Method PUT ### Endpoint `/devices/event-config` ### Parameters #### Request Body - **eventConfigs** (array) - Required - An array of event configuration objects. - **imei** (string) - Required - The IMEI of the device. - **eventType** (string) - Required - The type of event to configure. - **alertsEnabled** (boolean) - Required - Whether to enable alerts for this event type. ### Request Example ```json { "eventConfigs": [ { "imei": "123456789012345", "eventType": "tailgating", "alertsEnabled": true } ] } ``` ### Response #### Success Response (200) - **message** (string) - Success message indicating the bulk event configuration update. #### Response Example ```json { "message": "Bulk event configuration updated successfully." } ``` -------------------------------- ### Create Driver Request Sample (JavaScript) Source: https://developer.surfsight.net/openapi/surfsight/operation/postDrivers A JavaScript example using `fetch` to create a driver. This code snippet shows how to construct the request body and headers for a POST request to the /drivers endpoint. ```javascript const data = { "data": [ { "organizationId": 17, "driverThirdPartyId": "moshe123", "drivingLicense": "10203040", "firstName": "John", "lastName": "Doe" } ] }; fetch('https://api.surfsight.net/v1/drivers?organizationId=17', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### GET /devices/{imei}/trips Source: https://developer.surfsight.net/developer-portal/guides/retrieve-gps-data Retrieve all trips for a specific device within a given time range. The start and end times from the response can be used to fetch complete trip GPS data. ```APIDOC ## GET /devices/{imei}/trips ### Description Retrieve all trips of a device during a specific time range. The `start` and `end` data returned from this response can be used in the `GET /devices/{imei}/gps` call to show complete trips on a map. ### Method GET ### Endpoint `/v2/devices/{imei}/trips` ### Parameters #### Path Parameters - **imei** (string) - Required - The IMEI of the device. #### Query Parameters - **start** (string) - Required - Filter by a start date and time, in ISO 8601 format. - **end** (string) - Required - Filter by an end date and time, in ISO 8601 format. ### Request Example ```json { "request": "curl --request GET 'https://api-prod.surfsight.net/v2/devices/{imei}/trips?start={start}&end={end}' \ --header 'Authorization: Bearer {token}'" } ``` ### Response #### Success Response (200) - **data** (object) - Contains trip details. - **start** (object) - GPS data for the start of the trip. - **lat** (number) - The GPS latitude. - **lon** (number) - The GPS longitude. - **time** (number) - The time, in Unix time. - **subscriptionId** (number) - The ID of the GPS point. - **speed** (number) - The speed, in meters per second. - **accuracy** (number) - The accuracy of the GPS, in meters. - **end** (object) - GPS data for the end of the trip. - **lat** (number) - The GPS latitude. - **lon** (number) - The GPS longitude. - **time** (number) - The time, in Unix time. - **subscriptionId** (number) - The ID of the GPS point. - **speed** (number) - The speed, in meters per second. - **accuracy** (number) - The accuracy of the GPS, in meters. - **duration** (number) - The trip duration, in seconds. - **minSpeed** (number) - The minimum speed during the trip, in meters per second. - **maxSpeed** (number) - The maximum speed during the trip, in meters per second. - **distance** (number) - The trip distance, in kilometers. - **eventsCount** (number) - The number of events in the trip. - **virtualEventsCount** (number) - The number of virtual events in the trip. #### Response Example ```json { "data": { "start": { "lat": 32.17444508, "lon": 34.91930652, "time": 1639216678, "subscriptionId": 11978058081, "speed": 0, "accuracy": 11.792 }, "end": { "lat": 32.09437866, "lon": 34.77290326, "time": 1639218738, "subscriptionId": 11978435298, "speed": 1.919999957084656, "accuracy": 4.288 }, "duration": 2060, "minSpeed": 0, "maxSpeed": 35.02000045776367, "distance": 15.523432137029667, "eventsCount": 2, "virtualEventsCount": 0 } } ``` ``` -------------------------------- ### Retrieve Partner Operational Statistics - Node.js Source: https://developer.surfsight.net/openapi/surfsight/operation/getPartnerOperationalStatistics Example of how to retrieve partner operational statistics using Node.js with the 'node-fetch' library. This demonstrates making an authenticated GET request with query parameters for trend data. ```javascript const fetch = require('node-fetch'); async function getPartnerStatsNode(token, months = 1, weeks = 1) { try { const response = await fetch(`https://api-prod.surfsight.net/v2/partners/operational-statistics?months=${months}&weeks=${weeks}`, { method: 'GET', headers: { 'Authorization': `Bearer ${token}` } }); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } return await response.json(); } catch (error) { console.error('Error fetching partner statistics:', error); throw error; } } // Example usage: // const token = ''; // getPartnerStatsNode(token, 2, 5) // .then(data => console.log(JSON.stringify(data, null, 2))) // .catch(error => console.error('Failed to get stats:', error)); ``` -------------------------------- ### Add Device Request Sample (JavaScript) Source: https://developer.surfsight.net/openapi/surfsight/operation/postOrganizationDevices A JavaScript example demonstrating how to make a POST request to add a device to an organization using fetch. It includes setting the authorization header and the request body. ```javascript fetch("/organizations/{orgId}/devices", { method: "POST", headers: { "Authorization": "Bearer ", "Content-Type": "application/json" }, body: JSON.stringify({ "name": "Aragorn's car", "imei": "357660101000198", "groupId": 32 }) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Bulk Device Configuration Request Samples (JavaScript) Source: https://developer.surfsight.net/developer-portal/surfsightapi/reference/operation/putBulkDeviceConfig This JavaScript code snippet shows how to make a bulk device configuration request using the Fetch API. It constructs the request with the appropriate method, headers, and JSON payload, targeting the device configuration endpoint. ```javascript const apiUrl = 'http://localhost:3000/devices/device-config'; const token = ''; // Replace with your actual token const requestBody = { organizationId: 17, groupIds: [ 32 ], config: { adas: { value: true }, distractedDriver: { value: true }, liveVideo: { value: true }, driverCamera: { value: true }, textOverlay: { value: true }, inCabinCameraRecording: { value: true }, driverPosition: { value: "left" }, speedUnits: { value: "mph" }, audioAlarms: { value: true }, notifyLiveStreaming: { value: true }, adminPin: { value: "1234" }, driverPin: { value: "4321" }, brightness: { value: 128 }, dateTimeUnits: { value: "us" }, voiceRecording: { value: true }, standby: { timeout: 10 }, hotSpot: { internetAccess: false, hotspotEnabled: true }, recordingEncryption: { enabled: true, password: "]cTQ0TNJ[sZb{5TKL4J_+(&z4@C7j~+" }, privacy: { gpsEnabled: true, mvaiEnabled: true, liveStreamEnabled: true, allEventsEnabled: true, cameras: [ { cameraId: 1, recordingEnabled: true, eventsEnabled: true } ] }, pinCodeDi: { value: true }, qrDi: { value: true }, driverIdentification: { driverPrompt: true, audioAlert: true, driverPromptDurationSeconds: 30 }, virtualIgnition: { value: true }, screenTimeout: { value: 120 }, passengerLimit: { value: 1 }, wakeupMsg: { enabled: true, timeout: 10 }, ledEnabled: { value: true }, setTimezoneByCloud: { value: true } } }; fetch(apiUrl, { method: 'PUT', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify(requestBody) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Retrieve External Users (JavaScript) Source: https://developer.surfsight.net/openapi/surfsight/operation/getOrganizationExternalUsers Example using JavaScript to make a GET request to retrieve external users for an organization. This code requires a valid API token and organization ID. ```javascript // JavaScript example would go here ```