Arbab Nazar
Arbab Nazar

Reputation: 23811

How to find my organization Id over github?

How I can find my GitHub organization id?

Ideally through a script or a command I can parse its output.

Upvotes: 8

Views: 13418

Answers (4)

Yashash Gaurav
Yashash Gaurav

Reputation: 621

I was looking for the Org ID of an org that I was part of and used gh org list.

Note: if the org is private you will have to auth first using: gh auth login

Upvotes: 0

Marcin Kłopotek
Marcin Kłopotek

Reputation: 5991

Using gh CLI:

gh api orgs/<org-name> --jq .id

Note it will work out of the box for public organizations. For private ones you have to be authenticated:

gh auth login

Upvotes: 6

VonC
VonC

Reputation: 1329692

Type:

curl -H "Authorization: token OAUTH-TOKEN" https://api.github.com/organizations

(replace OAUTH-TOKEN by your own GitHub access token: see "Git automation with OAuth tokens" to get or create a PAT: a Personal Access Token)

You will see that you can below to more than one organization.

For each one:

curl -H "Accept: application/json" -H "Authorization: token OAUTH-TOKEN" https://api.github.com/organizations/<anorg> | jq ".id"

With jq (lightweight command-line JSON processor, which is available for all OS including Windows), you will get directly the id.

Upvotes: 8

Arbab Nazar
Arbab Nazar

Reputation: 23811

You can find it with the following command:

curl -H "Authorization: token personal-access-token" https://api.github.com/orgs/name-of-your-org

This command output something like this:

{
  "login": "your-org",
  "id": 15156947,
  "url": "https://api.github.com/orgs/your-org",
  "repos_url": "https://api.github.com/orgs/your-org/repos",
  "events_url": "https://api.github.com/orgs/your-org/events",
  "hooks_url": "https://api.github.com/orgs/your-org/hooks",
  "issues_url": "https://api.github.com/orgs/your-org/issues",
  "members_url": "https://api.github.com/orgs/your-org/members{/member}",
  "public_members_url": "https://api.github.com/orgs/your-org/public_members{/member}",
  "avatar_url": "https://avatars.githubusercontent.com/u/15056937?v=3",
  "description": "",
  "name": "",
  "company": null,
  "blog": "",
  "location": "",
  "email": "",
  "public_repos": 1,
  "public_gists": 0,
  "followers": 0,
  "following": 0,
  "html_url": "https://github.com/your-org",
  "created_at": "2013-11-09T21:58:06Z",
  "updated_at": "2014-09-18T16:54:44Z",
  "type": "Organization",
  "total_private_repos": 0,
  "owned_private_repos": 0,
  "private_gists": 0,
  "disk_usage": 0,
  "collaborators": 0,
  "billing_email": "[email protected]",
  "plan": {
    "name": "free",
    "space": 976562499,
    "private_repos": 0,
    "filled_seats": 2,
    "seats": 0
  }
}

So second line contain the desired org id:

"id": 15156947

Hope that help others.

Upvotes: 6

Related Questions