|
1 | 1 | # Connecting to GitHub Enterprise |
2 | 2 |
|
3 | | -Connecting to the GitHub Enterprise is similar to the public GitHub API, but requires two specific configurations: |
| 3 | +Connecting to GitHub Enterprise is similar to using the public GitHub API, but requires two specific configurations. Each is explained below with brief guidance and examples. |
4 | 4 |
|
5 | | -- To connect to **GitHub Enterprise Server**, you must provide the server's API endpoint in the `base_url` parameter. |
6 | | -- You need to switch the REST API schema version when using client. |
| 5 | +## Provide the server API endpoint |
7 | 6 |
|
8 | | -=== "Sync" |
| 7 | +When connecting to a GitHub Enterprise Server (GHES or GHEC), you must set the server's REST API endpoint via the `base_url` parameter when creating the client. Use the full API base URL for your instance (for example `https://example.ghe.com/api/v3/`). githubkit will ensure the trailing slash is present. |
| 8 | + |
| 9 | +This tells the client where to send REST and GraphQL requests rather than the public GitHub endpoints. |
| 10 | + |
| 11 | +```python hl_lines="4 7" |
| 12 | +from githubkit import GitHub |
| 13 | +from githubkit.versions.latest.models import PublicUser, PrivateUser |
| 14 | + |
| 15 | +github = GitHub("<your_token_here>", base_url="https://example.ghe.com/api/v3/") |
| 16 | +``` |
| 17 | + |
| 18 | +## Switch the REST API schema version |
9 | 19 |
|
10 | | - ```python hl_lines="4 7" |
11 | | - from githubkit import GitHub |
12 | | - from githubkit.versions.latest.models import PublicUser, PrivateUser |
| 20 | +GitHub Enterprise Server may require a different REST API schema/version than the public API. Use the `rest("<schema-version>")` selector on the client to choose the correct REST schema for your server (for example `ghec-2022-11-28`). Picking the right schema ensures endpoint signatures match your server version and provides autocompletion support in your IDE. |
13 | 21 |
|
14 | | - github = GitHub("<your_token_here>", base_url="https://example.ghe.com/api/v3/") |
| 22 | +The examples below demonstrate how to use both REST API and GraphQL API calls: |
15 | 23 |
|
16 | | - # call GitHub rest api |
| 24 | +=== "Sync" |
| 25 | + |
| 26 | + ```python hl_lines="2" |
| 27 | + # Call the GitHub REST API with a specific schema version |
17 | 28 | resp = github.rest("ghec-2022-11-28").users.get_authenticated() |
18 | 29 | user: PublicUser | PrivateUser = resp.parsed_data |
19 | 30 |
|
20 | | - # call GitHub graphql api |
| 31 | + # Call the GitHub GraphQL API |
21 | 32 | data: dict = github.graphql("{ viewer { login } }") |
22 | 33 | ``` |
23 | 34 |
|
24 | 35 | === "Async" |
25 | 36 |
|
26 | | - ```python hl_lines="4 7" |
27 | | - from githubkit import GitHub |
28 | | - from githubkit.versions.latest.models import PublicUser, PrivateUser |
29 | | - |
30 | | - github = GitHub("<your_token_here>", base_url="https://example.ghe.com/api/v3/") |
31 | | - |
32 | | - # call GitHub rest api |
| 37 | + ```python hl_lines="2" |
| 38 | + # Call the GitHub REST API with a specific schema version |
33 | 39 | resp = await github.rest("ghec-2022-11-28").users.async_get_authenticated() |
34 | 40 | user: PublicUser | PrivateUser = resp.parsed_data |
35 | 41 |
|
36 | | - # call GitHub graphql api |
| 42 | + # Call the GitHub GraphQL API |
37 | 43 | data: dict = await github.async_graphql("{ viewer { login } }") |
38 | 44 | ``` |
| 45 | + |
| 46 | +For more information, see [REST API Versioning](../usage/rest-api.md#rest-api-versioning). |
0 commit comments