Skip to content

Instantly share code, notes, and snippets.

@khamidou
Created April 9, 2018 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khamidou/f717ade516f9414eb800041b40e46044 to your computer and use it in GitHub Desktop.
Save khamidou/f717ade516f9414eb800041b40e46044 to your computer and use it in GitHub Desktop.
Creating a calendar event using the Nylas API with PHP and cURL
<?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