Can we use ALM API in SPHosted App to install other Apps (SPHosted or PHA) in a Site
I am trying to use ALM API in SPHosted App which have tenant level full control to install other Apps on the hostweb. is this possible and a supported usecase, if yes, how to make it work. I keep getting Method not supported error.
Here is the scenario
-
Install an SP Hosted App (say MasterApp) manually via UI on a Site. MasterApp have tenant fullcontrol
-
This SP Hosted app calls ALM REST /Install to install another SP hosted app (Say HelloWorld) which is in appcatalog. I am targeting sphost url to install the app to hostweb from appweb
-
I get below error. I made sure requestdigest and other headers is set. {"error":{"code":"-1, System.ServiceModel.ProtocolException","message":{"lang":"en-US","value":"The remote server returned an unexpected response: (405) Method Not Allowed."}}}
here is the request Request POST https://tenantname-38704515b7f3e8.sharepoint.com/SPAppMaster/_api/SP.AppContextSite(@target)/web/tenantappcatalog/AvailableApps/GetById('b83477ef-ae34-4bc3-b532-3353f4677b54')/Install?@target='https://tenantname.sharepoint.com' HTTP/1.1 Accept: application/json;odata=verbose Content-Type: application/json;odata=verbose X-RequestDigest: requestdigestvalue
Response HTTP/1.1 500 Internal Server Error Content-Type: application/json;odata=verbose;charset=utf-8 Content-Length: 176 {"error":{"code":"-1, System.ServiceModel.ProtocolException","message":{"lang":"en-US","value":"The remote server returned an unexpected response: (405) Method Not Allowed."}}}
Another scenario
-
Install Provider hosted app (say MasterPHApp) manually via UI on a Site. MasterPHApp have tenant fullcontrol.
-
This MasterPHApp calls ALM REST endpoint /install to install another app (say helloworld) in the code behind using httpwebrequest and setting bearer token.
-
I am successfully able to install helloworld app on the hostweb. No issues there.
We are trying to make this possible, however, right now only SPFX apps are installed properly (with correct permissions) using the ALM API's. Once this is fixed you should be able to complete your desired scenario.
#1144 is tracking the actual issue of not being able to install non spfx apps, so I'm going to close this issue.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues