Sharepoint REST API - post comment on behalf of another user - sharepoint-online

There is a way of how to add comments to Sharepoint site using REST API. It is explained here https://beaucameron.com/2021/01/18/add-comments-to-sharepoint-list-items-using-the-rest-api/ for example.
But when I add comment like this, it adds it on behalf of my name - because REST endpoint is accessed using access token, which is linked to my e-mail.
I'd like to migrate comments from one site to the other, and keep original authors.
Is there a way to post comments on behalf of other users?
I tried this POST body:
{
"__metadata": {
"type": "Microsoft.SharePoint.Comments.comment"
},
"text": "Some new comment",
"author": {
"__metadata": {
"type": "SP.Sharing.Principal"
},
"email": "AlexW#OnMicrosoft.com",
"id": 18,
"loginName": "i:0#.f|membership|alexw#onmicrosoft.com",
"name": "Alex Wilber",
"principalType": 1
}
}
But still, comment is posted on behalf of my name. The response is like the following:
{
"d": {
"__metadata": {
"id": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)",
"uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)",
"type": "Microsoft.SharePoint.Comments.comment"
},
"likedBy": {
"__deferred": {
"uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)/likedBy"
}
},
"replies": {
"__deferred": {
"uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)/replies"
}
},
"author": {
"__metadata": {
"type": "SP.Sharing.Principal"
},
"email": "myName.mySurname#onmicrosoft.com",
"expiration": null,
"id": 12,
"isActive": true,
"isExternal": false,
"jobTitle": null,
"loginName": "i:0#.f|membership|myName.mySurname#onmicrosoft.com",
"name": "myName mySurname",
"principalType": 1,
"userId": null,
"userPrincipalName": null
},
"createdDate": "2022-05-24T08:40:19.0841947Z",
"id": "15",
"isLikedByUser": false,
"isReply": false,
"itemId": 1,
"likeCount": 0,
"listId": "017dd808-5a37-4d65-89f9-b5ce994554b4",
"mentions": null,
"parentId": "0",
"replyCount": 0,
"text": "Some new comment"
}
}
So still, I'm the author of the comment...

Related

Create the message route in azure iothub using rest api

I am able to create the "message route" in azure portal and able to route messages to servicebusqueue if the query matching, I want to create the message route using the restapi instead of using azure portal, I have seen many documents but unable to find the proper one. Whether creating the message route using restapi is possible or not? if yes,How can I achieve this and please provide the respective links to refer?
I haven't tried this through REST API, but as Roman suggested,
You can check the IotHubResource_CreateOrUpdate which will help you understand how to Create or update the metadata of an Iot hub. The usual pattern to modify a property is to retrieve the IoT hub metadata and security metadata, and then combine them with the modified values in a new body to update the IoT hub.
Sample Request:
PUT https://management.azure.com/subscriptions/91d12660-3dec-467a-be2a-213b5544ddc0/resourceGroups/myResourceGroup/providers/Microsoft.Devices/IotHubs/testHub?api-version=2018-04-01
Request Body:
{
"name": "iot-dps-cit-hub-1",
"type": "Microsoft.Devices/IotHubs",
"location": "centraluseuap",
"tags": {},
"etag": "AAAAAAFD6M4=",
"properties": {
"operationsMonitoringProperties": {
"events": {
"None": "None",
"Connections": "None",
"DeviceTelemetry": "None",
"C2DCommands": "None",
"DeviceIdentityOperations": "None",
"FileUploadOperations": "None",
"Routes": "None"
}
},
"state": "Active",
"provisioningState": "Succeeded",
"ipFilterRules": [],
"hostName": "iot-dps-cit-hub-1.azure-devices.net",
"eventHubEndpoints": {
"events": {
"retentionTimeInDays": 1,
"partitionCount": 2,
"partitionIds": [
"0",
"1"
],
"path": "iot-dps-cit-hub-1",
"endpoint": "sb://iothub-ns-iot-dps-ci-245306-76aca8e13b.servicebus.windows.net/"
},
"operationsMonitoringEvents": {
"retentionTimeInDays": 1,
"partitionCount": 2,
"partitionIds": [
"0",
"1"
],
"path": "iot-dps-cit-hub-1-operationmonitoring",
"endpoint": "sb://iothub-ns-iot-dps-ci-245306-76aca8e13b.servicebus.windows.net/"
}
},
"routing": {
"endpoints": {
"serviceBusQueues": [],
"serviceBusTopics": [],
"eventHubs": [],
"storageContainers": []
},
"routes": [],
"fallbackRoute": {
"name": "$fallback",
"source": "DeviceMessages",
"condition": "true",
"endpointNames": [
"events"
],
"isEnabled": true
}
},
"storageEndpoints": {
"$default": {
"sasTtlAsIso8601": "PT1H",
"connectionString": "",
"containerName": ""
}
},
"messagingEndpoints": {
"fileNotifications": {
"lockDurationAsIso8601": "PT1M",
"ttlAsIso8601": "PT1H",
"maxDeliveryCount": 10
}
},
"enableFileUploadNotifications": false,
"cloudToDevice": {
"maxDeliveryCount": 10,
"defaultTtlAsIso8601": "PT1H",
"feedback": {
"lockDurationAsIso8601": "PT1M",
"ttlAsIso8601": "PT1H",
"maxDeliveryCount": 10
}
},
"features": "None"
},
"sku": {
"name": "S1",
"tier": "Standard",
"capacity": 1
}
}

