phpSPO
phpSPO copied to clipboard
Can't Add list items when using NTLM auth
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();
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();
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.
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.
Were you able to resolve this issue at all? I'm having the exact same problem.
Nope, add/write doesn’t work with SharePoint 2013 when using NTLM auth. Had to use another library.