Created
April 9, 2018 19:19
-
-
Save khamidou/f717ade516f9414eb800041b40e46044 to your computer and use it in GitHub Desktop.
Creating a calendar event using the Nylas API with PHP and cURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"; | |
$CALENDAR_ID = "The id of a calendar you got from the Nylas /calendars API"; | |
$ch = curl_init("https://api.nylas.com/events"); | |
# Setup request to send json via POST. | |
$payload = json_encode( | |
array("title" => "Alan Turing Birthdate", | |
"description" => "Alan Turing Birthdate", | |
"when" => array("object" => "date", "date" => "1912-06-23"), | |
"calendar_id" => $CALENDAR_ID, | |
)); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); | |
# Pass the access token as an HTTP basic auth username | |
curl_setopt($ch, CURLOPT_USERPWD, $ACCESS_TOKEN . ":"); | |
# Return response instead of printing. | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
# Send request. | |
$result = curl_exec($ch); | |
curl_close($ch); | |
# Print response. | |
echo $result; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment