Reputation: 6159
I'm trying to create a meeting as a application, add attendees, determine time availability.
This is what I have so far :
Auth
private async Task<ClientCredentialProvider> GetToken()
{
var confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(_microsoftAppId)
.WithTenantId(_microsoftTenantId)
.WithClientSecret(_microsoftAppPassword)
.Build();
ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);
return authProvider;
}
Meeting request
public async Task GetMeetingtime()
{
var authProvider = await GetToken();
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var attendees = new List<AttendeeBase>()
{
new AttendeeBase
{
Type = AttendeeType.Required,
EmailAddress = new EmailAddress
{
Name = "john doe",
Address = "[email protected]"
}
},
new AttendeeBase
{
Type = AttendeeType.Required,
EmailAddress = new EmailAddress
{
Name = "john toe",
Address = "[email protected]"
}
}
};
var locationConstraint = new LocationConstraint
{
IsRequired = false,
SuggestLocation = false,
Locations = new List<LocationConstraintItem>()
{
new LocationConstraintItem
{
ResolveAvailability = false,
DisplayName = "Conf room Hood"
}
}
};
var timeConstraint = new TimeConstraint
{
ActivityDomain = ActivityDomain.Work,
TimeSlots = new List<TimeSlot>()
{
new TimeSlot
{
Start = new DateTimeTimeZone
{
DateTime = "2020-12-10T09:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2020-12-10T17:00:00",
TimeZone = "Pacific Standard Time"
}
}
}
};
var isOrganizerOptional = false;
var meetingDuration = new Duration("PT1H");
var returnSuggestionReasons = true;
var minimumAttendeePercentage = (double)100;
await graphClient
.Me
.FindMeetingTimes(attendees, locationConstraint, timeConstraint, meetingDuration, null, isOrganizerOptional, returnSuggestionReasons, minimumAttendeePercentage)
.Request()
.Header("Prefer", "outlook.timezone=\"Pacific Standard Time\"")
.PostAsync();
}
This is the error I get:
Current authenticated context is not valid for this request. This occurs when a request is made to an endpoint that requires user sign-in. For example, /me requires a signed-in user. Acquire a token on behalf of a user to make requests to these endpoints. Use the OAuth 2.0 authorization code flow for mobile and native apps and the OAuth 2.0 implicit flow for single-page web apps.
How can I solve this?
Upvotes: 0
Views: 551
Reputation: 58723
According to docs, the findMeetingTimes API does not support application-only access: https://learn.microsoft.com/en-us/graph/api/user-findmeetingtimes?view=graph-rest-1.0&tabs=http.
It can only be called in the context of a signed-in user.
Now, you could try to use .Users["user-id"]
instead of .Me
just in case the docs are wrong about this.
"me" only makes sense when calling the API on behalf of a user, which you are not.
Calendar events can be created as an application that has write access to the users' calendars.
Upvotes: 2