Skip to main content

Example: Scheduling an Event

Scheduling an event via API requires multiple calls:

  1. Get ID value of source.
  2. Create a session.
  3. Add source to session.
  4. Create event for the session.

Each step is described below.

Step 1: Get ID Value of Source

Assuming sources already exist, get the list of sources to obtain the source ID value to add to the session. (See Get the Source List for details.)

GET https://192.168.0.168/apis/sources

The server returns a list of all sources. Find the source you wish to schedule, and note its id value:

...
{
  "description": "For API scheduling demo",
  "host": "0.0.0.0",
  "port": 1234,
  "type": "UDP",
  ...
  "id": "35a335fc-96c7-4617-b005-b89c55977606",
  ...
}
...

Step 2: Create a Session

Create a session by issuing a POST /api/sessions request. (See Create a Session for details.)

POST https://192.168.0.168/apis/sessions
{
  "title": "Test Session",
  "description": "Example",
  "syncrecord": true
}

The server returns the following. Note the session ID value for use in the next section.

{
  "data": {
    "title": "Test Session",
    "description": "Example",
    "ctime": 1592339408,
    "mtime": 1592339408,
    "duration": 0,
    "showExternalPlayer": false,
    "externalPlayerLinkActive": false,
    "id": "ccf00271-adda-42b4-895f-bb54338fb932",
    "movieTrackCount": 0,
    "sources": [],
    "recording": false
  }
}

The new session also appears in the web interface:

Step 3: Add Source to Session

Add the selected source to the new session by issuing a POST /apis/sessions/:sessionId/sources request, using the corresponding IDs you noted in the previous two steps (See Add a Session Source for details.)

POST https://192.168.0.168/apis/sessions/ccf00271-adda-42b4-895f-bb54338fb932/sources
{
"sourceId": "35a335fc-96c7-4617-b005-b89c55977606"
}

The server's response confirms the source was added to the session:

{
  "data": {
    "sourceId": "35a335fc-96c7-4617-b005-b89c55977606",
    "description": "For API scheduling demo",
    "host": "0.0.0.0",
    "port": 1230,
    "type": "UDP",
    ...
    "index": 0
  }
}

Step 4: Create Event for the Session

Finally, create the event using the POST /apis/sessions/:sessionId/events request. Use the session ID in the endpoint. (See Create a Session Event for details.)

POST https://192.168.0.168/apis/sessions/ccf00271-adda-42b4-895f-bb54338fb932/events
{
  "module": "session",
"startTime": 1592344800,
  "duration": 7200,
  "type": "weekly-recurring",
  "typeData": {
    "days": ["MON", "WED", "SAT"]
  },
  "command": "set-live",
  "parameters": {
    "record": true
  },
  "active": true
}

The response confirms the scheduled event:

{
  "data": {
    "moduleId": "ccf00271-adda-42b4-895f-bb54338fb932",
  "module": "session",
    "startTime": 1592344800,
    "duration": 7200,
    "type": "weekly-recurring",
    "typeData": {
      "days": [ "MON", "WED", "SAT" ]
    },
    "command": "set-live",
    "parameters": { "record": true },
    "active": true,
    "id": "e808eb59-00c4-4a2e-a0e1-b06a693c7736"
  }
}

And the web interface's Scheduler page is updated with the recurring event:

Schedule Event Result

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.