Why Does Calling Expand and Select on a PUT result in LESS information being returned - Acumatica REST API

In the example for Acumatica: "Lesson 2.1: Updating a Customer Account" the sample code will update the customer's Contact info, based on retrieving it by the email address. It expands the MainContact and selects CustomerID and CustomerClass:
https://localhost/MyStoreInstance/entity/Default/18.200.001/Customer?$filter=MainContact/Email eq 'info#jevy-comp.con'&$expand=MainContact&$select=CustomerID,CustomerClass
The values that are returned include CustomerID, CustomerClass PLUS a fully loaded BillingContact record, comprising 2150 Bytes of data like this:
{
"id": "0b88d208-297a-4b81-a20c-39d27bace10a",
"rowNumber": 1,
"note": "",
"BillingContact": {
"id": "e1133b8a-fca9-4885-8e4c-09a85808f025",
"rowNumber": 1,
"note": null,
"Activities": [],
"Address": {
"id": "4f1719aa-6eb0-4551-a143-ad2139e135aa",
"rowNumber": 1,
"note": null,
"AddressLine1": {
"value": "1000 Pennsylvania Ave"
},
"AddressLine2": {},
"City": {
"value": "San Francisco"
},
"Country": {
"value": "US"
},
"PostalCode": {
"value": "94107-3479"
},
"State": {
"value": "CA"
},
"custom": {},
"files": []
},
"Attention": {
"value": "Mister. Jack Green"
},
"Attributes": [],
"Campaigns": [],
"Cases": [],
"ContactID": {
"value": 12417
},
"DisplayName": {
"value": "Jevy Computers"
},
"Duplicates": [],
"Email": {
"value": "green#jevy-comp.con"
},
"Fax": {},
"FirstName": {},
"JobTitle": {
"value": ""
},
"LastName": {},
"MarketingLists": [],
"MiddleName": {},
"Notifications": [],
"Opportunities": [],
"Phone1": {
"value": "+1 (777) 380-0089"
},
"Phone1Type": {
"value": "Business 1"
},
"Phone2": {},
"Phone2Type": {
"value": "Business 2"
},
"Relations": [],
"Title": {},
"UserInfo": null,
"WebSite": {},
"custom": {},
"files": []
},
"BillingContactSameAsMain": {
"value": false
},
"CustomerClass": {
"value": "INTL"
},
"CustomerID": {
"value": "C000000003"
},
"custom": {},
"files": []
}
However, when I explicitly ask for BillingContact to be Expanded, I get LESS information than I get when I omit it from the EXPAND command altogether. (I get 1235 bytes in return.)
{
"id": "0b88d208-297a-4b81-a20c-39d27bace10a",
"rowNumber": 1,
"note": "",
"BillingContact": {
"id": "e1133b8a-fca9-4885-8e4c-09a85808f025",
"rowNumber": 1,
"note": null,
"Attention": {
"value": "Mr. Jack Green"
},
"ContactID": {
"value": 12417
},
"DisplayName": {
"value": "Jevy Computers"
},
"Email": {
"value": "green#jevy-comp.con"
},
"Fax": {},
"FirstName": {},
"JobTitle": {
"value": ""
},
"LastName": {},
"MiddleName": {},
"Phone1": {
"value": "+1 (777) 380-0089"
},
"Phone1Type": {
"value": "Business 1"
},
"Phone2": {},
"Phone2Type": {
"value": "Business 2"
},
"Title": {},
"WebSite": {},
"custom": {},
"files": []
},
"BillingContactSameAsMain": {
"value": false
},
"CustomerClass": {
"value": "INTL"
},
"CustomerID": {
"value": "C000000003"
},
"custom": {},
"files": []
}
Clearly I do not understand how the expand command is operating in a PUT. Can anyone explain it to me?
Why does including BillingContact in the expand command give me less BillingContact information?
When you execute a Put request, Acumatica automatically add expands for the entities your are touching, including subentities, so you see Address under BillingContact.
When you add expand on the billing contact, it overrides the default expands and you do not see Address any more.
To get Address in the result, you add another expand : BillingContact/Address
Same applies to all other entities

