SOLVED

Post comment to a modern site page using REST api

%3CLINGO-SUB%20id%3D%22lingo-sub-2445621%22%20slang%3D%22en-US%22%3EPost%20comment%20to%20a%20modern%20site%20page%20using%20REST%20api%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2445621%22%20slang%3D%22en-US%22%3E%3CP%3EUsing%20this%20endpoint%3A%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fxxx.sharepoint.com%2Fsites%2Fxxx%2F_api%2Fweb%2FLists%2FGetByTitle('SitePages')%2FGetItemById(305)%2FComments%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ehttps%3A%2F%2Fxxx.sharepoint.com%2Fsites%2Fxxx%2F_api%2Fweb%2FLists%2FGetByTitle('SitePages')%2FGetItemById(305)%2FComments%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3EAnd%20this%26nbsp%3B%3C%2FSPAN%3Elistitementitytypefullname%3A%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3ESP.Data.SitePagesItem%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EResponse%3A%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CDIV%3E%3CEM%3EThe%26nbsp%3Bproperty%26nbsp%3B'__metadata'%26nbsp%3Bdoes%26nbsp%3Bnot%26nbsp%3Bexist%26nbsp%3Bon%26nbsp%3Btype%26nbsp%3B'Microsoft.SharePoint.Comments.comment'.%26nbsp%3BMake%26nbsp%3Bsure%26nbsp%3Bto%26nbsp%3Bonly%26nbsp%3Buse%26nbsp%3Bproperty%26nbsp%3Bnames%26nbsp%3Bthat%26nbsp%3Bare%26nbsp%3Bdefined%26nbsp%3Bby%26nbsp%3Bthe%26nbsp%3Btype.%3C%2FEM%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EWhere%20is%20it%20getting%20the%20%22type%22%20from%3F%20Shouldn't%20it%20be%20using%20the%26nbsp%3Blistitementitytypefullname%3F%20And%20if%20that's%20the%20wrong%20type%2C%20reflect%20that%20in%20the%20error%3F%20And%20if%20wrong%2C%20what%20should%20the%26nbsp%3Blistitementitytypefullname%3A%20be%20for%20site%20page%20comments%3F%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2445621%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPIs%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2447105%22%20slang%3D%22en-US%22%3ERe%3A%20Post%20comment%20to%20a%20modern%20site%20page%20using%20REST%20api%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2447105%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F221756%22%20target%3D%22_blank%22%3E%40matt%20howell%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20need%20to%20use%26nbsp%3B%3CSTRONG%3EMicrosoft.SharePoint.Comments.comment%3C%2FSTRONG%3E%26nbsp%3Bas%20%3CSPAN%3Elistitementitytypefullname%20instead%20of%26nbsp%3BSP.Data.SitePagesItem.%3C%2FSPAN%3E%3C%2FP%3E%3CHR%20%2F%3E%3CP%3EPlease%20click%26nbsp%3B%3CSTRONG%3EMark%20as%20Best%20Response%3C%2FSTRONG%3E%26nbsp%3B%26amp%3B%20%3CSTRONG%3ELike%3C%2FSTRONG%3E%20if%20my%20post%20helped%20you%20to%20solve%20your%20issue.%20This%20will%20help%20others%20to%20find%20the%20correct%20solution%20easily.%20It%20also%20closes%20the%20item.%20If%20the%20post%20was%20useful%20in%20other%20ways%2C%20please%20consider%20giving%20it%20%3CSTRONG%3ELike%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Frequent Contributor

Using this endpoint:

https://xxx.sharepoint.com/sites/xxx/_api/web/Lists/GetByTitle('SitePages')/GetItemById(305)/Comment...

And this listitementitytypefullname:

SP.Data.SitePagesItem
Response:
The property '__metadata' does not exist on type 'Microsoft.SharePoint.Comments.comment'. Make sure to only use property names that are defined by the type.
Where is it getting the "type" from? Shouldn't it be using the listitementitytypefullname? And if that's the wrong type, reflect that in the error? And if wrong, what should the listitementitytypefullname: be for site page comments? 
 
2 Replies
best response confirmed by matt howell (Frequent Contributor)
Solution

@matt howell 

You need to use Microsoft.SharePoint.Comments.comment as listitementitytypefullname instead of SP.Data.SitePagesItem.


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

@ganeshsanap Thanks - I did initially try with Microsoft.SharePoint.Comments.comment and it failed probably due to some other issue, but now it works. Do you know if it's possible to reflect a user's name instead of the app name as the author, and if so how?