I've recently found this nice thread on adding an existing webpart using the csom: Add an existing WebPart Using the Sharepoint client object Model
I've tried the same approach for an app part (so an app part packaged in a .app) however I haven't found this particular part to reside in the web part gallery and as such I can't edit and retrieve this app part's XML. (I'm sure it is correctly installed as I can add the part while editing the page after I've added the app to the page. I've also compared the count of the items in the webpart gallery before and after installing the app and it seems to stay the same so I don't think I'm overlooking the part.)
What location or in what manner would I be able to retrieve this xml? Or should I try a different approach to adding an app part programmatically?
EDIT: I found a way to export as .webpart.
- Add the web part to the site
- Open the site page .aspx using sharepoint designer.
- Add the following attribute to the ClientWebPart: ExportMode="All"
- save your changes
- Now you can go back, edit your page in sharepoint and then choose "Export"