Skip to content

PrasadChinwal/laravel-microsoft-graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Microsoft Graph

A wrapper to integrate Microsoft Graph Api's to a Laravel Application.

Installation

  • composer require prasadchinwal/microsoft-graph
  • Run php artisan vendor:publish and publish the config file.
  • Edit the config/microsoft-graph.php file to configure your settings. You need Tenant, Client ID and Client Secret.

Usage:


User API

  1. Get users: Documentation

    Retrieves all the users.

    $graph = MicrosoftGraph::users()->get();
    dd($graph);
  2. Get user from ID: Documentation

    Retrieves a user from principalName.

    $graph = MicrosoftGraph::users()
    ->find('[email protected]');
    dd($graph);

Calendar Api


  1. Get user Calendars: Documentation

    Retrieves the users Calendar.

    $graph = MicrosoftGraph::calendar()
        ->for('user_email')
        ->get();
    dd($graph->first()->name); // To retrieve the name of the Calendar
  2. Get user Schedule : Documentation

    Retrieves the users Schedule.

    $users = ['[email protected]', '[email protected]'];
    $graph = MicrosoftGraph::calendar()
        ->for('[email protected]')
        ->schedule(users:$users, from: Carbon::now(), to: Carbon::now()->addDays(2), timezone: 'UTC', interval: 60);
    dd($graph);
  3. Get Calendar view for a user : Documentation

    Retrieves the calendar view for the user.

    MicrosoftGraph::calendar()
        ->for('[email protected]')
        ->view(
            start: \Carbon\Carbon::now()->toIso8601String(),
            end: \Carbon\Carbon::now()->toIso8601String(),
        );

Events API


  1. Get user Calendar events : Documentation

    Retrieves the users Calendar Events.

    $graph = MicrosoftGraph::event()
        ->for('[email protected]')
        ->get();
    dd($graph->first()->subject); // To retrieve subject of first event.

    You can also filter the events:

    For List of all filters please refer to docs https://learn.microsoft.com/en-us/graph/filter-query-parameter?tabs=http.

    $graph = MicrosoftGraph::event()
            ->for('[email protected]')
            ->where("start/dateTime", "ge", "2024-04-17")
            ->where("end/dateTime", "le", "2024-04-26")
            ->get();
  2. Create new Event for a user : Documentation

    Creates an event in calendar for the user.

  • Generate Event class using php artisan make:graph-event TestGraphEvent
  • Edit the Event class as required filling in necessary details about the event.
 $graph = MicrosoftGraph::event()
->create(new TestGraphEvent());
 dd($graph);
  1. Update an existing Event for a user : Documentation

    Updates an event in calendar for the user.

  • Edit the Event class as required filling in necessary details about the event.
     $graph = MicrosoftGraph::event()
         ->update(
                 new TestGraphEvent(),
                 eventId:'AAMk'
             );
     dd($graph);
  1. Cancel an event for a user : Documentation

    Cancels the event in calendar for the user.

     $graph = MicrosoftGraph::event()
     ->for('[email protected]')
     ->cancel(eventId: 'AAMk', message:"Cancelling via web request!");
     dd($graph);
  2. Accept an event for a user : Documentation

    Accept the event in calendar for the user.

     $graph = MicrosoftGraph::event()
         ->for('[email protected]')
         ->accept(eventId: 'AAMk', message:"Accepting via web request!");
     dd($graph);
  3. Decline an event for a user : Documentation

    Decline the event in calendar for the user.

  • Edit the Event class as required filling in necessary details about the event.
     $graph = MicrosoftGraph::event()
         ->for('[email protected]')
         ->decline(eventId: 'AAMk', message:"Declining via web request!");
     dd($graph);