Closed boonware closed 1 month ago
You are using a github app to operate on an installation api. So, you need to auth as the orgnization itself first. You can switch to the installation like this example.
PS: auth as the github app can only access the apis related to app itself (such as list installations). To operate on the other objects (third party which installed your app), you need to switch to specific installation (one-to-one binded to a user/org).
How do I know if an API is an "installation API"? I thought that using an app, and assuming it was installed into the org, I could use the app (not installation) to fetch information about the organization. Otherwise, every time my app is installed to an org, the installer needs to send me their installation ID but this is too cumbersome.
You can find the official documentation here: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/about-authentication-with-a-github-app
How do I know if an API is an "installation API"?
In the github rest api docs, every api will tell you which token yo use.
If the docs says: You must use a JWT to access this endpoint.
(Example), you should use the app auth.
If the docs says:
You must use installation token in this case.
send me their installation ID
No, they do not need to do this. You can simply get the installation id from the api (which needs app auth). Here is the api to get an orgnization installation: https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#get-an-organization-installation-for-the-authenticated-app
The whole app installation workflow example can be found at the githubkit's example: https://yanyongyu.github.io/githubkit/quickstart/github-app/#authenticating-as-an-installation-by-username
change the api called in the above example to get organization installation api.
If you have any other questions, feel free to open an issue 🤗
When authenticating as an app and not an installation, API requests are failing because the app installation ID is not being set. Surely, when authenticating as an app I do not need the installation ID.
I create my
github
instance as follows:Then, I list org membership. Note that my app has been installed into the requested org "foo":
This throws the following error: