Can't fetch supported time zones in Iana format - microsoft-graph-api

Trying to fetch supported time zones in Iana format from MS Graph using this code
var timeZones = await graphServiceClient
.Me
.Outlook
.SupportedTimeZones(TimeZoneStandard.Iana)
.Request()
.GetAsync();
I get this error
The parameter 'TimeZoneStandard=Iana' is not in scope.
Making the same call without the TimeZoneStandard.Iana parameter succceeds. Is TimeZoneStandard.Iana not supported?

Parameter needs to be correctly given as
(microsoft.graph.timeZoneStandard'Iana') as shown in below image.
Please check this image
Please refer this document for better understanding.

Related

How to convert UTC timezone to CET timezone in graph api?

Am tried with this piece of code
var Option = new List<Option>()
{
new QueryOption("startDateTime", filterStartDate.ToLongDateString()),
new QueryOption("endDateTime", filterEndDate.ToLongDateString()),
new HeaderOption("Prefer","outlook.timezone=\"Central European Time\"")
};
but am getting the bad request error.
Can anyone help me with this?
I have 2 ideas on your scenario, the first is that, according to the official sample, you can add Prefer request header like this if you used Graph SDK.
var events = await graphClient.Me.Events
.Request()
.Header("Prefer","outlook.timezone=\"Pacific Standard Time\"")
.Select("subject,body,bodyPreview,organizer,attendees,start,end,location")
.GetAsync();
By the way, the time zone you used is Central European Time but it's not supported by graph api. Per my searching, only Central European Standard Time can be found.
In general, the timeZone property can be set to any of the time zones currently supported by Windows, as well as the additional time zones supported by the calendar API.
The correct time zone is Central Europe Standard Time not Central European Time.
If you are calling calendar view events, startDateTime and endDateTime must be represented in ISO 8601 format.
var queryOptions = new List<QueryOption>()
{
new QueryOption("startDateTime", filterStartDate.ToUniversalTime().ToString("o")),
new QueryOption("endDateTime", filterEndDate.ToUniversalTime().ToString("o"))
new HeaderOption("Prefer","outlook.timezone=\"Central Europe Standard Time\"")
};
var calendarView = await graphClient.Me.Calendar.CalendarView
.Request(queryOptions)
.GetAsync();

Is there a way to get all Internet Message Headers of an item attachment?

I have a requirement to read all Internet Message Headers of an Item Attachment.
Using following query, it is possible to get headers. But not all.
var itemAttachment = await graphServiceClient.Users["id"]
.Messages[messageId]
.Attachments[messageWithItemAttachment[0].Id]
.Request()
.Expand($"microsoft.graph.itemAttachment/item")
.GetAsync();
I have found following resource which provides a way to read missing headers of an item.
Get message using Graph missing some InternetMessageHeaders
I need to know how can I use such expansion within a expand query?

Microsoft graph delta query documentation clarification

I am going through documentation for Microsoft Graph https://learn.microsoft.com/en-us/graph/delta-query-events?tabs=java and found that section "The next round: sample first request" doesn't include delta query as part of request in which case the current state meaning all the events should be returned.
Also, I see that the same request has no start or end date. I am aware that this call is being made using the deltaToken received in last call. So, should start and end Date be passed while making a call where I am using deltaToken to fetch the next set of changes?
Below is the code used in Documentation(Neither deltaToken is included nor Start and End date):
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new HeaderOption("Prefer", "odata.maxpagesize=2"));
IEventDeltaCollectionPage delta = graphClient.me().calendarView()
.delta()
.buildRequest( requestOptions )
.get();
Please help. Thanks in advance.
Any query parameter provided in the initial Delta query will be encoded in the Delta or skip token, this is why you don't need to pass it every time. (Start and end dates)
There seems to be an issue with this documentation page, it's never showing to use the Delta link and passing it back as a Delta token query parameter (similar to what's done with the skiptoken). I'll PR the docs tomorrow to get that fixed.

When is Microsoft Graph API finished calculating in Excel?

