How to retrieve extended properties of type datetime? - microsoft-graph-api

As a followup to How to retrieve extended properties for calendar event (by name)?: I can retrieve integer and string values with the singleValueExtendedProperties expansion, but how to retrieve dateTime values?
This fails ({{ }} are Postman variables):
https://graph.microsoft.com/v1.0/users/{{UserID}}/calendar/events/{{TTSyncedEventID}}?$expand=singleValueExtendedProperties($filter=id eq 'dateTime {00020329-0000-0000-C000-000000000046} Name TTSyncTime')
...with a not very helpful response:
{
"error": {
"code": "ErrorInvalidProperty",
"message": "PropertyId values may only be in one of the following formats: 'MapiPropertyType namespaceGuid Name propertyName', 'MapiPropertyType namespaceGuid Id propertyId' or 'MapiPropertyType propertyTag'."
}
}
I have tried several variations on date(Time) but without success...

Found it thanks to Vicky's comments.
These datetime properties were created with EWS in the same manner as the integer/string values described in the earlier SO question.
That code contains PropertyType="SystemTime", and that is exactly what I need to use:
<typ:SetItemField>
<typ:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings" PropertyName="TTSyncTime" PropertyType="SystemTime"/>
<typ:CalendarItem>
<typ:ExtendedProperty>
<typ:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings" PropertyName="TTSyncTime" PropertyType="SystemTime"/>
<typ:Value>UTCString</typ:Value>
</typ:ExtendedProperty>
</typ:CalendarItem>
</typ:SetItemField>
So the proper query becomes:
https://graph.microsoft.com/v1.0/users/{{UserID}}/calendar/events/{{TTSyncedEventID}}?$expand=singleValueExtendedProperties($filter=id eq 'SystemTime {{PS_PUBLIC_STRINGS_NameSpace}} Name TTSyncTime')
({{ }} are Postman variables)

As per the doc ,there is already start/dateTime property outside of singleValueExtendedProperties , so you can directly call the API - https://graph.microsoft.com/v1.0/me/calendar/events?$filter=start/dateTime eq '2022-12-28T12:30:00Z'

Related

Graph Api officeLocation

I am trying to run:
https://graph.microsoft.com/beta/users?$filter=startsWith(officeLocation, 'MOD')
and according to Microsoft Docs user resource type:
officeLocation String
Supports $filter (eq, ne, not, ge, le, in, startsWith, and eq on null values).
However, the response I am getting is:
"error": { "code": "Request_UnsupportedQuery", "message": "Unsupported or invalid query filter clause specified for property 'officeLocation' of resource 'User'.",
What am I missing or doing wrong?
Try to add query parameter $count=true and header ConsistencyLevel:eventual.
https://graph.microsoft.com/beta/users?$filter=startsWith(officeLocation, 'MOD')&$count=true
Advanced query capabilities on Azure AD directory objects

Filtering users by business phone number with MS Graph API fails

According to the MS Graph API documentation, businessPhones are supported to be used in a $filter query with eq comparison, just like the imAddresses property.
When inspecting Microsoft's use query parameters documentation, there's an example where the imAddresses property is used in a collection filter and it works just fine.
GET https://graph.microsoft.com/v1.0/users?$filter=imAddresses/any(s:s eq 'admin#contoso.com')
My goal ist to list all users that have a specific phone number in their businessPhones collection property.
However, when I try to use the businessPhones property in a similar query, the query does not work as expected.
GET https://graph.microsoft.com/v1.0/users?$filter=businessPhones/any(s:s eq '1234')
Status code: 400
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'businessPhones' of resource 'User'.",
"innerError": {
"date": "2021-07-30T08:07:24",
"request-id": "ac3923be-de11-448f-b2b5-245edc82d20e",
"client-request-id": "ac3923be-de11-448f-b2b5-245edc82d20e"
}
}
}
Any ideas on what I am missing?
You need to use advanced query capabilities, which means you need to add a $count=true query string parameter and a ConsistencyLevel=Eventual header to your request.

Calendar events $filter query on start/timeZone in Microsoft Graph API

I'd like to apply a filter to the https://graph.microsoft.com/v1.0/me/calendars/<calendar>/events endpoint by providing the OData v4.0 $filter as a query parameter, but applying eq to start/timeZone results in an error:
When $filter is subject eq 'My Subject' and start/dateTime eq '1970-01-01T00:00:00.0000000' and end/dateTime eq '1970-01-01T00:01:00.0000000' and start/timeZone eq 'UTC' and end/timeZone eq 'UTC' I get back:
{
"error": {
"code": "InvalidDateTime",
"message": "The value 'UTC' of parameter 'DateTime' is invalid.",
"innerError": {
"request-id": "68f797e2-5059-4a8a-8fc6-0063e31d6498",
"date": "2019-06-07T13:46:54"
}
}
}
The documentation references the Prefer: outlook.timezone header, but only indicates that it applies to the response, and says nothing about interpreting the request:
For all GET operations that return events, you can use the Prefer:
outlook.timezone header to specify the time zone for the event start
and end times in the response.
How can I filter on the (dateTime, timeZone) combination? It would be best if I didn't have to know the timeZone of the event and could instead query based on UTC, but I don't see how to do that either.
Thank you!
You can't filter on timeZone and you shouldn't have too. All DateTime values are stored in UTC. They are only converted into a local time zone when you include Prefer: outlook.timezone
You should be able to simply use
subject eq '{subject}' and start/dateTime eq '{date}T{time}' and end/dateTime eq '{date}T{time}'

