cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Regular Visitor

Creating portal comments in portal with the new Web API

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!

 

3 REPLIES 3
Highlighted
Impactful Individual
Impactful Individual

Re: Creating portal comments in portal with the new Web API

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!

Highlighted
Regular Visitor

Re: Creating portal comments in portal with the new Web API

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?

 

Highlighted
Impactful Individual
Impactful Individual

Re: Creating portal comments in portal with the new Web API

Hi @Vnct 

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

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Users online (5,294)