{"id":28473241,"url":"https://github.com/nylas/nylas-php","last_synced_at":"2025-07-02T02:31:03.902Z","repository":{"id":57029583,"uuid":"39979179","full_name":"nylas/nylas-php","owner":"nylas","description":null,"archived":false,"fork":false,"pushed_at":"2017-12-16T09:03:20.000Z","size":34,"stargazers_count":18,"open_issues_count":10,"forks_count":27,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-06-07T12:06:38.358Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nylas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-31T00:53:04.000Z","updated_at":"2021-12-02T17:14:31.000Z","dependencies_parsed_at":"2022-08-23T18:50:10.252Z","dependency_job_id":null,"html_url":"https://github.com/nylas/nylas-php","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nylas/nylas-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylas%2Fnylas-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylas%2Fnylas-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylas%2Fnylas-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylas%2Fnylas-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nylas","download_url":"https://codeload.github.com/nylas/nylas-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nylas%2Fnylas-php/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263063919,"owners_count":23408013,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-07T12:06:38.966Z","updated_at":"2025-07-02T02:31:03.892Z","avatar_url":"https://github.com/nylas.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Nylas PHP\n\nPHP bindings for the Nylas REST API [https://www.nylas.com](https://www.nylas.com)\n\n## **NOTE**: The Nylas PHP SDK is currently not actively maintained, and may need some TLC. However, our [Ruby](https://github.com/nylas/nylas-ruby), [Node](https://github.com/nylas/nylas-nodejs) or [Python](https://github.com/nylas/nylas-python) SDKs are fully supported.\n\nPlease feel free to use it and send us a pull request if you fix anything or add a feature, though. :)\n\n## Installation\n\nYou can install the library by running:\n\n```php\ncd nylas-php\ncomposer install\n```\n\n\n## Usage\n\nThe Nylas REST API uses server-side (three-legged) OAuth, and this library provides convenience methods to simplify the OAuth process. Here's how it works:\n\n1. You redirect the user to our login page, along with your App Id and Secret\n1. Your user logs in\n1. She is redirected to a callback URL of your own, along with an access code\n1. You use this access code to get an authorization token to the API\n\nFor more information about authenticating with Nylas, visit the [Developer Documentation](https://www.nylas.com/docs/gettingstarted-hosted#authenticating).\n\nIn practice, the Nylas REST API client simplifies this down to two steps.\n\n## Auth\n\n**index.php**\n\n```php\n$client = new Nylas(CLIENT, SECRET);\n$redirect_url = 'http://localhost:8080/login_callback.php';\n$get_auth_url = $client-\u003ecreateAuthURL($redirect_url);\n\n// redirect to Nylas auth server\nheader(\"Location: \".$get_auth_url);\n```\n\n**login_callback.php**\n\n```php\n$access_code = $_GET['code'];\n$client = new Nylas(CLIENT, SECRET);\n$get_token = $client-\u003egetAuthToken($access_code);\n\n// save token in session\n$_SESSION['access_token'] = $get_token;\n```\n\n\n## Fetching Account Information\n\n```php\n$client = new Nylas(CLIENT, SECRET, TOKEN);\n$account = $client-\u003eaccount();\n\necho $account-\u003eemail_address;\necho $account-\u003eprovider;\n```\n\n\n\n## Fetching Threads\n\n```php\n$client = new Nylas(CLIENT, SECRET, TOKEN);\n\n// Fetch the first thread\n$first_thread = $client-\u003ethreads()-\u003efirst();\necho $first_thread-\u003eid;\n\n// Fetch first 2 latest threads\n$two_threads = $client-\u003ethreads()-\u003eall(2);\nforeach($two_threads as $thread) {\n    echo $thread-\u003eid;\n}\n\n// List all threads with 'ben@nylas.com'\n$search_criteria = array(\"any_email\" =\u003e \"ben@nylas.com\");\n$get_threads = $client-\u003ethreads()-\u003ewhere($search_criteria)-\u003eitems()\nforeach($get_threads as $thread) {\n    echo $thread-\u003eid;\n}\n```\n\n## Working with Threads\n\n```php\n// List thread participants\nforeach($thead-\u003eparticipants as $participant) {\n    echo $participant-\u003eemail;\n    echo $participant-\u003ename;\n}\n\n// Mark as Read\n$thread-\u003emarkAsRead();\n\n// Mark as Seen\n$thread-\u003emarkAsSeen();\n\n// Archive\n$thread-\u003earchive();\n\n// Unarchive\n$thread-\u003eunarchive();\n\n// Trash\n$thread-\u003etrash();\n\n// Star\n$thread-\u003estar();\n\n// Unstar\n$thread-\u003eunstar();\n\n// Add or remove arbitrary tags\n$to_add = array('cfa1233ef123acd12');\n$to_remove = array('inbox');\n$thread-\u003eaddTags($to_add);\n$thread-\u003eremoveTags($to_remove);\n\n// Listing messages\nforeach($thread-\u003emessages()-\u003eitems() as $message) {\n    echo $message-\u003esubject;\n    echo $message-\u003ebody;\n}\n```\n\n## Working with Files\n\n\n```php\n$client = new Nylas(CLIENT, SECRET, TOKEN);\n\n$file_path = '/var/my/folder/test_file.pdf';\n$upload_resp = $client-\u003efiles()-\u003ecreate($file_path);\necho $upload_resp-\u003eid;\n```\n\n## Working with Drafts\n\n```php\n$client = new Nylas(CLIENT, SECRET, TOKEN);\n\n$person_obj = new \\Nylas\\Models\\Person('Kartik Talwar', 'kartik@nylas.com');\n$message_obj = array( \"to\" =\u003e array($person_obj),\n                      \"subject\" =\u003e \"Hello, PHP!\",\n                      \"body\" =\u003e \"Test \u003cbr\u003e message\");\n\n$draft = $client-\u003edrafts()-\u003ecreate($message_obj);\n$send_message = $draft-\u003esend();\necho $send_message-\u003eid;\n```\n\n## Working with Events\n\n```php\n$client = new Nylas(CLIENT, SECRET, TOKEN);\n$calendars = $client-\u003ecalendars()-\u003eall();\n\n$calendar = null;\nfoeach($calendars as $i) {\n  if(!$i-\u003eread_only) {\n    $calendar = $i;\n  }\n}\n\n$person_obj = new \\Nylas\\Models\\Person('Kartik Talwar', 'kartik@nylas.com');\n$calendar_obj = array(\"title\" =\u003e \"Important Meeting\",\n                      \"location\" =\u003e \"Nylas HQ\",\n                      \"participants\" =\u003e array($person_obj),\n                      \"calendar_id\" =\u003e $calendar-\u003eid,\n                      \"when\" =\u003e array(\"start_time\" =\u003e time(),\n                                      \"end_time\" =\u003e time() + (30*60)));\n// create event\n$event = $client-\u003eevents()-\u003ecreate($calendar_obj);\necho $event-\u003eid;\n\n// update\n$event = $event-\u003eupdate(array(\"location\" =\u003e \"Meeting room #1\"));\n\n// delete event\n$event-\u003edelete();\n// delete event (alternate)\n$remove = $client-\u003eevents()-\u003efind($event-\u003eid)-\u003edelete();\n```\n\n\n\n## Open-Source Sync Engine\n\nThe [Nylas Sync Engine](http://github.com/nylas/sync-engine) is open-source, and you can also use the PHP library with the open-source API. Since the open-source API provides no authentication or security, connecting to it is simple. When you instantiate the Nylas object, provide null for the App ID, App Secret, and API Token, and pass the fully-qualified address of your copy of the sync engine:\n\n```php\n$client = new Nylas(CLIENT, SECRET, TOKEN, 'http://localhost:5555/');\n```\n\n## Contributing\n\nWe'd love your help making Nylas better. Join the Google Group for project updates and feature discussion. We also hang out in `#nylas` on [irc.freenode.net](irc.freenode.net), or you can email [support@nylas.com](mailto:support@nylas.com).\n\nPlease sign the Contributor License Agreement before submitting pull requests. (It's similar to other projects, like NodeJS or Meteor.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnylas%2Fnylas-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnylas%2Fnylas-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnylas%2Fnylas-php/lists"}