We have started using Dynamic API to retrieve an entity's attribute list for migration purposes as below:
GET [Organization URI]/api/data/v9.0/EntityDefinitions(LogicalName='contact')?$select=LogicalName,AttributeOf,AttributeType HTTP/1.1
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
For "DateTime" AttributeType field, there is a property within its calls DateTimeBehavior which has a "DateOnly" Value:
"DateTimeBehavior": {
"Value": "DateOnly"
}
We need to know this to convert the legacy data to either DateTime or Date field. However, if we include DateTimeBehavior into the $select of our GET api call, we will get:
{
"error": {
"code": "0x0",
"message": "Could not find a property named 'DateTime' on type 'Microsoft.Dynamics.CRM.AttributeMetadata'."
}
}
So we're stuck doing separate call for each "DateTime" AttributeType field to discover if it's a "DateOnly" or not.
Is there a way I can $select all attributes within an entity and include this "DateOnly" field if it's exists?
Any help is much appreciated.
I don't believe so. In order to retrieve the properties of a specific type of attribute you must cast the Attributes collection-valued navigation property to the type you want.
However, you can get back ALL the datetime attributes with their appropriate DateTimeBehavior
for an entity/table at once (vs. querying each attribute one at a time).
GET /api/data/v9.0/EntityDefinitions(LogicalName='account')/Attributes/Microsoft.Dynamics.CRM.DateTimeAttributeMetadata?$select=LogicalName,DateTimeBehavior