0

I am trying create list item on Sharepoint on line using REST API. When I am creating item on the root site or on the root/subsite - everything is awesome. But if I am trying to create list item on the Team-site with URL like root/teams/msteams_cc6dfd/, I am getting error:

' <m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"> <m:code>-2130575251, System.Runtime.InteropServices.COMException</m:code> <m:message xml:lang="en-US">The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.</m:message> </m:error>'

Interisting, that GET on this site works fine, but POST no.

P.S. Sorry for my crazy English.

1 Answers1

0

POST requests need X-RequestDigest header exists in your request. You can get it from current page or from /_api/web/contextinfo endpoint.
Use this link for examples: https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/complete-basic-operations-using-sharepoint-rest-endpoints#writing-data-by-using-the-rest-interface
To get from page: "X-RequestDigest": $("#__REQUESTDIGEST").val()
To get it from contextinfo create GET request to this endpoint and extract FormDigestValue param value.
I think it will solve your problem.

UPDATED:

It can be permissions issue. Please check account permissions on this sites. If you done all correctly with X-RequestDigest then it can be only permissions issue. Is this account has required permissions to call API ? Is this account has permissions to create list item in this sites on required for you lists ?
Try to add account to site collection administrators. Is it working? Is your lists has unique permissions ? May be account has Contribute role on site but not have access to specific list because there unique permissions exists.
Can you create list items not from 1C but from other ways ? PowerShell script, Console App C#, javascript from some on your SharePoint sites? If it working correctly then issue in 1C code.

  • OK. But wuy on the 'https://tenant.sharepoint.com/test' the POST works correctly, without 'X-RequestDigest', but on the 'https://tenant.sharepoint.com/teams/test', or 'https://tenant.sharepoint.com/sites/test' it is does not work? – Evgeny Trifonov Dec 12 '18 at 07:48
  • I don't know. It is just suggestion. When I see this error last time it was because I didn't use X-RequestDigest. Did you try this ? Is it working? –  Dec 12 '18 at 08:11
  • ОК. We will try it. Now we are creating intergration between 1C and Sharepoint ;). I sent your link to 1c-developer. – Evgeny Trifonov Dec 12 '18 at 08:16
  • 1c-developer sad, that he used `X-RequestDigest`, and it is does not work on the /sites and /teams – Evgeny Trifonov Dec 12 '18 at 09:55
  • Please check account permissions on this sites. If you done all correctly with X-RequestDigest then it can be only permissions issue. Is this account has required permissions to call API ? Is this account has permissions to create list item in this sites on required for you lists ? –  Dec 12 '18 at 10:11
  • Account have "contibute" role on the all sites. On the root site and on the /teams site too. – Evgeny Trifonov Dec 12 '18 at 10:19
  • Try to add account to site collection administrators. Is it working? Is your lists has unique permissions ? May be account has Contribute role on site but not have access to specific list because there unique permissions exists. –  Dec 12 '18 at 10:21
  • Can you create list items not from 1C but from other ways ? PowerShell script, Console App C#, javascript from some on your SharePoint sites? If it working correctly then issue in 1C code. –  Dec 12 '18 at 10:22
  • I don't know what happend, but it's works! I just add full control to account. But on the other site it has only contribute and works too. I have only one idea. Some features disabled on O365 by default in your tenant, but if you start using them, they turn on. May be POST in REST API for team sites was disabled (we never used them early)? I opened ticket in MS Support and will ask. P.S. PowerShell script, Console App C#, javascript are working correctly. – Evgeny Trifonov Dec 12 '18 at 14:30
  • Good. I updated answer with data from comments. Please mark answer as accepted (or best answer) If you think that answer solved your issue. –  Dec 12 '18 at 14:35