Skip to content

Commit d9ee464

Browse files
authored
Add defaultRestApiVersion context variable (#60508)
1 parent 7890dc1 commit d9ee464

File tree

8 files changed

+19
-14
lines changed

8 files changed

+19
-14
lines changed

content/billing/tutorials/automate-usage-reporting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ You must authenticate your request to this endpoint.
7272
```bash
7373
curl -L \
7474
-H "Authorization: Bearer $GITHUB_TOKEN" \
75-
-H "X-GitHub-Api-Version: 2022-11-28" \
75+
-H "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
7676
https://api.github.com/enterprises/ENTERPRISE/settings/billing/usage/summary
7777
```
7878

@@ -82,7 +82,7 @@ Replace `ENTERPRISE` with the enterprise slug and set the `GITHUB_TOKEN` environ
8282

8383
```bash
8484
gh api \
85-
-H "X-GitHub-Api-Version: 2022-11-28" \
85+
-H "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
8686
/enterprises/ENTERPRISE/settings/billing/usage/summary
8787
```
8888

content/billing/tutorials/control-costs-at-scale.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ In your terminal, run the following command, replacing `ENTERPRISE` with the slu
132132
```shell copy
133133
gh api \
134134
-H "Accept: application/vnd.github+json" \
135-
-H "X-GitHub-Api-Version: 2022-11-28" \
135+
-H "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
136136
/enterprises/ENTERPRISE/settings/billing/cost-centers
137137
```
138138

@@ -174,7 +174,7 @@ In your terminal, run the following command, replacing `ENTERPRISE` and `NAME` w
174174
gh api \
175175
--method POST \
176176
-H "Accept: application/vnd.github+json" \
177-
-H "X-GitHub-Api-Version: 2022-11-28" \
177+
-H "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
178178
/enterprises/ENTERPRISE/settings/billing/cost-centers \
179179
-f 'name=NAME'
180180
```
@@ -200,7 +200,7 @@ In your terminal, run the following command, replacing `COST_CENTER_ID` with the
200200
gh api \
201201
--method POST \
202202
-H "Accept: application/vnd.github+json" \
203-
-H "X-GitHub-Api-Version: 2022-11-28" \
203+
-H "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
204204
/enterprises/ENTERPRISE/settings/billing/cost-centers/COST_CENTER_ID/resource \
205205
--input - <<< '{
206206
"users": [
@@ -244,7 +244,7 @@ In your terminal, run the following command, replacing `ENTERPRISE`, `COST_CENTE
244244
gh api \
245245
--method POST \
246246
-H "Accept: application/vnd.github+json" \
247-
-H "X-GitHub-Api-Version: 2022-11-28" \
247+
-H "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
248248
/enterprises/ENTERPRISE/settings/billing/budgets \
249249
-f budget_type='SkuPricing' \
250250
-f budget_product_sku='copilot_premium_request' \

content/code-security/how-tos/secure-at-scale/configure-enterprise-security/configure-specific-tools/setting-dependabot-to-run-on-github-hosted-runners-using-vnet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ If your Azure VNET environment is configured with a firewall with an IP allowlis
9393
curl -L \
9494
-H "Accept: application/vnd.github+json" \
9595
-H "Authorization: Bearer YOUR-TOKEN" \
96-
-H "X-GitHub-Api-Version: 2022-11-28" \
96+
-H "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
9797
https://api.github.com/meta
9898
```
9999

content/github-models/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ To call models programmatically, you’ll need:
4545
-X POST \
4646
-H "Accept: application/vnd.github+json" \
4747
-H "Authorization: Bearer YOUR_GITHUB_PAT" \
48-
-H "X-GitHub-Api-Version: 2022-11-28" \
48+
-H "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
4949
-H "Content-Type: application/json" \
5050
https://models.github.ai/inference/chat/completions \
5151
-d '{"model":"openai/gpt-4.1","messages":[{"role":"user","content":"What is the capital of France?"}]}'

content/rest/about-the-rest-api/api-versions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ You should use the `X-GitHub-Api-Version` header to specify an API version. For
3434
curl {% data reusables.rest-api.version-header %} https://api.github.com/zen
3535
```
3636

37-
Requests without the `X-GitHub-Api-Version` header will default to use the `2022-11-28` version.
37+
Requests without the `X-GitHub-Api-Version` header will default to use the `{{ defaultRestApiVersion }}` version.
3838

3939
If you specify an API version that is no longer supported, you will receive a `400` error.
4040

content/rest/using-the-rest-api/getting-started-with-the-rest-api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ The following example request uses the ["Get Octocat" endpoint](/rest/meta/meta#
256256
```shell copy
257257
gh api --method GET /octocat \
258258
--header 'Accept: application/vnd.github+json' \
259-
--header "X-GitHub-Api-Version: 2022-11-28"
259+
--header "X-GitHub-Api-Version: {{ defaultRestApiVersion }}"
260260
```
261261

262262
#### Example request using query parameters
@@ -275,7 +275,7 @@ The following example uses the ["Create an issue" endpoint](/rest/issues/issues#
275275
```shell copy
276276
gh api --method POST /repos/{% ifversion ghes %}REPO-OWNER/REPO-NAME{% else %}octocat/Spoon-Knife{% endif %}/issues \
277277
--header "Accept: application/vnd.github+json" \
278-
--header "X-GitHub-Api-Version: 2022-11-28" \
278+
--header "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
279279
-f title='Created with the REST API' \
280280
-f body='This is a test issue created by the REST API' \
281281
```
@@ -332,7 +332,7 @@ The following example request uses the ["Get Octocat" endpoint](/rest/meta/meta#
332332
curl --request GET \
333333
--url "https://api.github.com/octocat" \
334334
--header "Accept: application/vnd.github+json" \
335-
--header "X-GitHub-Api-Version: 2022-11-28"
335+
--header "X-GitHub-Api-Version: {{ defaultRestApiVersion }}"
336336
```
337337

338338
#### Example request using query parameters
@@ -343,7 +343,7 @@ The ["List public events" endpoint](/rest/activity/events#list-public-events) re
343343
curl --request GET \
344344
--url "{% data variables.product.rest_url %}/events?per_page=2&page=1" \
345345
--header "Accept: application/vnd.github+json" \
346-
--header "X-GitHub-Api-Version: 2022-11-28" \
346+
--header "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
347347
https://api.github.com/events
348348
```
349349

@@ -359,7 +359,7 @@ curl \
359359
--request POST \
360360
--url "{% data variables.product.rest_url %}/repos/{% ifversion ghes %}REPO-OWNER/REPO-NAME{% else %}octocat/Spoon-Knife{% endif %}/issues" \
361361
--header "Accept: application/vnd.github+json" \
362-
--header "X-GitHub-Api-Version: 2022-11-28" \
362+
--header "X-GitHub-Api-Version: {{ defaultRestApiVersion }}" \
363363
--header "Authorization: Bearer YOUR-TOKEN" \
364364
--data '{
365365
"title": "Created with the REST API",

src/frame/middleware/context/context.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ export default async function contextualize(
8383
req.context.nonEnterpriseDefaultVersion = nonEnterpriseDefaultVersion
8484
req.context.initialRestVersioningReleaseDate =
8585
allVersions[nonEnterpriseDefaultVersion].apiVersions[0]
86+
// The default REST API version that requests use when no X-GitHub-Api-Version header is specified
87+
// This is the oldest supported version (last in the sorted descending array)
88+
const apiVersions = allVersions[nonEnterpriseDefaultVersion].apiVersions
89+
req.context.defaultRestApiVersion = apiVersions[apiVersions.length - 1]
8690

8791
const restDate = new Date(req.context.initialRestVersioningReleaseDate)
8892
req.context.initialRestVersioningReleaseDateLong = restDate.toUTCString().split(' 00:')[0]

src/types/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export type Context = {
156156
getDottedData?: (dottedPath: string) => unknown
157157
initialRestVersioningReleaseDate?: string
158158
initialRestVersioningReleaseDateLong?: string
159+
defaultRestApiVersion?: string
159160
nonEnterpriseDefaultVersion?: string
160161
enterpriseServerVersions?: string[]
161162
enterpriseServerReleases?: typeof enterpriseServerReleases

0 commit comments

Comments
 (0)