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|[email protected]", "Description" : "[email protected]", "DisplayText" : "test user", "EntityType" : "User", "ProviderDisplayName" : "Tenant", "ProviderName" : "Tenant", "IsResolved" : true, "EntityData" : {"Title" : "", "MobilePhone" : "", "Department" : "", "Email" : "[email protected]"}, "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|[email protected]", "Description" : "[email protected]", "DisplayText" : "test user", "EntityType" : "User", "ProviderDisplayName" : "Tenant", "ProviderName" : "Tenant", "IsResolved" : true, "EntityData" : {"Title" : "", "MobilePhone" : "", "Department" : "", "Email" : "[email protected]"}, "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 Answer 1

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|[email protected]', 'Description' : '[email protected]', 'DisplayText' : 'test user', 'EntityType' : 'User', 'ProviderDisplayName' : 'Tenant', 'ProviderName' : 'Tenant', 'IsResolved' : true, 'EntityData' : {'Title' : '', 'MobilePhone' : '', 'Department' : '', 'Email' : '[email protected]'}, '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 and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.