Skip to content

Conversation

siddharth-vaghasia
Copy link
Contributor

Type

  • [x ] New Feature

Related Issues?

NA

What is in this Pull Request ?

Added new command Export-PnPPowerApp which will export a specified PowerApp as zip package, this command would be useful to automate the backup of the PowerApp/s or to automate the deployment in DevOps

Note - @gautamdsheth @KoenZomers - I would need your advise/feedback specifically on one thing... so adding some comments in PR for your comment.

resources = wrapper.Resources
};

var responseHeader = RestHelper.PostAsyncGetResponseHeader<string>(Connection.HttpClient, $"https://api.bap.microsoft.com/providers/Microsoft.BusinessAppPlatform/environments/{environmentName}/exportPackage?api-version=2016-11-01", AccessToken, payload: exportPostData).GetAwaiter().GetResult();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gautamdsheth @KoenZomers
To Export a PowerApp Package we need to make multiple API Calls, and this is 2nd call /exportpackage which returns us the location of another URL which will tell us when the download is ready but we have to keep of sending request.... and then when the status is successed it would return the url of zip file. Now the location property from this API call comes in response Headers and not as a response content so I had to introduce new functions in RestHelper which will return us headers to read the response headers properties.

So if you check in RestHelper, I have added two new functions...open to suggestions on the best way to handle this?

}
}

private static async Task<HttpResponseHeaders> SendMessageAsyncGetResponseHeader(HttpClient httpClient, HttpRequestMessage message)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New method to make API Call but return Response Headers rather than content

return default(T);
}

public static async Task<HttpResponseHeaders> PostAsyncGetResponseHeader<T>(HttpClient httpClient, string url, string accessToken, object payload, bool camlCasePolicy = true, string accept = "application/json")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base method which is being called from actuall command.cs file.

@gautamdsheth
Copy link
Collaborator

Can you please move the logic to a separate file or create one like PowerAppsUtility ? We can move the all these REST calls in there and keep the cmdlet clean and just return the link if available ?

Also, can you please rename the method as GetPackageLink ?

About the method names, am still thinking on how to reduce duplicate code, will get back to you on that

@siddharth-vaghasia
Copy link
Contributor Author

Can you please move the logic to a separate file or create one like PowerAppsUtility ? We can move the all these REST calls in there and keep the cmdlet clean and just return the link if available ?

Also, can you please rename the method as GetPackageLink ?

About the method names, am still thinking on how to reduce duplicate code, will get back to you on that

Hi @gautamdsheth - sorry was not able get to this sooner... I have updated as per review comments. please check now?

@gautamdsheth gautamdsheth merged commit 46ccefe into pnp:dev Jul 17, 2023
@gautamdsheth
Copy link
Collaborator

Thanks @siddharth-vaghasia , merged this, amazing stuff ! Much appreciated 😊🙏
Sorry for late response.

@siddharth-vaghasia
Copy link
Contributor Author

hi @gautamdsheth - do let me know when it would be available for testing? I will test it once :)

@KoenZomers
Copy link
Collaborator

@siddharth-vaghasia Should be in the current nightly build. Every night at 2.30 AM CET a nightly build gets created which contains the latest code thus far.

@LucasCXavier
Copy link

Hi @KoenZomers, @siddharth-vaghasia. Hope you are doing well!
I'm having trouble executing this cmdlet as it's not appearing in my list of available commands. Are there any prerequisites I might be missing?
Thank you in advance!

@siddharth-vaghasia
Copy link
Contributor Author

hi @LucX4 - can you please the PnP PowerShell version you are using?

@LucasCXavier
Copy link

Hi @siddharth-vaghasia,

It's 1.12.0:

image

@LucasCXavier
Copy link

@siddharth-vaghasia,
I wasn't using the latest version. I'm able to run the command now.
Thanks for your help.

@LucasCXavier
Copy link

Hi @siddharth-vaghasia and @gautamdsheth, hope you're doing well!

I've been trying to run the Export-PnPPowerApp cmdlet for several hours but haven't had any success so far.
Even when authenticating via the .pfx certificate, I'm encountering a Forbidden error.

The error message says that the service principal doesn't have permission to access:

https://10.0.5.20:20273/providers/Microsoft.BusinessAppPlatform/environments/

The App Registration has already been added as System Administrator in the target environment, so it's unclear what's missing.

Has anyone faced something similar before or knows if there are additional permission steps required (perhaps at the Enterprise Application level or API permissions in Azure)?

Thanks,
Lucas

@siddharth-vaghasia
Copy link
Contributor Author

hi @LucasCXavier - Did you try running it with User's Permission to verify?...just connect pnp-online with any SharePoint site in interactive mode and the user should have access to targetted PowerApps as owner.

@LucasCXavier
Copy link

Hi @siddharth-vaghasia,
I got the following errror when trying to use Connect-PnPOnline -url https://tenant.sharepoint.com -interactive.
Connect-PnPOnline: Specified method is not supported.

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

Successfully merging this pull request may close these issues.

4 participants