1

I'm quite new to Sharepoint stuff, and currently am trying to interact with the REST API. I have been able to get all kinds of data without much problems by sending GET reuqests, but sending POST requests has not worked so far (unless sending a POST request to get the context info).

Basically I am trying to add a subsite to my existing site, following the examples from https://msdn.microsoft.com/EN-US/library/office/jj164022.aspx#WritingData ("Section: Create a Site with REST") - however I am using Java as my choice of development language.

First I sent a post request to /_api/contextinfo to get the formDigestValue. I include this as a header for the variable "X-RequestDigest". Is this correct way of approaching things?

Afterwards I manage to send the following POST request - but constantly get a 400 Bad Request error.

******** LOGGING REQUEST ******** 
Request Method: POST 
Request URI: https://<site_url_hidden>/_api/web/webinfos/add 

Request Headers: 
{X-RequestDigest=[0x16B17C7ECCC4A9D9B42B4F91F1518BAB394F9D...<context_info_retrieved_prior_to_post>],
accept=[application/json;odata=verbose], 
content-type=[application/json;odata=verbose],  
Content-Length=[207], 
Authorization=[<OAUTH_STIFF]}

Body: 
{"parameters": {
    "__metadata":{"type":"SP.WebInfoCreationInformation"},
    "url":"RestSubWeb",
    "title":"RestSubWeb",
    "description":"REST created web",
    "language":1033,
    "webTemplate":"STS",
    "useUniquePermissions":false
    }
}
Response Status: 400

The request seems to match what the example is showing, as far as I can see... so currently am pretty clueless on what could be wrong.

Appreciate any help, tips, etc...

EDIT: The error I get is:

"value":"A value was encountered that has a type name that is incompatible with the metadata. 
The value specified its type as 'SP.WebInfoCreationInformation', but the type specified in the metadata is 'SP.WebCreationInformation'."

After changing the type to SP.WebCreationInformation I get the following error:

,"value":"The property 'language' does not exist on type 'SP.WebCreationInformation'. Make sure to only use property names that are defined by the type."}

EDIT2: Seems like the properties are case sensitive. Sending the correct values has now fixed the problem of 400 - Bad request. Now getting a 401 Unauthorized instead.

Thanks,

5
  • Helpful? sharepoint.stackexchange.com/questions/152778/…
    – Akhoy
    Aug 10, 2015 at 14:06
  • Not sure... my headers look correct. I'm getting also a different error. But I'll try the code in the example and see if I can get anywhere with it. Aug 10, 2015 at 15:31
  • are you using JS to make these calls? Aug 10, 2015 at 18:23
  • No - using Java. But I'll give it a try with JS tomorrow morning just to see if it works or not... at this point I'd be happy just to get a POST request go through. :) Aug 10, 2015 at 19:25
  • Did not manage to send requests via JS. Keep getting 403 error and couldn't figure out how to get past it. Got info on error messages when sending via Java - added to original post. Investigation continues. Aug 11, 2015 at 7:23

0

Your Answer

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

Browse other questions tagged or ask your own question.