Get events that have an custom property set by an add-in

This question is a follow-up to Get custom property set in Outlook Add-In via Microsoft Graph.
My Outlook Office.js add-in is adding some custom properties to an event. It works as expected and I can access those properties using Microsoft Graph, with following GET request:
/v1.0/me/events/{event-id}?$expand=SingleValueExtendedProperties($filter=id%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af')
But now I try to subscribe to push notifications by posting such body to the push notifications endpoint (/v1.0/subscriptions):
{
changeType: "created,updated,deleted",
notificationUrl: `[...my url...]`,
resource: `/users/${userData.id}/events?$filter=singleValueExtendedProperties/any(ep%3A%20ep%2Fid%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af')`,
expirationDateTime: tomorrow,
clientState: "SecretClientState"
}
But I'm getting:
{
"error": {
"code": "ExtensionError",
"message": "Operation: Create; Exception: [Status Code: BadRequest; Reason: Bad Request]",
"innerError": {
"request-id": "01dcece6-0103-4bef-8231-e9ab9480402a",
"date": "2017-04-04T20:20:58"
}
}
}
Tried to set the resource in the request unescaped, but with same result, next thing I tried is the $filter functionality, so did a get request in following format using the MS Graph explorer:
/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep%3A%20ep%2Fid%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af')
but got following error:
{
"error": {
"code": "ErrorInvalidUrlQueryFilter",
"message": "The filter expression for $filter does not match to a single extended property and a value restriction.",
"innerError": {
"request-id": "aca7c8ed-6e30-4490-8feb-7f1d2aed6b88",
"date": "2017-04-04T20:38:28"
}
}
}
does it mean that I also have to filter by value and not only id?
That would be an issue because I want the events that have the property set, but I don't know the value beforehand, I want to read it after I get a push notification.
Is there a way to get events which simply have a custom property set by my add-in, and subscribe to push notifications for events which has this custom property?
EDIT:
When I change id to PropertyId as suggested in the answer I'm getting:
{
"error": {
"code": "BadRequest",
"message": "Could not find a property named 'PropertyId' on type 'microsoft.graph.singleValueLegacyExtendedProperty'.",
"innerError": {
"request-id": "1d3db71e-6ee2-4680-9317-64687813c52a",
"date": "2017-04-05T13:49:45"
}
}
}
EDIT-2:
Now when I add filtering by value, it works:
/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af' and ep/value eq 'foo')
but I wan't all the events with that property regardless the value of it...
EDIT-3
No trying by filtering by value but using the non-equal ne operator:
/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af' and ep/value ne 'Foo')
it seems to work, but this time it looks like it just ignores the filter and returns all events, with and without that custom property set from the add-in.
After several tries I found a way to filter for events/messages that have a custom property regardless it's value:
https://graph.microsoft.com/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af' and ep/value ne null)
with the added important part being and ep/value ne null, whereas something like and ep/value ne 'fooo' didn't work, it just returned everything.
Above filtering works also for filtering of events for which we want subscribe to push events.
I believe the filter query should be
PropertyId eq ....
instead of Id eq ...

O365 API filter on complex types

What is the query to get emails received from a specific sender email address?
I have tried filtering on the "Address" property of the "From" property, which is a "Recipient" complex type according to O365 Microsoft.Exchange.Services.OData.Model namespace.
OData filtering on complex types goes something like this
/Me/Inbox/Messages?$filter=From/Address eq 'email#email.com'
However, this returns the following error:
"error": {
"code": "ErrorInvalidProperty",
"message": "The property 'Address' is invalid.",
"innererror": {
"message": "The property 'Address' is invalid.",
"type": "Microsoft.Exchange.Services.OData.InvalidPropertyException",
"stacktrace": " at Microsoft.Exchange.Services.OData.SchemaExtensions.ResolveProperty(Schema schema, String propertyName)\r\n at Microsoft.Exchange.Services.OData.Model.EwsFilterConverter.GetPropertyProvider(QueryNode queryNode)\r\n at Microsoft.Exchange.Services.OData.Model.EwsFilterConverter.ConvertFilterNode(QueryNode queryNode)\r\n at Microsoft.Exchange.Services.OData.Model.EwsQueryAdapter.GetRestriction()\r\n at Microsoft.Exchange.Services.OData.Model.MessageProvider.Find(String parentFolderId, MessageQueryAdapter queryAdapter)\r\n at Microsoft.Exchange.Services.OData.Model.FindMessagesCommand.InternalExecute()\r\n at Microsoft.Exchange.Services.OData.ODataCommand`2.Execute()\r\n at Microsoft.Exchange.Services.OData.ODataTask.Execute(TimeSpan queueAndDelayTime, TimeSpan totalTime)"
}
}
I got the same error that property of complex type is invalid.
It seems that exchange service does not support complex type filtering.
You can try getting all the Messages to local storage and doing filtering.
Email address is a complex type however it is listed as filterable (https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#RESTAPIResourcesMessage) which means the following should work...
https://outlook.office365.com/api/v1.0/me/messages?$filter=From/EmailAddress/Address eq 'email#email.com'
However, I'm having trouble with this, it seems to be simply returning blank values whereas the following works...
https://outlook.office365.com/api/v1.0/me/messages?$filter=From/EmailAddress/Name eq 'Joe Bloggs'
So, there could be a fault with the API or the email address might need to be formatted differently.

Resources