How to add a new top-level entity (to rest web service endpoint) using acumatica screenID?

Acumatica cloud ERP has a screen that displays failed push notifications (screenID = SM502000). I have created a new Web Services Endpoint, and added a new top-level entity from that screenID. However, no matter what fields I try to add, I get a variation on this error:
Optimization cannot be performed.The following fields cause the error:\r\nSelected: View FailedToSend has BQL delegate\r\n
Edit. I was able to create a REST end-point to fetch the results using a generic inquiry. Here is the JSON returned:
{
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"rowNumber": 1,
"note": null,
"Result": [
{
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"rowNumber": 1,
"note": null,
"Date": {
"value": 637167021636873690
},
"DateTimeStamp": {
"value": "2020-02-07T19:56:03.687369+00:00"
},
"DestinationNamePushNotifications_hookId": {
"value": "test"
},
"DestinationNamePushNotifications_hookId_description": {
"value": "test"
},
"Error": {
"value": "Send to target test failed. Message: WebHook returns not success code: NotFound; Message: Tunnel webhook.local not found"
},
"NotificationBody": {
"value": "..."
},
"PushNotifications_selected": {},
"Selected": {
"value": false
},
"SourceName": {
"value": "SO-SalesOrder"
},
"TransactionId": {
"value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
"custom": {},
"files": []
},
{
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"rowNumber": 2,
"note": null,
"Date": {
"value": 637167021636873690
},
"DateTimeStamp": {
"value": "2020-02-07T19:56:03.687369+00:00"
},
"DestinationNamePushNotifications_hookId": {
"value": "test"
},
"DestinationNamePushNotifications_hookId_description": {
"value": "test"
},
"Error": {
"value": "Send to target test failed. Message: WebHook returns not success code: NotFound; Message: Tunnel webhook.local not found"
},
"NotificationBody": {
"value": "..."
},
"PushNotifications_selected": {},
"Selected": {
"value": false
},
"SourceName": {
"value": "SO-SalesOrder"
},
"TransactionId": {
"value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
"custom": {},
"files": []
}
]
}
Here's a good tutorial for using GI to access data via API:
https://www.acumatica.com/blog/contract-based-apis-in-generic-inquiries/
Try retrieving the records one by one with a REST filter in the URL. The issue is that the target graph you added has a data view (FailedToSend) which uses a data view delegate.
Because data view delegates can be slower than no delegates the API refuses to return more than one record as an optimization.

Azure API Set-body JSON to JSON covert

The response i am getting is below Which i need to convert the input JSON Format to other JSON structure and send the response back. I am struck how to get the data from the JSOn and construct the new JSON format
{
"totalSize": 1,
"done": true,
"records": [{
"attributes": {
"type": "test123",
"url": "/services/data/testapp"
},
"Id": "8373837",
"Name": "6294",
"Application": "9932932932",
"contact": {
"attributes": {
"type": "testcon",
"url": "/services/data/testappsss"
},
"Name": "testName",
"FirstName": "test",
"LastName": "name",
"MailingStreet": null,
"MailingCity": null,
"unemail": "testname#test,.co",
"MailingState": null,
"MailingCountry": null,
"MailingPostalCode": null,
"stuId": "328237832"
},
"currentusbss": "83277832873278",
"currentsu": {
"attributes": {
"type": "testsub",
"url": "/services/data/v44.0jsjsj"
},
"price": 2,
"Name": "SUB-20426"
},
"bal": 234,
"startdate": "2020-02-03",
"enddate": "2020-05-03"
}]
}
I need to convert above JSON format to below JSON format and send it using set-body method in out-bond policies
{
"info": {
"studentName": "testName",
"studentFirstName": "test",
"studentMiddleName": "",
"studentLastName": "Name",
"studentEmail": "testname#test,.co",
"role": "STUDENT",
"billingCountryCode": "US",
"systemId": "XX",
"stuId": "328237832"
},
"address": {
"address1": "1234 Grove St",
"address2": "",
"city": "Tempe",
"countryCode": "US",
"countryDescription": "UNITED STATES",
"stateCode": "AZ",
"stateDescription": "Arizona",
"postalCode": "45235",
"foreignState": "Arizona",
"region": "Domestic",
"phoneNumber": ""
},
"account": {
"institutionId": "1",
"paymentPlan": "N",
"currencyDesc": "United States Dollars",
"currencyType": "USD",
"bal": 234,
"daysLate":"18",
"opportunityId": "9932932932",
"studentParameterName": null,
"studentParameterValue": null
},
"studentTerms": [
{
"startdate": "2020-02-03",
"enddate": "2020-05-03",
"Name": "SUB-20426",
"description": "XQYember 03, 2020 "
}
]
}
You can use Liquid Template for this case:
Using Liquid Templates in Azure API Management
Using Liquid templates with set body
Or you create a new body in the outbound-section with a new JObject

Creating a Meeting in JSON Format issue

Is there any way to create a Calendar entry using a mailfile where the Organizer is not the mailfile Owner?
For example:
http://mycompanycom/mail/utils.nsf/api/calendar/events
I want to use a gereric mailfile where DAS is enabled and make all request against it; otherwise I'll need to query every Organizer's mailfile.
The only way I can make it to work is when I set the organizer the same as the mailfile owner, for example:
http://mycompany.com/mail1/ndev1.nsf/api/calendar/events
Here Notes Dev1 is the Owner for ndev1.nsf
{
"events": [
{
"summary": "TEST FEB 2018",
"location": "TEST LOCATION - NOT NEEDED",
"description": "",
"CalendarDateTime": {
"date": "2018-02-26",
"time": "17:00:00",
"utc": true
},
"start": {
"date": "2018-02-26",
"time": "17:00:00",
"utc": true
},
"end": {
"date": "2018-02-26",
"time": "18:00:00",
"utc": true
},
"class": "public",
"transparency": "opaque",
"sequence": 0,
"x-lotus-noticetype": "I",
"attendees": [
{
"role": "chair",
"status": "accepted",
"rsvp": false,
"displayName": "Notes Dev1/MYCOMPANY",
"email": "notes.dev1#mycompany.com"
},
{
"role": "req-participant",
"status": "needs-action",
"rsvp": true,
"displayName": "Pablo Solano/MYCOMPANY",
"email": "pablo.solano#mycompany.com"
},
{
"role": "req-participant",
"status": "needs-action",
"rsvp": true,
"displayName": "Notes Dev2/MYCOMPANY",
"email": "notes.dev2#mycomany.com"
},
{
"role": "req-participant",
"userType": "room",
"status": "accepted",
"rsvp": true,
"email": "maar#teradyne.com"
}
],
"organizer": {
"displayName": "Notes Dev1/MYCOMPANY",
"email": "notes.dev1#mycompany.com"
}
}
]
}
I found this url: http://www-10.lotus.com/ldd/ndseforum.nsf/xpTopicThread.xsp?documentId=CB20A0E36EE82AB385258154003B0A86
with this text:
One important caveat: The organizer property must match the owner of the database as specified in the request URL (/{database}/api/calendar/events).
I see few options for you:
Quick&dirty - change/add current user as owner of the calendar on the fly every time. Not recommended.
Make your code to work on behalf of universal identity, which is also owner of the calendar. Caveat: meeting will be arranged by that identity.
Create the meeting from user's calendar. Probably that's not what you want.

Resources