Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New sample script: list sites where the particular app is installed #1634

Closed
waldekmastykarz opened this issue Jun 5, 2020 · 20 comments
Closed

Comments

@waldekmastykarz
Copy link
Member

Docs
Author n/a
Original Post n/a
Description List all sites where the particular app is installed
Keywords SharePoint Framework Governance
@kunj-sangani
Copy link

Hi @waldekmastykarz
Do we just want to iterate all the site collections present in the tenant and check for the site collection app catalog and see if the id of the app or name of the app provided is present or not in the sample

@waldekmastykarz
Copy link
Member Author

Initially, the idea was to get the list of all sites in which the particular app is installed, in case the app hasn't been deployed globally to all sites. I don't know off the top of my head if a site collection app catalog would change anything with regards to how an installed app is detected, but it would be good to verify that in both cases apps are being correctly picked up. Would you like to give it a try? 🙂

@kunj-sangani
Copy link

yes sure @waldekmastykarz
But I tried a few sets of command
spo app list -- But it only provides the list of application present in the app catalog and not the installed
spo app get -- Provides the information about the app but not where the app is installed

Sorry but I was not able to find any command which would list installed app in a site collection can you please guide on that

@waldekmastykarz
Copy link
Member Author

Yes, it seems that we're missing commands for this script. App instances can be retrieved using CSOM but we don't have it implemented in Office 365 CLI right now. Would you be interested in building this command first?

@kunj-sangani
Copy link

@waldekmastykarz I would like to give it a try

@waldekmastykarz
Copy link
Member Author

Awesome! Let's start by creating a new issue with the spec (we have an issue template for that). Once we've verified that we're thinking about the same, you can start working on it. Fair enough? 🙂

@kunj-sangani
Copy link

Yes Sure @waldekmastykarz
Let me create an issue with the spec

@nbelyh
Copy link

nbelyh commented Nov 4, 2020

@kunj-sangani
Did you have a chance to look into this issue? Is there any progress?
I'm also interested in getting a list of sites where an app is installed (or at least a check if the app is installed on a particular site) 😄

@waldekmastykarz
Is it possible to call REST API directly using CLI? I was thinking about a workaround like:

/_api/web/AppTiles?$select=Title

If I could call that in the authenticated context of CLI, that would be good enough for me...

@waldekmastykarz
Copy link
Member Author

Not at the moment, no, but you can get an access token from the CLI and issue the request using curl or a similar tool.

@nbelyh
Copy link

nbelyh commented Nov 4, 2020

Thanks, found it! Token is also good enough 👍

@nbelyh
Copy link

nbelyh commented Nov 6, 2020

May be of some interest, here is a script fragment for Azure DevOps that checks if an app is installed on the target site (assuming "ubuntu-latest" image, o365 CLI installed, and tenant, target_site, and app_name to be tenant name, site name, and the app name respectively.

- script: |
  CMD_GET_TOKEN=$(o365 util accesstoken get -r <TENANT>)
  echo "##vso[task.setvariable variable=SpToken]${CMD_GET_TOKEN}"

- script: |
  CMD_IS_APP_INSTALLED=$(curl -s -H "Authorization: Bearer $(SpToken)" -H "Accept: application/json" <TARGET_SITE>/_api/web/AppTiles?$filter=Title%20eq%20%27<APP_NAME>%27)
  echo "##vso[task.setvariable variable=SpAppInstalled]${CMD_IS_APP_INSTALLED}"

and the condition to use in some other task that depends on the fact if app is installed or not (quite dirty, it just looks for string matching app name in the stringified JSON returned by CURL, but was good enough for my purposes)

condition: contains(variables['SpAppInstalled'], '<APP_NAME>')

@waldekmastykarz
Copy link
Member Author

Thanks for sharing @nbelyh 👍

@waldekmastykarz
Copy link
Member Author

Since we shipped #2025 we're no longer blocked and could pick this up again.

@plamber
Copy link
Contributor

plamber commented Nov 7, 2021

Hi @nbelyh and @waldekmastykarz,
I had a look into this.

What do you think about this approach:

Lookup the app by title or Lookup the app by ProductId.
- loop over all sites using "m365 spo site classic list"
- for each site call m365 spo app instance list and filter by title or productId

This should give you the desired results.

I was thinking about a practical example for SharePoint administrators. Imagine you have an app that is installed in the app catalog with a specific version. As an admin I want to be sure that when I am upgrading to the latest version from the app catalog, that all app instances in the tenant are being updated to the latest version.

If I am not mistaken, I have to know where these apps are installed to perform the desired upgrade operation.

Based on this assumption I was looking what values the m365 spo app instance list retrieves.
image
I am lacking the Version value of that specific app. Do you have any idea why it is not returned? Without this information I am not able to report all different versions of a specific app in my environment.

Cheers

@nbelyh
Copy link

nbelyh commented Nov 7, 2021

Hi @plamber! At the time of creating this issue, the "app instance list" command did not exist, in fact it was added as a solution for this issue, if you look at the history of the linked issue above. Its implementation is based on _api/web/AppTiles, like described here, but that API does not seem to provide any version information. To get the app version, that underlying SharePoint API needs to be extended, as far a I understand.

@plamber
Copy link
Contributor

plamber commented Nov 7, 2021

Hi @nbelyh or @kunj-sangani ,
are you still interested in creating the sample code from this issue?

We could then see if we should look for another usecase in a separate issue.

Cheers

@nbelyh
Copy link

nbelyh commented Nov 7, 2021

@plamber from my side it's not needed, the code that would iterate all sites and then calling "app instance list" on each seems to be obvious. I.e. for me this issue was relevant one year ago, when "app instance list" did not exist, but not now.

@waldekmastykarz
Copy link
Member Author

What do you think about this approach:

Lookup the app by title or Lookup the app by ProductId.

  • loop over all sites using "m365 spo site classic list"
  • for each site call m365 spo app instance list and filter by title or productId

@plamber apps are deployed in a site collection app catalog but installed in a web, so if we're to get the list of all sites where the app is installed, we'd need to iterate over all webs and not site collections, right?

@Adam-it Adam-it added the hacktoberfest Issue perfect for hacktoberfest label Sep 25, 2022
@Jwaegebaert Jwaegebaert removed the hacktoberfest Issue perfect for hacktoberfest label Nov 2, 2022
@SmitaNachan
Copy link
Contributor

Can I take this?

@Jwaegebaert
Copy link
Contributor

You sure can! All yours @SmitaNachan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment