Events API v2 - Virtual Locations

Skill Level: 
Advanced

This API endpoint allows access for specific virtual locations.

Available Methods

Read

GET http://events.unl.edu/api/v2/virtual-location/{location_id}/

This endpoint is for getting a specific virtual location based on its ID.

HTTP Method


GET

Authentication Requirements


None

Request Data


  • location_id number Required Path
    ID of the virtual location to look up. This will go into the path of the request.

Response Data


  • Status number
    Status code for the request.
  • Message string
    Status message for the request.
  • Data Virtual Location Object | null
    The requested virtual location data or null on error.
    • id string
      The ID of the virtual location.
    • name string
      The name of the virtual location.
    • url string
      The url of the virtual location.
    • default-additional-public-info string | null
      The additional public info of the virtual location or null if none is set. This will be overridden on events.unl.edu if the event has specific virtual location additional public info set.
    • user-id string | null
      The user UID that the virtual location is saved to or null if none is set.
    • calendar-id string | null
      The calendar ID that the virtual location is saved to or null if none is set.

Example Code


Javascript
async function eventsAPI() {
    const response = await fetch('https://events.unl.edu/api/v2/virtual-location/12345/');
    if (response.ok) {
        const response_json = await response.json();
        console.log(response_json.data);
    }
}
CURL
curl -X GET 'https://events.unl.edu/api/v2/virtual-location/12345/'
PHP
function eventsAPI() {
    $url = 'https://events.unl.edu/api/v2/virtual-location/12345/';

    // Make an HTTP GET request using file_get_contents
    $response = file_get_contents($url);

    if ($response !== false) {
        // Decode the JSON response
        $responseData = json_decode($response, true);

        // Check if JSON decoding was successful
        if ($responseData !== null) {
            // Access the 'data' field in the response JSON
            var_dump($responseData);
        } else {
            echo 'JSON decoding error';
        }
    } else {
        echo 'Error fetching data';
    }
}

Create

POST http://events.unl.edu/api/v2/virtual-location/

This endpoint is for creating a new virtual location.

HTTP Method


Post

Authentication Requirements


You must add a header to the request with the header key being Authentication and the value being your API Token.

Request Data


  • name string Required
    The name of the virtual location.
  • url string Required
    The URL of the virtual location.
  • default-additional-public-info string | null
    The additional public info of the location or null if none is set. This will be overridden on events.unl.edu if the event has specific location additional public info set.
  • save-user bool
    If you want this saved to your user then set this to true, otherwise it will default to false. If you do not save it to yourself or one of your calendars you will not be able to edit it in the future.
  • save-calendar bool
    If you want this saved to a calendar then set this to true, otherwise it will default to false. If you do not save it to yourself or one of your calendars you will not be able to edit it in the future.
  • calendar-id string | null
    The calendar ID that the virtual location is saved to if the save-calendar is set.

Response Data


  • Status number
    Status code for the request.
  • Message string
    Status message for the request.
  • Data Virtual Location Object | null
    The newly created virtual location data or null on error.
    • id string
      The ID of the virtual location.
    • name string
      The name of the virtual location.
    • url string
      The web page of the virtual location.
    • default-additional-public-info string | null
      The additional public info of the virtual location or null if none is set. This will be overridden on events.unl.edu if the event has specific virtual location additional public info set.
    • user-id string | null
      The user UID that the virtual location is saved to or null if none is set.
    • calendar-id string | null
      The calendar ID that the virtual location is saved to or null if none is set.

Example Code


Javascript
async function eventsAPI() {

    // Sets up data
    const data = {
        'name': 'WDN Zoom',
        'url': 'https://go.unl.edu/wdn-zoom',
        'default-additional-public-info': 'Password is "webdev"',
        'save-user': true,
        'save-calendar': true,
        'calendar-id': '3809',
    }

    // Sends request with method, headers, and data
    const response = await fetch(
        'https://events.unl.edu/api/v2/virtual-location/',
        {
            method: 'POST',
            headers: {
                'content-type': 'application/json',
                'Authentication': MY_API_TOKEN,
            },
            body: JSON.stringify(data),
        }
    );

    // Checks response and throws error on error
    if (response.ok) {
        const response_json = await response.json();
        console.log(response_json.data);
    } else {
        response.text().then(text => {throw new Error(text)})
    }
}
CURL
curl -X POST https://events.unl.edu/api/v2/virtual-location/ \
-H "Content-Type: application/json" \
-H "Authentication: MY_API_TOKEN" \
-d '{
    "name": "WDN Zoom",
    "url": "https://go.unl.edu/wdn-zoom",
    "default-additional-public-info": "Password is \"webdev\"",
    "save-user": true,
    "save-calendar": true,
    "calendar-id": "3809",
}'
PHP
function eventsAPI() {
    $data = array(
        'name' => 'WDN Zoom',
        'url' => 'https://go.unl.edu/wdn-zoom',
        'default-additional-public-info' => 'Password is "webdev"',
        'save-user' => true,
        'save-calendar' => true,
        'calendar-id' => '3809',
    );

    $jsonData = json_encode($data);

    $apiToken = 'MY_API_TOKEN';

    $url = 'https://events.unl.edu/api/v2/virtual-location/';
    $headers = array(
        'Content-Type: application/json',
        'Authentication: ' . $apiToken,
    );

    // Initialize cURL session
    $ch = curl_init();

    // Set cURL options
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    // Execute cURL session and get the response
    $response = curl_exec($ch);

    // Check if cURL request was successful
    if ($response === false) {
        // Handle cURL error
        echo 'cURL Error: ' . curl_error($ch);
    } else {
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($httpCode === 200) {
            // Successful response
            $responseData = json_decode($response, true);
            var_dump($responseData);
        } else {
            // Error response
            echo 'API Error: ' . $response;
        }
    }

    // Close cURL session
    curl_close($ch);
}

Update

PUT http://events.unl.edu/api/v2/virtual-location/{location_id}/

This endpoint is for updating a specific virtual location based on its ID.

HTTP Method


PUT

Authentication Requirements


You must add a header to the request with the header key being Authentication and the value being your API Token.

Request Data


Even if the data hasn't changed, please re-enter any previously existing data to avoid unintentional null values.

  • location_id string Required Path
    The id of the virtual location to update. This will go into the path of the request.
  • name string Required
    The name of the virtual location.
  • url string Required
    The url of the virtual location.
  • default-additional-public-info string | null
    The additional public info of the virtual location or null if none is set. This will be overridden on events.unl.edu if the event has specific virtual location additional public info set.
  • save-user bool
    If you want this saved to your user then set this to true, otherwise it will default to false. If this is set to false or omitted it will cause the virtual location to be un-saved to you. If another user has the virtual location saved to them this will do nothing.
  • save-calendar bool
    If you want this saved to a calendar then set this to true, otherwise it will default to false. If this is set to false or omitted it will cause the virtual location to be un-saved to your calendar. If you do not have access to the calendar it is saved to this will do nothing.
  • calendar-id string | null
    The calendar ID that the virtual location is saved to if the save-calendar is set.

Response Data


  • Status number
    Status code for the request.
  • Message string
    Status message for the request.
  • Data Virtual Location Object | null
    The newly updated virtual location data or null on error.
    • id string
      The ID of the virtual location.
    • name string
      The name of the virtual location.
    • url string
      The URL of the virtual location.
    • default-additional-public-info string | null
      The additional public info of the virtual location or null if none is set. This will be overridden on events.unl.edu if the event has specific virtual location additional public info set.
    • user-id string | null
      The user UID that the virtual location is saved to or null if none is set.
    • calendar-id string | null
      The calendar ID that the virtual location is saved to or null if none is set.

Example Code


Javascript
async function eventsAPI() {

    // Sets up data
    const data = {
        'name': 'WDN Zoom',
        'url': 'https://go.unl.edu/wdn-zoom',
        'default-additional-public-info': 'Password is "webdev"',
        'save-user': true,
        'save-calendar': true,
        'calendar-id': '3809',
    }

    // Sends request with method, headers, and data
    const response = await fetch(
        'https://events.unl.edu/api/v2/virtual-location/12345/',
        {
            method: 'PUT',
            headers: {
                'content-type': 'application/json',
                'Authentication': MY_API_TOKEN,
            },
            body: JSON.stringify(data),
        }
    );

    // Checks response and throws error on error
    if (response.ok) {
        const response_json = await response.json();
        console.log(response_json.data);
    } else {
        response.text().then(text => {throw new Error(text)})
    }
}
CURL
curl -X PUT https://events.unl.edu/api/v2/virtual-location/ \
-H "Content-Type: application/json" \
-H "Authentication: MY_API_TOKEN" \
-d '{
    "name": "WDN Zoom",
    "url": "https://go.unl.edu/wdn-zoom",
    "default-additional-public-info": "Password is \"webdev\"",
    "save-user": true,
    "save-calendar": true,
    "calendar-id": "3809",
}'
PHP
function eventsAPI() {
    $data = array(
        'name' => 'WDN Zoom',
        'url' => 'https://go.unl.edu/wdn-zoom',
        'default-additional-public-info' => 'Password is "webdev"',
        'save-user' => true,
        'save-calendar' => true,
        'calendar-id' => '3809',
    );

    $jsonData = json_encode($data);

    $apiToken = 'MY_API_TOKEN';

    $url = 'https://events.unl.edu/api/v2/location/12345/';
    $headers = array(
        'Content-Type: application/json',
        'Authentication: ' . $apiToken,
    );

    // Initialize cURL session
    $ch = curl_init();

    // Set cURL options
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    // Execute cURL session and get the response
    $response = curl_exec($ch);

    // Check if cURL request was successful
    if ($response === false) {
        // Handle cURL error
        echo 'cURL Error: ' . curl_error($ch);
    } else {
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        if ($httpCode === 200) {
            // Successful response
            $responseData = json_decode($response, true);
            var_dump($responseData);
        } else {
            // Error response
            echo 'API Error: ' . $response;
        }
    }

    // Close cURL session
    curl_close($ch);
}
Contributed By: 
DXG