Sample code for 30+ languages & platforms
React Native

Outlook Calendar List Events

See more Outlook Calendar Examples

Retrieve a list of events in a calendar.

Chilkat React Native Downloads

React Native
import { Http, HttpResponse, JsonObject } from '@chilkat/react-native'

async function chilkatExample() {
  // This example requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const http = new Http();

  // Use your previously obtained access token here: Get Outlook Calendar OAuth2 Access Token (Azure AD v2.0 Endpoint).

  const jsonToken = new JsonObject();
  try {
    jsonToken.loadFile('qa_data/tokens/outlookCalendar.json');
  } catch {
    console.log(jsonToken.lastErrorText);
    return;
  }

  http.authToken = jsonToken.stringOf('access_token');

  // Specify the ID of the calendar to list.
  const calendarId = 'AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAAAiCsAAAA';

  http.setUrlVar('id', calendarId);

  // To list the events in the default calendar, use the following URL: https://graph.microsoft.com/v1.0/me/calendars/events

  const resp = new HttpResponse();
  try {
    await http.httpNoBodyAsync('GET', 'https://graph.microsoft.com/v1.0/me/calendars/{$id}/events', resp);
  } catch {
    console.log(http.lastErrorText);
    return;
  }

  console.log(`Response status code = ${resp.statusCode}`);

  // The HTTP request succeeded if the response status code = 200.
  if (resp.statusCode !== 200) {
    console.log(resp.bodyStr);
    console.log('Failed');
    return;
  }

  const json = new JsonObject();
  json.load(resp.bodyStr);
  json.emitCompact = false;
  console.log(json.emit());

  // Here is a sample response:

  // Use this online tool to generate parsing code from sample JSON: 
  // Generate Parsing Code from JSON

  // {
  //   "value": [
  //     {
  //       "originalStartTimeZone": "originalStartTimeZone-value",
  //       "originalEndTimeZone": "originalEndTimeZone-value",
  //       "responseStatus": {
  //         "response": "",
  //         "time": "datetime-value"
  //       },
  //       "iCalUId": "iCalUId-value",
  //       "reminderMinutesBeforeStart": 99,
  //       "isReminderOn": true
  //     }
  //   ]
  // }

  let originalStartTimeZone = '';
  let originalEndTimeZone = '';
  let responseStatusResponse = '';
  let responseStatusTime = '';
  let iCalUId = '';
  let reminderMinutesBeforeStart = 0;

  let i = 0;
  const countI = json.sizeOfArray('value');
  while (i < countI) {
    json.i = i;
    originalStartTimeZone = json.stringOf('value[i].originalStartTimeZone');
    originalEndTimeZone = json.stringOf('value[i].originalEndTimeZone');
    responseStatusResponse = json.stringOf('value[i].responseStatus.response');
    responseStatusTime = json.stringOf('value[i].responseStatus.time');
    iCalUId = json.stringOf('value[i].iCalUId');
    reminderMinutesBeforeStart = json.intOf('value[i].reminderMinutesBeforeStart');
    json.boolOf('value[i].isReminderOn');
    i++;
  }
}