Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to fetch all the relationships available for an entity from CRM using web api?

I have a requirement to fetch and show all the available Relationships of an Entity on HTML page, separately. Eg: If I chose, Account, in the html page, I should be able to see 1:N, N:1 and N:N relationships of Account Entity.

I have tried below, queries and I feel, these are not helping me correctly, Please suggest me a workaround for this to achieve.

https://<CRMORGNAME>/api/data/v8.2/RelationshipDefinitions/Microsoft.Dynamics.CRM.ManyToOneRelationshipMetadata?$select=Entity1LogicalName,SchemaName&$filter=Entity1LogicalName eq 'account'

https://<CRMORGNAME>/api/data/v8.2/RelationshipDefinitions?$select=RelationshipType,SchemaName
like image 795
Sai Krishna Avatar asked Oct 15 '25 16:10

Sai Krishna


1 Answers

You can do it the following way:

One to many:

https://contoso.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/OneToManyRelationships?$select=SchemaName,RelationshipType

Many to one:

https://contoso.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/ManyToOneRelationships?$select=SchemaName,RelationshipType

Many to many:

https://contoso.crm.dynamics.com/api/data/v8.2/EntityDefinitions(70816501-edb9-4740-a16c-6a5efbc05d84)/ManyToManyRelationships?$select=SchemaName,RelationshipType

Of course you should first get the proper EntityDefinition id (the '70816501-edb9-4740-a16c-6a5efbc05d84' is for account in this case)

https://contoso.crm.dynamics.com/api/data/v8.2/EntityDefinitions?$select=SchemaName,LogicalName,MetadataId&$filter=LogicalName eq 'account'
like image 176
Pawel Gradecki Avatar answered Oct 18 '25 06:10

Pawel Gradecki



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!