I can see how to trigger the calculation of a spreadsheet using Microsoft Graph API here...
https://learn.microsoft.com/en-us/graph/api/workbookapplication-calculate?view=graph-rest-1.0&tabs=http
But, when I pull the results from the calculations they don't seem to be updated. However, I pull a second or third time, it is usually updated.
I assume this means that calculation hasn't finished b/c of the size of the file or complexity of the calcs.
However, being asynchronous, I'm not finding any way to check to see when the calculations have finished.
Any idea how to do this?
UPDATE 1:
This is the code I'm (now) using to create the session (per #UJJAVAL123-MSFT)
var persistChanges = false;
var wrkbk = await graphClient.Me.Drive.Items[strItemId].Workbook
.CreateSession(persistChanges)
.Request()
.PostAsync();
This will give me a value for 'id' like this...
cluster=US5&session=15.SN3PEPF000074ED1.A82.1.V24.7737Nwad4oPuVafaO%2fpAkiay14.5.en-US5.en-US26.10037ffe965d2cf2-Unlimited1.A1.N16.16.0.12904.3505114.5.en-US5.en-US1.V1.N0.1.A&usid=1b230e8f-3bd0-cdaa-2da6-47db74154075
I'm not exactly sure how/where to use this, or whether I use the entire thing (it looks like a query string) or if I'm supposed to parse and pull out one of the values...
cluster=US5
session=15.SN3PEPF000074ED1.A82.1.V24.xxxxxxxxxxxxxxxxx%2fpAkiay14.5.en-US5.en-US26.10037ffe965d2cf2-Unlimited1.A1.N16.16.0.12904.3505114.5.en-US5.en-US1.V1.N0.1.A
usid=1b230e8f-3bd0-cdaa-2da6-xxxxxxxxxxxx
and this is the code i'm using to trigger the calculation, but not sure how to connect the two...
var calculationType = "FullRebuild";
await graphClient.Me.Drive.Items[strItemId].Workbook.Application
.Calculate(calculationType)
.Request()
.PostAsync();
Also, I'm seeing that it is possible to create, refresh and close a session, but not entirely sure how to check on a specific async process inside that session.
Here is the code I'm using to check a specific range for a value, not sure where we pass the session-id here either...
var result = await graphClient.Me.Drive.Items[strItemId].Workbook.Worksheets[strSheetName]
.Range(strRangeName)
.Request()
.GetAsync();
UPDATE 2:
I can run an API call (presumably) in the same session successfully by passing the workbook-session-id (which is the ENTIRE string shown above) and I get the expected 204 No Content response. However, it is not clear from the c# Code Snippet in the Microsoft Graph Explorer how to pass the workbook-session-id in the request.
Here is the code it provides...
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
await graphClient.Me.Drive.Items["{item-id}"].Workbook.Application
.Calculate(null)
.Request()
.PostAsync();
So the question remains, how can I do a PostAsync or GetAsync and reference the workbook-session-id?
This code does NOT give me an error...
await graphClient.Me.Drive.Items[strItemId].Workbook.Application
.Calculate(calculationType)
.Request()
.Header("workbook-session-id",wrkbk.Id)
.PostAsync();
So now, the question is WHEN do I get the workbook-session-id? Do I get it when I initially open the workbook and then pass it to every call?
You should create a session and pass the session Id with each request. The presence of a
session Id in the requests ensures that you are using the Excel API in the most efficient
way possible.
Check here for API call to get a session
So after a decent amount of testing, i figured it out.
The answer is that you use the CreateSession method (https://learn.microsoft.com/en-us/graph/api/workbook-createsession?view=graph-rest-1.0&tabs=http) to get the workbook info, and you set the persistChanges setting, then you get back info about the workbook session.
Like this...
using Microsoft.Graph;
// strItemId = the id from the microsoft graph api of the item
// strUserId = the id of the user from the microsoft graph api (note: must have permissions set correctly)
public static async Task<WorkbookSessionInfo> GetWorkbookSessionId(string strItemId, string strUserId)
{
// true = you can see changes in the workbook
// false = don't update the workbook, just do calculations
var persistChanges = true;
try
{
var wrkbk = await graphClient.Users[strUserId].Drive.Items[strItemId].Workbook
.CreateSession(persistChanges)
.Request()
.PostAsync();
var result = wrkbk;
return result;
}
catch (Exception ex)
{
Console.WriteLine($"Error getting items: {ex.Message}");
return null;
}
}
And you are returned a WorkbookSessionInfo object, which includes the SessionId for use in subsequent calls. This way, it keeps all your calls in the same session!
https://learn.microsoft.com/en-us/graph/api/resources/workbooksessioninfo?view=graph-rest-1.0

OneDrive API returns files that are not available

I use the MS Graph API to upload data to OneDrive.
I have deleted all data on OneDrive, but when I use the :
var search = await graphClient.Users[user.Id].Drive.Root
.Search("")
.Request()
.GetAsync();
foreach (var item in search)
{
Console.WriteLine(item.Name);
}
I get data displayed even though my OneDrive is empty, why ?
I use:
.Net 4.7.2,
Visual Studio
The solution is:
If I use this code:
var search = await graphClient.Users[user.Id].Drive.Root
.Search("")
.Request()
.GetAsync();
He's searching through the index.
Data can also be displayed there although it is no longer available.
Therefore, data that is no longer available on OneDrive is also displayed.
Do not use the search function.

Resources