Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for creating Site Collection #23

Closed
swapnilgaonkar opened this issue May 11, 2020 · 7 comments
Closed

Support for creating Site Collection #23

swapnilgaonkar opened this issue May 11, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@swapnilgaonkar
Copy link

I can't find API in your library to create new Site Collection.
There is API to create sub-site under particular site but no API to create Site collection

@swapnilgaonkar swapnilgaonkar added the enhancement New feature or request label May 11, 2020
@koltyakov
Copy link
Owner

Hi @swapnilgaonkar, are you running SharePoint Online?

In SPO, we can handle this using /_api/SPSiteManager endpoint. However, if it's On-Prem it depends on the version, and not possible via client-side APIs in older SharePoint versions.

@koltyakov
Copy link
Owner

koltyakov commented May 11, 2020

@swapnilgaonkar
Copy link
Author

Thanks for reply.
I am running SPO.
I have tried /_api/SPSiteManager. It can be used to create modern sites only(can not create classic sites. Failed with error "Performing this operation on a site with this template is not allowed"). Correct me if I am wrong

I am looking for API/method which can create all type of site collection(similar to 'tenant.CreateSite' in c# CSOM).
Do you think it will be possible to do it using Rest API similar to '/_api/SPSiteManager'

@koltyakov
Copy link
Owner

Classic site collections can only be created using Tenant API (CSOM, that you've mentioned), it's unlikely that something will appear in REST or Graph regarding Classic sites ever.
A Tenant site can be requested using gosip, CSOM XML package can be constructed "manually", for example, if the aim is to avoid any .Net dependencies and have the feature in pure Go. The site classic add command from O365 CLI can be reproduced. And there is CSOM requests helper (example) in gosip for workaround some REST API gaps. Though, I didn't have plans to extend gosip with any tenant-level APIs. As it can lead to serious efforts to add support for all management features while at the same time, true cross-platform tools such as Office 365 CLI already exist for management purposes.

So, if it's single time automation I'd suggest mixing Go & other friendly technologies together. If a method which is entended being in a solution and only pure Go is appropriate without other prerequisites and dependencies, when ProcessQuery helper and crafted CSOM XML package withing a custom method is a way to go.

@swapnilgaonkar
Copy link
Author

swapnilgaonkar commented May 15, 2020

Thanks,
I was able to create classic site using above suggestion related to CSOM XML package and CSOM requests helper in library

@swapnilgaonkar
Copy link
Author

swapnilgaonkar commented May 15, 2020

FYI, I have to modify ProcessQuery by adding code mentioned in bold.
This is necessory to avoid https://stackoverflow.com/questions/31398044/got-error-invalid-character-%C3%AF-looking-for-beginning-of-value-from-json-unmar
This issue was seen only when api was failing to create site.

data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
data = bytes.TrimPrefix(data, []byte("\xef\xbb\xbf"))

var arrRes []interface{}
if err := json.Unmarshal(data, &arrRes); err != nil {
return data, err
}

koltyakov added a commit that referenced this issue May 15, 2020
@koltyakov
Copy link
Owner

Interesting. Maybe it's environment-specific as ProcessQuery's implementation is used in a number of places but no issues due to BOM prefix. Added BOM prefix removal to the codebase, at least it doesn't break anything with CSOM which worked before.

If you'd like, feel free to post a PR with an example for classic sites in SPO to the sandbox project, so we can reference it as a solution here for others to reuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants