Web API: Invalid role specified for entity in relationship

By | October 13, 2017

Here is another error you might run into with Web API:

Invalid role specified for entity in relationship

It seems that, when associating two entities through an N:N, it’s important to add them to the web api request in the right sequence. For example, for this particular N:N, I originally created that N:N on the account entity:

So, when trying to add account to a contact(which means I would not be using those entities in the order in which I created the relationship), I was getting that error above. But, once I switched the entities to add “contact” to “account”, it all worked out:

 


POST https://treecatoct2017.crm3.dynamics.com/api/data/v8.2/accounts(36859222-06AE-E711-A94C-000D3AF3E34A)/new_account_contact/$ref HTTP/1.1
Content-Type: application/json
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
{
“@odata.id”:”https://treecatoct2017.crm3.dynamics.com/api/data/v8.2/contacts(97A39480-A8AE-E711-A94A-000D3AF3E840)”
}

And, of course, it all started in the community forums, so big thanks to Cornel there for figuring this out:
https://community.dynamics.com/crm/f/117/p/254562/711558

Leave a Reply

Your email address will not be published.