I have created pages then added web-part zones / web-parts programmatically using below function,
function addWebPart(webUrl, pageUrl,webPartXml,zoneId,zoneIndex, Success,Error){
var context = new SP.ClientContext(webUrl);
var web = context.get_web();
var file = web.getFileByServerRelativeUrl(webUrl + pageUrl);
var webPartMngr = file.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared);
var webPartDef = webPartMngr.importWebPart(webPartXml);
var webPart = webPartDef.get_webPart();
webPartMngr.addWebPart(webPart, zoneId, zoneIndex);
context.load(webPart);
context.executeQueryAsync(
function() {
Success(webPart);
},
Error
);
Now, I need to create a page then add web-part zones / web-parts programmatically in SharePoint online using PnP JS.
Can anyone help me with the same?
You could refer to this question: https://github.com/pnp/pnpjs/issues/557
Using PnPJS, You need to grab webpart xml in a page and add it in page content.