Please specify what version of the library you are using: [ 1.1.4 ]
I am running node 8.11.1, and trying to add an new subweb like this:
let now = Date.now().toString();
let add = await pnp.sp.web.webs.add("Test", now);
let url = add.web.toUrl();
My expectations is that url will point to the newly created web.
The observed behavior on v1.1.4 is that the result of toUrl() is:
https://tenant.sharepoint.com/sites/test-site/_api/https://tenant.sharepoint.com/sites/test-site/1534407111046/_api/web
whereas in v1.1.3 the result is:
https://tenant.sharepoint.com/sites/test-site/1534406924382/_api/web
(I can also see similar problems with site.openWebById(id) that will always give a pointer to the root web)
Call pnp.sp.web.webs.add and inspect the result.
Thanks for letting us know. Also experiencing the same behavior. We'll take a look.
I actually caught this the other day, we'll get it fixed up.
@koltyakov here is the fix for the body of that method, can you drop it in? What happened here is that the service changed what they returned in the "odata" object and it broke everything. Was actually the reason for the surprise release a few weeks ago.
const parts: string[] = [];
if (candidate.hasOwnProperty("odata.type") && candidate["odata.type"] === "SP.Web") {
// webs return an absolute url in the editLink
if (candidate.hasOwnProperty("odata.editLink")) {
parts.push(candidate["odata.editLink"]);
} else if (candidate.hasOwnProperty("__metadata")) {
// we are dealing with verbose, which has an absolute uri
parts.push(candidate.__metadata.uri);
}
} else {
if (candidate.hasOwnProperty("odata.metadata") && candidate.hasOwnProperty("odata.editLink")) {
// we are dealign with minimal metadata (default)
parts.push(extractWebUrl(candidate["odata.metadata"]), "_api", candidate["odata.editLink"]);
} else if (candidate.hasOwnProperty("odata.editLink")) {
parts.push("_api", candidate["odata.editLink"]);
} else if (candidate.hasOwnProperty("__metadata")) {
// we are dealing with verbose, which has an absolute uri
parts.push(candidate.__metadata.uri);
}
}
if (parts.length < 1) {
Logger.write("No uri information found in ODataEntity parsing, chaining will fail for this object.", LogLevel.Warning);
return "";
}
return combinePaths(...parts);
Thanks, @patrick-rodgers! Testing this now.
The issue was closed automatically on PR merge.
I've done some testing, everything worked great with the fix kindly provided by @patrick-rodgers.
Most helpful comment
Thanks for letting us know. Also experiencing the same behavior. We'll take a look.