1

I'm currently reading up on using REST urls to add data in SharePoint 2013 On-Premises. Ultimately, I'd like to use JavaScript to leverage REST. I found this guide about testing this functionality through Fiddler.

I have run into some errors and I'm hoping someone here can help me identify why.

My request in Fiddler composer:

POST http://sp2013/_api/web/lists/getByTitle('TEST‘)/items HTTP/1.1
ACCEPT: application/json;odata=verbose
Content-Type: application/json;odata=verbose
X-RequestDigest: 0x9D22271840E34310DC94173D764AA679D3E1FD9F8F3C56816C64D7EC7769D6373CCC14F4EF5095FCABAC115B81ECC5CA767606603A9F800C4A26B00263548DF9
Host: sp2013
Content-Length: 104

Request Body:
{‘_metadata':{‘type':’SP.Data.TESTListItem’},
‘Title':’My Item’};

I get 403 back after execution. Error message under JSON tab “value=The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.”

Inspectors > Headers

Request Headers POST /_api/web/lists/getByTitle(‘TEST’)/items HTTP/1.1
Client: ACCEPT: application/json;odata=verbose
Cookies/ Login: Authorization: NTLM TlRMTVNTUAADAAAAGAAYAH4AAABgAWABlgAAAAwADABYAAAADAAMAGQAAAAOAA4AcAAAABAAEAD2AQAANYKI4gYDgCUAAAAPaXDnH+TwVxwmtRoMN7kF80IAQQBNAEIATwBPAGsAcABpAG4AdABvAEsAUABMAFQANwA2ADQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA29lgEyWuouINwQXxvOAE+QEBAAAAAAAAxZdD0ROU0AGyvCMcqiyyCgAAAAACAAQAUQBBAAEAEABNAEIAUwBQADIAMAAxADMABAAeAHEAYQAuAEIAYQBtAGIAbwBvAC4AbABvAGMAYQBsAAMAMABNAEIAUwBQADIAMAAxADMALgBxAGEALgBCAGEAbQBiAG8AbwAuAGwAbwBjAGEAbAAFABgAQgBhAG0AYgBvAG8ALgBsAG8AYwBhAGwABwAIAMWXQ9ETlNABBgAEAAIAAAAIADAAMAAAAAAAAAABAAAAACAAAOsI1DrUsj/QuC65hIvjd7wGOaN4bv579Bsas1/lTiGMCgAQAAAAAAAAAAAAAAAAAAAAAAAJADoASABUAFQAUAAvAG0AYgBzAHAAMgAwADEAMwAuAHEAYQAuAGIAYQBtAGIAbwBvAC4AbABvAGMAYQBsAAAAAAAAAAAAAAAAALBGUQ6shfqgaazYVFVgWks=
Entity Content-Length: 73 Content-Type: application/json;odata=verbose
Miscellaneous X-RequestDigest: 0x9D22271840E34310DC94173D764AA679D3E1FD9F8F3C56816C64D7EC7769D6373CCC14F4EF5095FCABAC115B81ECC5CA767606603A9F800C4A26B00263548DF9

1 Answer 1

1

The issue is with your request digest -- refer back to the tutorial you mentioned under the section "What if i want to POST (Add) Data to my SharePoint List?" and make sure you follow steps 1-6; the request digest values also expire, so it needs to be done within a relatively short amount of time...

If you're going to use REST with JavaScript anyway (and not C# as was the intention of the tutorial you referenced) I suggest you just fire up a browser and use the dev tools to do all of your testing anyway (chrome dev tools network tab will be about as helpful as fiddler for you if you're going to use JS from a SharePoint page).

That request digest value can be found as a page variable on any SP page with a standard master page. You can find it with document.getElementById("__REQUESTDIGEST").value

1
  • How quickly do the Request Digests change? I have 3 different values. One from doing a POST on contextinfo, one from doing getElementById on the page, and then when I execute, I get a different one in Inspectors > Headers.. Do I include just the date and time stamp at the end? (I've tried with and without). X-RequestDigest: 0x99ACFD37F8678B93FAEC36F62C3808B9CC708E727712D22A5DD5669339C378CCEB1835E9CEE464F8EAF259BD23DC6EF4DA4A66D4508813A5829FDA97AEB76258,22 May 2015 18:55:53 -0000 This was done within a few minutes.
    – spex5
    Commented May 22, 2015 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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