1

Using SharePoint REST API call SP.Web.ShareObject I try to share a document with another user of the same SharePoint site. The API call returns success response (Code 200) but can't update the share permission of the document. The response body contains following error message

SPWeb.ShareObjectInternal: no resolved users. ShareByEmailEnabled: False, CanPickerAcceptAnyEmail: False PickerInput: {"Key" : "i:0#.f|membership|test@sharepointsite.info", "Description" : "test@sharepointsite.info", "DisplayText" : "test user", "EntityType" : "User", "ProviderDisplayName" : "Tenant", "ProviderName" : "Tenant", "IsResolved" : true, "EntityData" : {"Title" : "", "MobilePhone" : "", "Department" : "", "Email" : "test@sharepointsite.info"}, "MultipleMatches" : []}

This is the code I have used for sharing

$url = "https://tenant-my.sharepoint.com/personal/test_sharepointsite_info/_api/SP.Web.ShareObject";
$path = 'https://tenant-my.sharepoint.com/personal/test_sharepointsite_info/Documents/TestDoc.docx';
$data = array(
    "url" => $path,
    "peoplePickerInput" => '{"Key" : "i:0#.f|membership|test@sharepointsite.info", "Description" : "test@sharepointsite.info", "DisplayText" : "test user", "EntityType" : "User", "ProviderDisplayName" : "Tenant", "ProviderName" : "Tenant", "IsResolved" : true, "EntityData" : {"Title" : "", "MobilePhone" : "", "Department" : "", "Email" : "test@sharepointsite.info"}, "MultipleMatches" : []}',
    "roleValue" => "1073741827",
    "groupId" => 0,
    "propagateAcl" => false,
    "sendEmail" => false,
    "includeAnonymousLinkInEmail" => false,
    "emailSubject" => "Subject",
    "emailBody" => "Body"
);
$body = json_encode($data);
$content_length = strlen($body);
$header = array(
    'X-RequestDigest' => $contextObject->d->GetContextWebInformation->FormDigestValue,
    'accept'=>'application/json;odata=verbose',
    'IF-MATCH' => '*', 
    'content-length' => $content_length
);
o365_performHttpRequestWithOAuth($url, array(), 'POST', $header, $body, 'application/json;odata=verbose');

What is wrong with the above code? why it returns the above error message?

1

You are missing [] brackets around object in peoplePickerInput and this property should be in correct format so it should look something like this:

"peoplePickerInput" => "[{'Key' : 'i:0#.f|membership|test@sharepointsite.info', 'Description' : 'test@sharepointsite.info', 'DisplayText' : 'test user', 'EntityType' : 'User', 'ProviderDisplayName' : 'Tenant', 'ProviderName' : 'Tenant', 'IsResolved' : true, 'EntityData' : {'Title' : '', 'MobilePhone' : '', 'Department' : '', 'Email' : 'test@sharepointsite.info'}, 'MultipleMatches' : []}]",

That's because peoplePickerInput should be a string of JSON formatted data as they say here: https://msdn.microsoft.com/en-us/library/office/mt143099.aspx?f=255&MSPPError=-2147217396

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.