Hi,
Can anyone let me know that how to Add items in a list which exists in another site collection on item updated event of list in some other site collection by using remote event receiver in SharePoint online.
I have given Tenant scope permissions to add-in and checked the checkbox 'Allow add-in to make app only calls' and creating Context by using below code:
string destinationSiteUrl = "Site coll2 URL";Uri destinationSiteUri = new Uri(destinationSiteUrl);
//target realm of the tenant (This is constant per tenant)
string targetRealm = TokenHelper.GetRealmFromTargetUrl(destinationSiteUri);
//generate access token for destination site
string accessToken = TokenHelper.GetAppOnlyAccessToken(TokenHelper.SharePointPrincipal, destinationSiteUri.Authority, targetRealm).AccessToken;
//get destination site context using access token
using (var destinationContext = TokenHelper.GetClientContextWithAccessToken(destinationSiteUrl, accessToken))
{
var destinationlist = destinationContext.Web.Lists.GetByTitle("List1");
ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
ListItem newItem = destinationlist.AddItem(itemCreateInfo);
newItem["Title"] = "new Item";
newItem.Update();
destinationContext.ExecuteQuery();
}
Thanks in advance.
Regards,
Abha Sharma