Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

CRM 2016 Web Api for creating a many to many relationship

Posted on by Microsoft Employee

Hi,

I have two entities: "new_majorations" and "contacts". I have also an entity for the relations between the two: "new_contact_new_majorationset." 

How can I use the Web Api to create a new entry in "new_contact_new_majorationset" (so a new relation beetween "new_majorations" and "contacts")?

Thanks!

*This post is locked for comments

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: CRM 2016 Web Api for creating a many to many relationship

    Interesting.. I just got the same error with my contact-accounts when I switched the entities.. Good to know.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM 2016 Web Api for creating a many to many relationship

    I just succeeded by inverted the entities: so I put the contacts in the url and new_majorations in the body.

    Thanks for your help!

    Cornel.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM 2016 Web Api for creating a many to many relationship

    I discovered that I had a double parenthesis in the end of the request. Removing it I got the error message "Invalid role specified for entity 'new_majoration'in relationship 'new_contact_new_majoration.Referencing".

    Thanks,

    Cornel.

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: CRM 2016 Web Api for creating a many to many relationship

    Heh.. try removing that extra ")"

    "@odata.id":"myurl/api/data/v8.2/contacts(8b46e99f-1fb0-e711-80da-00155d050128))"

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM 2016 Web Api for creating a many to many relationship

    And if I used "new_contact_new_majoration" instead of "new_contact_new_majorationset" I got the error message "Bad Request - Error in query syntax."

    Thanks,

    Cornel.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM 2016 Web Api for creating a many to many relationship

    Hi Alex,

    If I put "/$ref" I got the error message: "The URI segment '$ref' is invalid after the segment 'new_contact_new_majorationset'".

    Thanks,

    Cornel.

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: CRM 2016 Web Api for creating a many to many relationship

    I think you missed /$ref in the post url.

    This worked for me:

    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)"
    }

    Where new_account_contact is an N:N relationship.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM 2016 Web Api for creating a many to many relationship

    Hi Alex,

    The link you posted is for one to many relationships.

    Anyway, I did try it, but I got the error "Unmapped Request found".

    This was the POST request:

    "myurl/api/data/v8.2/new_majorations(b56bc9c7-6a50-e311-aa33-00155d060a6a)/new_contact_new_majoration"

    {

    "@odata.id":"myurl/api/data/v8.2/contacts(8b46e99f-1fb0-e711-80da-00155d050128))"

    }

    Thanks,

    Cornel.

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: CRM 2016 Web Api for creating a many to many relationship

    Hi,

     You'll need to post this kind of request through javascript:

     msdn.microsoft.com/.../mt607875.aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans