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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Creating portal commen...
Power Pages
Unanswered

Creating portal comments in portal with the new Web API

(0) ShareShare
ReportReport
Posted on by 2

Hello,

 

I'm trying to use to new Portal's Web API to create portal comments in entity adx_portalcomments.
This entity has a custom field, abc_contactid (not required field), which is a lookup to the contact entity.

The record is created successfully if I don't specify this contact field, but it doesn't work if I try to associate a contact with abc_contactid.

 

  • My first attempt was to try and create a record like this:

webapi.safeAjax({
    type: 'POST',
    url: '/_api/adx_portalcomments',
    contentType: 'application/json',
    data: JSON.stringify({
        'subject': 'Test',
        'description': 'test...',
        'regardingobjectid_incident@odata.bind': '/incidents(00000000-0000-0000-0000-000000000001)',
        'abc_contactid@odata.bind': '/contacts(00000000-0000-0000-0000-000000000002)'
    }),
    success: function (res, status, xhr) {
        console.log('OK');
    },
    error: function () {
        console.error('Error');
    }
});


Then I get a "Bad Request" error: "An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'abc_contactid' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values."


It is to be noted that the regardingobjectid field works perfectly!

 

I also tried with 'abc_ContactId@odata.bind': '/_api/contacts(00000000-0000-0000-0000-000000000002)', which is the schema name of the field.

 

// 1. Create the record.
webapi.safeAjax({
    type: 'POST',
    url: '/_api/adx_portalcomments',
    contentType: 'application/json',
    data: JSON.stringify({
        'subject': 'Test',
        'description': 'test...',
        'regardingobjectid_incident@odata.bind': '/incidents(00000000-0000-0000-0000-000000000001)'
    }),
    success: function (res, status, xhr) {
        console.log('Portal comment created');

        // 2. Associate the new record with the contact.
        var entityId = xhr.getResponseHeader('entityId');

        webapi.safeAjax({
            type: 'POST',
            url: '/_api/adx_portalcomments(' + entityId + ')/abc_Contact_adx_PortalComment_ContactId/$ref',
            contentType: 'application/json',
            data: JSON.stringify({
                '@odata.id': '/contacts(00000000-0000-0000-0000-000000000002)'
            }),
            success: function (res, status, xhr) {
                console.log('contact associated with the portal comment');
            },
            error: function () {
                console.error('Error');
            }
        });
    },
    error: function () {
        console.error('Error');
    }
});

 

The records is created successfully, but then when I try to make the association, I get the error "Resource not found for the segment adx_portalcomments.".

Am I doing something wrong? Or is there something not yet implemented?

 

Thanks!

 

Categories:
I have the same question (0)
  • H V Profile Picture
    1,510 on at

    Hi @Vnct 

    Have you added abc_contactid logical field name in Site Settings Webapi/contact/fields record?

    Did you assign Entity Permission Append & Append To for Portal Comments & Contact entities?

     

    --------------------------
    If you like this post, give a Thumbs up. Where it solved your query, Mark as a Solution so it can help other people!

  • Vnct Profile Picture
    2 on at

    Hi @hardikv 

    Thank you for your answer.

    - Yes, I added all fields in Site Settings.

    - And yes, Entity Permissions include Append and Append To for both entities.

    It works perfectly well if I use a standard Entity Form, so I suppose it shouldn't be related to access rights issues?

     

  • H V Profile Picture
    1,510 on at

    Hi @Vnct 

    Yes, If it works fine in Entity Form, then it will not be access right issue!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard