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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Associating entities u...
Power Pages
Unanswered

Associating entities using Web API fails in portal

(0) ShareShare
ReportReport
Posted on by 2

Hi, 

I am trying to associate two items using Web API call, an N to N relationship exists between the tables.

The 1st entity has unique identifier as entity1id and entity2 has one as entity2id. Both these fields are text type.

The entity permissions are in place and site setting is also set for both the entities.

Still the API call fails with a 404 Not Found status code.

The ajax call I am using is:-

 

webapi.safeAjax({

        type: 'POST',

        url: '/_api/entity1('+entity1id +')/<relationshipname>/$ref',

        contentType: 'application/json',

        data: JSON.stringify({

            '@odata.entity2id': '/entity2(' + entity2id + ')'

        }),

        success: function () {

            console.log('success');

        },

        error: function () {

            console.error('Error associating');

        }

Categories:
I have the same question (0)
  • oliver.rodrigues Profile Picture
    9,455 Most Valuable Professional on at

    Hi

     

    a few things to check:

    • have you double checked your Portals version? has to be 9.2.6.41 or higher
    • is your "entity1" the entity set instead of entity name.. for example contacts instead of contact ?


    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

  • Abhishek0672 Profile Picture
    2 on at

    Hi Oliver,

    Thank you for your response. My portal version is higher than required.
    I was missing the entity set name on one of the entities. But now after correcting that, I'm getting a different error: "Attribute <relationship name> cannot be found for entity entity1"

  • Ulrikke Akerbaek Profile Picture
    101 on at

    I am attempting to do the same, and having trouble finding the correct entity set name. How would I go about finding it without writing code? 

     

    Have you made sure to add Site Settings "Webapi/[entity]/fields" to "*" or including the missing field in the list? 

     

    I wonder, @Abhishek0672, have you added webapi site settings for the N:N entity? 

  • oliver.rodrigues Profile Picture
    9,455 Most Valuable Professional on at

    @Abhishek0672 

     

    were you able to get this working? have you tried @UlrikkeAkerbæk suggestion on adding the * for all attributes

     

    also make sure you have both site settings and entity permissions for every entity you are performing operations with the API

  • Ulrikke Akerbaek Profile Picture
    101 on at

    @OliverRodrigues can you please elaborate a bit more around the Entity Permissions needed for API to work? Does it have to be global permissions? Do I need only "Write" to "POST", "Update" to "PATCH" and "PUT" and "Delete" to "DELETE"? 

    And is it important that the function calling the API is located at home "/" page - or can this be triggered from any page in the site map? 

    I am new to working with API's and don't get it quite yet. So - of course I started with N:N relationship deep in my entity permission structure. *Rolling my eyes to myself* 

    Thank you for helping me out. 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
rezarizvii Profile Picture

rezarizvii 55

#2
DP_Prabh Profile Picture

DP_Prabh 38

#3
oliver.rodrigues Profile Picture

oliver.rodrigues 30 Most Valuable Professional

Last 30 days Overall leaderboard