React Native Requires Chilkat v11.0.0+
React Native
MS Graph Create Calendar
See more Microsoft Calendar Examples
Creates a new calendar.For more details, see https://docs.microsoft.com/en-us/graph/api/user-post-calendars?view=graph-rest-1.0
Chilkat React Native Downloads
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 as shown here:
// Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope.
const jsonToken = new JsonObject();
try {
jsonToken.loadFile('qa_data/tokens/msGraphCalendar.json');
} catch {
console.log(jsonToken.lastErrorText);
return;
}
http.authToken = jsonToken.stringOf('access_token');
// Create a JSON body for the HTTP POST
// {
// "name": "Work"
// }
const json = new JsonObject();
json.updateString('name', 'Work');
// POST the JSON to https://graph.microsoft.com/v1.0/me/calendars
const resp = new HttpResponse();
try {
await http.httpJsonAsync('POST', 'https://graph.microsoft.com/v1.0/me/calendars', json, 'application/json', resp);
} catch {
console.log(http.lastErrorText);
return;
}
json.load(resp.bodyStr);
json.emitCompact = false;
if (resp.statusCode !== 201) {
console.log(json.emit());
console.log(`Failed, response status code = ${resp.statusCode}`);
return;
}
console.log(json.emit());
// A sample response:
// {
// "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/calendars/$entity",
// "id": "AQMkAD...TgAAAA==",
// "name": "Work",
// "color": "auto",
// "changeKey": "5+vF7T...HjDcA==",
// "canShare": true,
// "canViewPrivateItems": true,
// "canEdit": true,
// "owner": {
// "name": "...",
// "address": "outlook_3A33...4CC15@outlook.com"
// }
// }
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
const odataContext = json.stringOf('"@odata.context"');
const id = json.stringOf('id');
const name = json.stringOf('name');
const color = json.stringOf('color');
const changeKey = json.stringOf('changeKey');
const canShare = json.boolOf('canShare');
const canViewPrivateItems = json.boolOf('canViewPrivateItems');
const canEdit = json.boolOf('canEdit');
const ownerName = json.stringOf('owner.name');
const ownerAddress = json.stringOf('owner.address');
console.log('Success.');
}