phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

Can't Add list items when using NTLM auth

Open anchorman5588 opened this issue 7 years ago • 5 comments

Connection works Reading list items works

Connecting to a SharePoint 2013 site.

When I attempt to add items I get these errors:

Warning: First parameter must either be an object or the name of an existing class in /vendor/vgrem/php-spo/src/Runtime/OData/JsonPayloadSerializer.php on line 52

Warning: First parameter must either be an object or the name of an existing class in /vendor/vgrem/php-spo/src/Runtime/OData/JsonPayloadSerializer.php on line 55

Notice: Trying to get property of non-object in /vendor/vgrem/php-spo/src/Runtime/OData/JsonPayloadSerializer.php on line 72

Warning: Invalid argument supplied for foreach() in /vendor/vgrem/php-spo/src/Runtime/ClientValueObject.php on line 39

Warning: First parameter must either be an object or the name of an existing class in /vendor/vgrem/php-spo/src/Runtime/OData/JsonPayloadSerializer.php on line 52

Warning: First parameter must either be an object or the name of an existing class in /vendor/vgrem/php-spo/src/Runtime/OData/JsonPayloadSerializer.php on line 55

Warning: Invalid argument supplied for foreach() in /vendor/vgrem/php-spo/src/Runtime/ClientObject.php on line 129

Code:

$authCtx = new NetworkCredentialContext($username, $password);
$authCtx->AuthType = CURLAUTH_NTLM; //NTML auth schema
$ctx = new ClientContext($url,$authCtx);
$list = $ctx->getWeb()->getLists()->getByTitle($listtitle);
$itemProperties = array('Title' => 'Tester','__metadata' => array('type' => 'SP.Data.TestListItem'));
$item = $list->addItem($itemProperties);
$ctx->executeQuery();

anchorman5588 avatar Mar 25 '17 02:03 anchorman5588

Greetings,

i verified the creation of list item using the similar example and cant reproduce the specified error.

Could you please provide a few more details such as:

  • which PHP version are you using
  • is authentication actually succeeds, do you get any warnings by running the following code:
$authCtx = new NetworkCredentialContext($username, $password);
$ctx = new ClientContext($url,$authCtx);
$ctx->executeQuery();  

vgrem avatar Mar 25 '17 14:03 vgrem

PHP version 5.6.27

The code you provided seems to works fine, no errors.

Also, I am able to read list items using the example code. Just can't add/write.

anchorman5588 avatar Mar 25 '17 17:03 anchorman5588

I tried adding list items to the examples/test site (SharePoint Online) and had no issue (I changed the connection settings in my own code). The only difference is my site uses the NTLM authentication because it's SharePoint 2013.

UPDATE:

I noticed it's not returning the "FormDigest" details. A vardump of $response in function requestFormDigest of ClientContext.php returns

string(344) "

Is anyone able to add a list item to SharePoint 2013?

Or is there workaround I can try?

Side note - I'm able to add list items using SOAP with another php library... but I wish to upgrade to REST service as SOAP is deprecated in SharePoint 2013.

anchorman5588 avatar Mar 27 '17 14:03 anchorman5588

Were you able to resolve this issue at all? I'm having the exact same problem.

chrisbiasbas avatar Jan 05 '18 04:01 chrisbiasbas

Nope, add/write doesn’t work with SharePoint 2013 when using NTLM auth. Had to use another library.

anchorman5588 avatar Jan 05 '18 15:01 anchorman5588