Search code examples
odatadynamics-crm

Getting only property definitions of entity in OData


I am working on an app which requires communication with OData service (Microsoft Dynamics CRM to be exact). I have a requirement where I only need to know what all properties does the entity have.

e.g.

[Organization URI]/api/data/v8.1/contacts

returns all the contacts, however I want only property definitions of the contact.

Right now [Organization URI]/api/data/v8.1/contacts returns the JSON with values, however what I am looking is something schema of contacts entity. It should return me what all properties it has (e.g. firstname, lastname) and possibly the type of properties.

I tried using $metadata but without any luck. Is it possible to get information about entity only?

Any help would be appreciated.


Solution

  • The answers provided describe how to get the metadata for an entity, which technically does have all the definitions for a given entity. However, when using the Web API an alternative would be to download the CSDL metadata document ($metadata) for the Web API and look for the definition of the contacts entityType. This is the data used to generate this documentation contact EntityType and provides the specific definition used by the Web API.

    You will see there are differences in the structure. i.e. metadata defines LookupAttributeMetadata attributes, but the Web API uses Single-valued navigation properties and read-only 'lookup properties'.

    For information to understand the Web API $metadata, see Web API types and operations > Entity types