msgraph-typescript-typings icon indicating copy to clipboard operation
msgraph-typescript-typings copied to clipboard

Incorrect type for "Identity" in "IdentitySet"

Open arthur-caillaud opened this issue 5 years ago • 12 comments

The type Identity seems to be different from what the API is returning. This error occured for us when retrieving the identity of the creator of the document using the createdBy.user field on a DriveItem.

Expected (declared in microsoft-graph.d.ts line 8736)

{
  id?: string;
  displayName?: string;
}

Returned by API

{
  email: "some.email@domain",
  displayName: "Some Name"
}

We tried to switch to the beta types but they are the same.

We are for now casting the createdBy.user property to what the API is returning. AB#7046

arthur-caillaud avatar Feb 03 '20 10:02 arthur-caillaud

This is expected behavior per the metadata. This is an OpenType which means that undefined properties may be returned in this object. Additionally, id and displayName are nullable so it is expected that they may not be present in a response.

      <ComplexType Name="identity" OpenType="true">
        <Property Name="displayName" Type="Edm.String" />
        <Property Name="id" Type="Edm.String" />
      </ComplexType>

@ificator and @BarryShehadeh It seems like the email property should be schematized.

MIchaelMainer avatar Feb 04 '20 19:02 MIchaelMainer

Thank you for your answer. I was not clear but the issue is precisely about the email property being absent in the types and returned by the API. No problem with some properties being optional.

arthur-caillaud avatar Feb 05 '20 08:02 arthur-caillaud

I also ran into this issue. Any updates on this?

mpsijm avatar Oct 26 '20 12:10 mpsijm

I apologize, I somehow missed the previous notification from GitHub.

So there are two questions:

  1. Why is id missing?
  2. Why is email a dynamic property instead of being present in the schema?

For the former it will be useful to understand the scenario - was this a call against SharePoint or OneDrive Personal? what API was being invoked?

For the latter - off the top of my head I don't see why this cannot be the case. There will be times when there is no email (e.g. if the identity represents a device) and so the value would be nullable but from that's essentially no different to todays state.

ificator avatar Oct 26 '20 17:10 ificator

  1. In my context, I'm using a SharePoint API. The exact same user sometimes has an id, sometimes doesn't. The email property from that same user seems to be there most of the time, but not always. See also the scenario I posted here: https://github.com/microsoftgraph/microsoft-graph-docs-contrib/issues/4363.

  2. In the case that the identity represents a device, it would also make sense to me that the email is nullable. However, (a) it is currently not documented (neither in the typings nor in the docs) and (b) it seems to be not consistently set for regular users as in my previous point.

mpsijm avatar Oct 26 '20 17:10 mpsijm

Any kind of inconsistency should be viewed as a bug so we'll investigate what's going on with the delta API. Are there any other APIs that you've noticed missing id values?

ificator avatar Oct 31 '20 20:10 ificator

Not that I know of, at the moment. Is there a better place to report those inconsistencies than the typings or docs repositories? Then I can report back there if I can consistently reproduce missing values using the Graph Explorer.

mpsijm avatar Nov 01 '20 07:11 mpsijm

For OneDrive / SharePoint API issues / questions the best place is https://github.com/OneDrive/OneDrive-api-docs. We generally only spot issues other repos when we're explicitly tagged.

ificator avatar Nov 01 '20 16:11 ificator

Hi @mpsijm we recently pushed a change that should result in delta populating the id for identity objects that represent a user/group. Could you confirm that things are looking more consistent for you now?

ificator avatar Nov 25 '20 17:11 ificator

@ificator Yes, on first sight it looks like it's been fixed, thanks :smile: Still need to some more thorough testing, if I find anything weird I'll report back :slightly_smiling_face:

The email field now also seems to show up consistently in the response data (if the user has an email, of course), even though that field is still undocumented (see my second point in https://github.com/microsoftgraph/msgraph-typescript-typings/issues/116#issuecomment-716720698).

mpsijm avatar Nov 27 '20 14:11 mpsijm

Hello @mpsijm , could you please tell me how do you make the email and id of a user showing up consistently in the response CreatedBy filed. MS Graph API is GET /drives/{drive-id}/items/{item-id} For some users, the email and id are missing in the response.

https://learn.microsoft.com/en-us/graph/api/resources/identity?view=graph-rest-1.0 In some circumstances, the unique identifier for the actor might not be available. In this case, the displayName property for the identity will be returned, but the id property will be missing from the resource. What is the circumstance?

aigolang avatar Mar 13 '23 08:03 aigolang

@aigolang I did not do anything specific for this. The change in the API from https://github.com/microsoftgraph/msgraph-typescript-typings/issues/116#issuecomment-733835281 appeared to have fixed things, and we did not run into any issues since then. I still do not know under what circumstances some fields may be empty :sweat_smile:

mpsijm avatar Mar 13 '23 09:03 mpsijm