1

I have Provider Hosted Add-In and everything is working as expected but fails on 'web.GetProvisioningTemplate(creationInfo)'.

it gives me below error

The remote server returned an error: (401) Unauthorized

Below is the complete code,

    var siteUrl = "<siteurl>"; //This is not the same url from where add in is running
var tenantAdminUrl = "";
var appId = "";
var appSecret = "";

    using (ClientContext ctx = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(tenantAdminUrl, appId, appSecret))
    {
        Tenant tenant = new Tenant(ctx);
        ctx.Load(tenant);
        ctx.ExecuteQuery();

        var site = tenant.GetSiteByUrl(siteUrl);
        var web = site.RootWeb;

        ctx.Load(site);
        ctx.Load(web);
        ctx.ExecuteQuery();

        var sourcelist = web.GetList(listUrl);
        ctx.Load(sourcelist);
        ctx.ExecuteQuery();

        ProvisioningTemplateCreationInformation creationInfo = new ProvisioningTemplateCreationInformation(web);

        var provisioningTemplate = web.GetProvisioningTemplate(creationInfo);

    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.