web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM 2016 Web Api for creating a many to many relationship

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    Hi,

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

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

  • Community Member Profile Picture
    on at

    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.

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    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
    on at

    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.

  • Community Member Profile Picture
    on at

    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.

  • Verified answer
    ashlega Profile Picture
    34,477 on at

    Heh.. try removing that extra ")"

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

  • Community Member Profile Picture
    on at

    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.

  • Community Member Profile Picture
    on at

    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.

  • ashlega Profile Picture
    34,477 on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans