Creating a calendar event - location information ignored

Carl Ogden 121 Reputation points
2021-10-08T12:02:07.267+00:00

Hi

I've got the following code, which creates an appointment from our web based system in Outlook Calendar. But, the location just shows the address as text and not as a configured location. Can someone help in what I've done wrong?

                        $app_location = [
                            'displayName'  => $location,
                            'locationType' => 'Default',
                            'address' => [
                                'street'          => $property->AddressLn1,
                                'city'            => $property->AddressLn2,
                                'state'           => $property->AddressTown,
                                'countryOrRegion' => $property->AddressCounty,
                                'postalCode'      => $property->PostCode,
                            ],
                            'coordinates' => [
                                'latitude'  => $property->Latitude,
                                'longitude' => $property->Longitude,
                            ]
                        ];
                        $locations = [
                            'displayName'   => $location,
                            'address' => [
                                'street'          => $property->AddressLn1,
                                'city'            => $property->AddressLn2,
                                'state'           => $property->AddressTown,
                                'countryOrRegion' => $property->AddressCounty,
                                'postalCode'      => $property->PostCode,
                            ],
                            'coordinates' => [
                                'latitude'  => $property->Latitude,
                                'longitude' => $property->Longitude,
                            ],
                        ];
                        $newEvent = [
                            'subject'                    => $event_subject,
                            'isReminderOn'               => $isReminderOn,
                            'reminderMinutesBeforeStart' => $reminderMinutesBeforeStart,
                            'isAllDay'                   => $isAllDay,
                            'showAs'                     => $showAs,
                            'sensitivity'                => $sensitivity,
                            'body'                       => [
                                'content' => $notes,
                                'contentType' => 'text'
                            ],
                            'start' => [
                                'dateTime' => $app_start_date,
                                'timeZone' => $viewData['userTimeZone']
                            ],
                            'end' => [
                                'dateTime' => $app_end_date,
                                'timeZone' => $viewData['userTimeZone']
                            ],
                            'attendees'     => $attendees,
                            'location'      => [$app_location],
                            'locations'     => [$locations],
                            'transactionId' => $appointment_id,
                        ];

Thanks for any help in advance.
Carl.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,666 questions
0 comments No comments
{count} votes

Accepted answer
  1. Shweta Choudhary 601 Reputation points Microsoft Employee
    2021-10-18T11:28:39.29+00:00

    Thank you for reaching out.

    If you're organizing an event that involves a meeting location:

    Set the location property of the event accordingly.
    Set the optional locationEmailAddress property if the meeting location has an email address.
    Additionally, if the meeting location has been set up as a resource, or if the event involves some equipment that has been set up as a resource:

    Invite the resource as an attendee.
    Set the attendee type property as resource.
    Set the attendee emailAddress as the resource email address.

    Sample code for creating an event that occurs in multiple locations (Javascript)

     const options = {
         authProvider,
        };
    
        const client = Client.init(options);
    
        const event = {
          subject: 'Plan summer company picnic',
          body: {
            contentType: 'HTML',
            content: 'Let\'s kick-start this event planning!'
          },
          start: {
              dateTime: '2017-08-30T11:00:00',
              timeZone: 'Pacific Standard Time'
          },
          end: {
              dateTime: '2017-08-30T12:00:00',
              timeZone: 'Pacific Standard Time'
          },
          attendees: [
            {
              emailAddress: {
                address: 'DanaS@contoso.onmicrosoft.com',
                name: 'Dana Swope'
              },
              type: 'Required'
            },
            {
              emailAddress: {
                address: 'AlexW@contoso.onmicrosoft.com',
                name: 'Alex Wilber'
              },
              type: 'Required'
            }
          ],
          location: {
            displayName: 'Conf Room 3; Fourth Coffee; Home Office',
            locationType: 'Default'
          },
          locations: [
            {
              displayName: 'Conf Room 3'
            },
            {
              displayName: 'Fourth Coffee',
              address: {
                street: '4567 Main St',
                city: 'Redmond',
                state: 'WA',
                countryOrRegion: 'US',
                postalCode: '32008'
              },
              coordinates: {
                latitude: 47.672,
                longitude: -102.103
              }
            },
            {
              displayName: 'Home Office'
            }
          ],
          allowNewTimeProposals: true
        };
    
        await client.api('/me/events')
         .post(event);
    

    Thanks

    0 comments No comments

0 additional answers

Sort by: Most helpful