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

Call to _api/GroupSiteManager/CreateGroupEx end point (to create Teams Site) causes JSON Node error #322

Open
RigidCollision opened this issue Feb 20, 2023 · 0 comments
Labels

Comments

@RigidCollision
Copy link

RigidCollision commented Feb 20, 2023

Usinbg the following to create a SharePoint Teams Site:

<?php
	error_reporting(E_ERROR);

	// autoload
	spl_autoload_register(function ($classname) {
		$classname = ltrim($classname, "\\");
		preg_match('/^(.+)?([^\\\\]+)$/U', $classname, $match);
		$classname = './'.str_replace("\\", "/", $match[1])
			.str_replace(array("\\", "_"), "/", $match[2])
			.".php";
		include_once $classname;
	});

	use Office365\Runtime\Auth\ClientCredential;
	use Office365\Runtime\Http\RequestOptions;
	use Office365\Runtime\ResourcePath;
	use Office365\SharePoint\ClientContext;
	use Office365\SharePoint\Web;

	// Data variables
	$reference="SIT0000010";
	$site="My Address";

	try {
		// Login credentials
		$credentials = new ClientCredential("MyUserId", "MyUserPass");
		$ctx = (new ClientContext("https://MyDomain.sharepoint.com"))->withCredentials($credentials);

		// Build request
		$url = "{$ctx->getBaseUrl()}/_api/GroupSiteManager/CreateGroupEx";
		$request = new RequestOptions($url);

		//payload
		$payload = array (
			"alias" => "CommunicationSite1",
			"displayName" => "CommunicationSite1",
			"isPublic" => true,
			"optionalParams" => 
			array (
				"CreationOptions" => 
				array ("SPSiteLanguage:1033","implicit_formula_292aa8a00786498a87a5ca52d9f4214a_6142d2a0-63a5-4ba0-aede-d9fefca2c767"),
				"Description" => "MyDescription",
				"Owners" => 
				array (
					"MyUserEmail"
				)
			)
		);

		// Excecute
		$resp = $ctx->getPendingRequest()->executeQueryDirect($request);
		// Capture response
		$json = json_decode($resp->getContent(), true);
		print("Site has been created: {$json["d"]["Create"]["SiteUrl"]} \n");
	}
	catch (Exception $e) {
		echo 'Failed: ',  $e->getMessage(), "\n";
	}
?>

Results in:

Failed: {"error":{"code":"-1, Microsoft.Data.OData.ODataException","message":{"lang":"en-US","value":"A node of type 'StartArray' was read from the JSON reader when trying to read a value of a property; however, a 'PrimitiveValue' or 'StartObject' node was expected."}}}

The JSON checks out as 100% valid.

{
	"alias": "CommunicationSite1",
	"displayName": "CommunicationSite1",
	"isPublic": true,
	"optionalParams": {
		"CreationOptions": ["SPSiteLanguage:1033", "implicit_formula_292aa8a00786498a87a5ca52d9f4214a_6142d2a0-63a5-4ba0-aede-d9fefca2c767"],
		"Description": "MyDescription",
		"Owners": ["MyUserEmail"]
	}
}

A remote collegue has verified that this works in Postman.

@RigidCollision RigidCollision changed the title Call to _api/GroupSiteManager/CreateGroupEx end point (to creat Teams Site) causesJSON Node error Call to _api/GroupSiteManager/CreateGroupEx end point (to create Teams Site) causes JSON Node error Feb 20, 2023
@vgrem vgrem added the bug label Oct 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants