{"id":18999903,"url":"https://github.com/totalcrm/microsoft-graph-bundle","last_synced_at":"2026-01-11T08:56:57.101Z","repository":{"id":40483238,"uuid":"427922635","full_name":"totalcrm/microsoft-graph-bundle","owner":"totalcrm","description":"Symfony Bundle MicrosoftGraph API Integration by TotalCRM ","archived":false,"fork":false,"pushed_at":"2022-08-16T14:12:19.000Z","size":77,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-27T13:46:06.992Z","etag":null,"topics":["bundle","calendar","contacts","microsoftgraph","symfony","symfony-bundle"],"latest_commit_sha":null,"homepage":"https://totalcrm.ru","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/totalcrm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-14T12:29:53.000Z","updated_at":"2024-04-09T04:00:41.000Z","dependencies_parsed_at":"2022-08-09T21:50:37.945Z","dependency_job_id":null,"html_url":"https://github.com/totalcrm/microsoft-graph-bundle","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/totalcrm/microsoft-graph-bundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/totalcrm%2Fmicrosoft-graph-bundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/totalcrm%2Fmicrosoft-graph-bundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/totalcrm%2Fmicrosoft-graph-bundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/totalcrm%2Fmicrosoft-graph-bundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/totalcrm","download_url":"https://codeload.github.com/totalcrm/microsoft-graph-bundle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/totalcrm%2Fmicrosoft-graph-bundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271166321,"owners_count":24710464,"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","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bundle","calendar","contacts","microsoftgraph","symfony","symfony-bundle"],"created_at":"2024-11-08T18:05:40.849Z","updated_at":"2026-01-11T08:56:57.089Z","avatar_url":"https://github.com/totalcrm.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TotalCRM MicrosoftGraphBundle\r\n\r\n## Installation\r\n\r\n### Add MicrosoftGraphBundle to your project\r\n\r\nThe recommended way to install the bundle is through Composer.\r\n\r\n```bash\r\n$ composer require 'totalcrm/microsoft-graph-bundle'\r\n```\r\n\r\nSymfony 3: add MicrosoftGraphBundle in AppKernel.php registerBundles()\r\n```php\r\n$bundles = [\r\n    ...,\r\n    New TotalCRM\\MicrosoftGraph\\MicrosoftGraphBundle(),\r\n];\r\n```\r\nSymfony 4 and up: add MicrosoftGraphBundle in bundles.php\r\n```php\r\nreturn [\r\n    ...,\r\n    TotalCRM\\MicrosoftGraph\\MicrosoftGraphBundle::class =\u003e ['all' =\u003e true],\r\n];\r\n```\r\n\r\n## Configuration \r\nYou have to configure your api.\r\n\r\nSymfony 3: add to config.yml\r\n \r\nSymfony 4 and up: create config/packages/microsoft_graph.yaml\r\n``` yml\r\nmicrosoft_graph:\r\n    client_id: \"%env(MS_GRAPH_CLIENT_ID)%\"\r\n    client_secret: \"%env(MS_GRAPH_CLIENT_SECRET)%\"\r\n    tenant_id: \"%env(MS_GRAPH_TENANT_ID)%\"\r\n    contact_folder: \"%env(MS_GRAPH_CONTACT_FOLDER)%\"\r\n    redirect_uri: \"app_dashboard\"\r\n    homepage_route: \"app_dashboard\"\r\n    prefer_time_zone: \"%env(MS_GRAPH_TIMEZONE_UTC)%\" \r\n    version: \"1.0\"\r\n    scopes:  # see more details https://developer.microsoft.com/en-us/graph/docs/authorization/permission_scopes\r\n        - openid\r\n        - offline_access\r\n        - Contacts.Read\r\n        - Contacts.ReadWrite\r\n        - Contacts.ReadWrite.Shared\r\n        - Calendars.Read\r\n        - Calendars.Read.Shared\r\n        - Calendars.ReadWrite\r\n        - Tasks.ReadWrite\r\n        ...\r\n```\r\n\r\n# Get token from Office 365 | API Graph\r\n``` php\r\n    /** @var MicrosoftGraphClient $graphClient */\r\n    $graphClient = $container-\u003eget('microsoft_graph.client');\r\n\r\n    try {\r\n        /* if you have a refresh token then  the token will refresh */\r\n        $graphClient-\u003egetNewToken();\r\n    } catch(\\Exception $ex) {\r\n        /* return url by Authorization */\r\n\r\n        $url = $graphClient-\u003eredirect();\r\n\r\n        /*\r\n        Follow the link $url and login in to Microsoft Office 365 Service\r\n        After successful authorization, you should be redirected to the redirect_uri page with the code parameter, which you need to save\r\n        See set token Office 365 auth and cached\r\n        */\r\n    }\r\n```\r\n# Set token Office 365 auth and cached\r\n``` php\r\n    /** @var MicrosoftGraphClient $graphClient */\r\n    $graphClient = $container-\u003eget('microsoft_graph.client');\r\n    $authorizationCode = \"0.AQUAIIWUa9rYQEKaSsxrxOyxTP-AiocQKThAr3_TKz.......\";\r\n\r\n    try {\r\n        $this-\u003egraphClient-\u003esetAuthorizationCode($authorizationCode);\r\n    } catch (\\Exception $exception) {\r\n        if ($exception-\u003egetMessage() === 'invalid_grant') {\r\n            /*\r\n            OAuth2 Authorization code was already redeemed\r\n            Please retry with a new valid code or use an existing refresh token\r\n            */\r\n        } else {\r\n            /*\r\n            Authorization code save error\r\n            Please retry with a new valid code or use an existing refresh token\r\n            */\r\n        }\r\n    }\r\n\r\n```\r\n\r\n\r\n# Example get contacts in folder\r\n``` php\r\n    /** @var MicrosoftGraphContactManager $contactManager */\r\n    $contactManager = $container-\u003eget('microsoft_graph.contact_manager');\r\n    \r\n    //Get Contacts by Folder\r\n    /** @var Microsoft\\Graph\\Model\\Contact[] $folders */\r\n    $folders = $contactManager-\u003egetContactFolders();\r\n    dump($contacts);\r\n\r\n    foreach ($folders as $folder) {\r\n        /** @var Microsoft\\Graph\\Model\\Contact[] $contacts */\r\n        $contacts = $contactManager-\u003egetContacts($folder-\u003egetId());\r\n        dump($contacts);\r\n    }\r\n\r\n    //Get All Contacts \r\n    /** @var Microsoft\\Graph\\Model\\Contact[] $contacts */\r\n    $contacts = $contactManager-\u003egetContacts();\r\n    dump($contacts);\r\n```\r\n\r\n# Example get contact by id\r\n``` php\r\n    $id = '...';\r\n    $contact = $contactManager-\u003egetContact($id);\r\n    dump($contacts);\r\n```\r\n # Create an contact\r\n``` php\r\n\r\n    /** @var Microsoft\\Graph\\Model\\PhysicalAddress $businessAddress */\r\n    $businessAddress = new Model\\PhysicalAddress();\r\n    $businessAddress\r\n        -\u003esetPostalCode('PostalCode')\r\n        -\u003esetCity('City')\r\n        -\u003esetState('State')\r\n        -\u003esetStreet('Street')\r\n        -\u003esetCountryOrRegion('Country')\r\n    ;\r\n\r\n    /** @var Microsoft\\Graph\\Model\\EmailAddress $emailAddress */\r\n    $emailAddress = new EmailAddress();\r\n    $emailAddress\r\n        -\u003esetName('DisplayName')\r\n        -\u003esetAddress('email@gmail.com')\r\n    ;\r\n    \r\n    /** @var Microsoft\\Graph\\Model\\Contact $newContact */\r\n    $newContact = new Model\\Contact();\r\n    $newContact\r\n        -\u003esetNickName('NickName')\r\n        -\u003esetDisplayName('DisplayName')\r\n        -\u003esetMiddleName('MiddleName')\r\n        -\u003esetGivenName('GivenName')\r\n        -\u003esetBusinessAddress($businessAddress)\r\n        -\u003esetEmailAddresses($emailAddress)\r\n        ...\r\n    ;\r\n\r\n    $contact = $contactManager-\u003eaddContact($newContact);\r\n    dump($contact);\r\n```\r\n\r\n# Example get events from outlook calendar\r\n``` php\r\n// Get calendar service \r\n    $calendarManager = $this-\u003eget('microsoft_graph.calendar');\r\n            \r\n//Get a collection of Microsoft\\Graph\\Model\\Event\r\n    $startTime = new DateTime(\"first day of this month\");\r\n    $endTime = new DateTime(\"first day of next month\");\r\n    \r\n    $events = $calendarManager-\u003egetEvents($startTime,$endTime);\r\n\r\n//Get a  Microsoft\\Graph\\Model\\Event\r\n    $id='...';\r\n    $event = $calendarManager-\u003egetEvent($id);\r\n     \r\n```\r\n # Create an event\r\n``` php\r\n//  create Microsoft\\Graph\\Model\\Event and set properties\r\n    $newEvent = new Microsoft\\Graph\\Model\\Event();              \r\n    $start = $calendar-\u003egetDateTimeTimeZone(new \\DateTime('Now next minute'));\r\n    $end = $calendar-\u003egetDateTimeTimeZone(new \\DateTime('Now next hour'));\r\n    \r\n    $newEvent-\u003esetSubject('Controller Test Token');\r\n    $newEvent-\u003esetStart($start);\r\n    $newEvent-\u003esetEnd( $end);     \r\n\r\n    $event= $calendarManager-\u003eaddEvent( $newEvent);\r\n    \r\n    dump($event);\r\n```\r\n # Update an event\r\n``` php\r\n    $id = '...';\r\n    $updateEvent = new Microsoft\\Graph\\Model\\Event(); \r\n    $updateEvent-\u003esetId($id);\r\n    $updateEvent-\u003esetSubject(\"I Forgot The Eggs!\");\r\n    $event = $calendarManager-\u003eupdateEvent($updateEvent);\r\n``` \r\n # Delete an event\r\n``` php\r\n    $id='...';\r\n    $response = $calendar-\u003edeleteEvent($id);\r\n    dump($response-\u003egetStatus()==204 ? \"Event deleted\" : $response);\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftotalcrm%2Fmicrosoft-graph-bundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftotalcrm%2Fmicrosoft-graph-bundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftotalcrm%2Fmicrosoft-graph-bundle/lists"}