Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Create site via REST API with App-only authorization policy

$
0
0

I'm trying to develop a desktop service using the App-only authorization policy that automatically manages certain aspects of an Office 365 tenant. Specifically, I'm trying to create and delete sites/subsites via the REST API.

I have successfully imported TokenHelper.cs into my test harness to get an access token and to make basic changes. For example, I can easily do the following via REST to an instance "mycorpx.sharepoint.com":

  • Get the title
  • Get the context info and retrieve the value to populate X-RequestDigest header for later POST actions
  • Get lists - all or by name
  • Create Lists
  • Create folders

However, when I attempt to create a site via the REST API documented here:

http://msdn.microsoft.com/en-us/library/office/jj164022.aspx - Creating a site with REST

I'm doing the following with C#, but the example is JavaScript.

HttpWebRequest folderSiteRequest = (HttpWebRequest)HttpWebRequest.Create(_targetAppUri.ToString() + "_api/web/webinfos/add");

I get an HTTP error of 400 - bad request.

When the App is registered, I give it the following scope and permissions:

<AppPermissionRequests><AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="FullControl"/></AppPermissionRequests>

I've even tried the following, but the same error persists:

<AppPermissionRequests><AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl"/></AppPermissionRequests>

If I perform the site management with the CSOM tenant administration methods (e.g. CreateSite()) and use the tenant admin URI, then I can create sites without a problem. For example:

var SHAREPOINT_PID = "00000003-0000-0ff1-ce00-000000000000"; // SharePoint constant           
var tenantAdminUri = new Uri("https://mycorpx-admin.sharepoint.com");

string token = TokenHelper.GetAppOnlyAccessToken(SHAREPOINT_PID, tenantAdminUri.Authority, null).AccessToken;

ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(tenantAdminUri.ToString(), token)

...

clientContext.ExecuteQuery();

I want to standardize on one API and would like to understand what I'm doing wrong with regard to the REST API and creating sites given that so far I can do almost everything else that I need/want to do. Am I missing something regarding the 

Thanks in advance,

Mattd


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>