Reputation: 5774
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.
Upvotes: 3
Views: 3613
Reputation: 4085
See Query Metadata using the Web API. The previous answer is close but you need the $expand=Attributes
to get the list of Attributes. Plus it gets all entities where you want to filter on Contact.
GET [Organization URI]/api/data/v8.1/EntityDefinitions?$select=LogicalName&**$expand=Attributes($select=LogicalName)**&$filter=SchemaName eq 'Contact'
In the returned JSON you'll find the attributes at
value[0].Attributes
Which is an array. In this case I $select=LogicalName
so each one has the property LogicalName (as well as the MetadataId which is the GUID for that property).
So the first $select
is for properties from the entities.
The $expand
tells CRM to include the Attributes. The inner $select
tells which fields to return on the Attribute. The $filter
makes sure they only return all this metadata for Contact.
Upvotes: 5
Reputation: 258
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
Upvotes: 2
Reputation: 17562
If you are using the Web Api (looks like you are), then you can retrieve the EntityMetadata
which has a navigation property for AttributeMetadata
, which will describe attributes (aka; fields, properties).
[Organization URI]/api/data/v8.1/EntityDefinitions
Use the Web API with CRM metadata
For example: GET [Organization URI]/api/data/v8.1/EntityDefinitions?$select=DisplayName,IsKnowledgeManagementEnabled,EntitySetName&$filter=SchemaName eq 'Contact' HTTP/1.1
Further examples at Query Metadata using the Web API
Upvotes: 1