Combine product name variables for REST and GraphQL API base URLs (#50521)
This commit is contained in:
@@ -75,13 +75,13 @@ Most endpoints return an `etag` header, and many endpoints return a `last-modifi
|
||||
For example, if a previous request returned an `etag` header value of `644b5b0155e6404a9cc4bd9d8b1ae730`, you can use the `if-none-match` header in a future request:
|
||||
|
||||
```shell
|
||||
curl {% data variables.product.api_url_pre %}/meta --include --header 'if-none-match: "644b5b0155e6404a9cc4bd9d8b1ae730"'
|
||||
curl {% data variables.product.rest_url %}/meta --include --header 'if-none-match: "644b5b0155e6404a9cc4bd9d8b1ae730"'
|
||||
```
|
||||
|
||||
For example, if a previous request returned a `last-modified` header value of `Wed, 25 Oct 2023 19:17:59 GMT`, you can use the `if-modified-since` header in a future request:
|
||||
|
||||
```shell
|
||||
curl {% data variables.product.api_url_pre %}/repos/github/docs --include --header 'if-modified-since: Wed, 25 Oct 2023 19:17:59 GMT'
|
||||
curl {% data variables.product.rest_url %}/repos/github/docs --include --header 'if-modified-since: Wed, 25 Oct 2023 19:17:59 GMT'
|
||||
```
|
||||
|
||||
## Do not ignore errors
|
||||
|
||||
@@ -313,7 +313,7 @@ Use the `curl` command to make your request. For more information, see [the curl
|
||||
Specify the following options and values in your request:
|
||||
|
||||
- **`--request` or `-X`** followed by the HTTP method as the value. For more information, see "[HTTP method](#http-method)."
|
||||
- **`--url`** followed by the full path as the value. The full path is a URL that includes the base URL for the GitHub REST API (`https://api.github.com`) and the path of the endpoint, like this: `{% data variables.product.api_url_code %}/PATH`.{% ifversion ghes %} Replace `HOSTNAME` with the name of {% data variables.location.product_location %}.{% endif %} Replace `PATH` with the path of the endpoint. For more information, see "[Path](#path)."
|
||||
- **`--url`** followed by the full path as the value. The full path is a URL that includes the base URL for the GitHub REST API (`https://api.github.com`) and the path of the endpoint, like this: `{% data variables.product.rest_url %}/PATH`.{% ifversion ghes %} Replace `HOSTNAME` with the name of {% data variables.location.product_location %}.{% endif %} Replace `PATH` with the path of the endpoint. For more information, see "[Path](#path)."
|
||||
|
||||
To use query parameters, add a `?` to the end of the path, then append your query parameter name and value in the form `parameter_name=value`. Separate multiple query parameters with `&`. If you need to send an array in the query string, use the query parameter once per array item, and append `[]` after the query parameter name. For example, to provide an array of two repository IDs, use `?repository_ids[]=REPOSITORY_A_ID&repository_ids[]=REPOSITORY_B_ID`. For more information, see "[Query parameters](#query-parameters)." For an example, see "[Example request using query parameters](#example-request-using-query-parameters-1)."
|
||||
- **`--header` or `-H`**:
|
||||
@@ -339,7 +339,7 @@ The ["List public events" endpoint](/rest/activity/events#list-public-events) re
|
||||
|
||||
```shell copy
|
||||
curl --request GET \
|
||||
--url "{% data variables.product.api_url_code %}/events?per_page=2&page=1" \
|
||||
--url "{% data variables.product.rest_url %}/events?per_page=2&page=1" \
|
||||
--header "Accept: application/vnd.github+json" \
|
||||
--header "X-GitHub-Api-Version: 2022-11-28" \
|
||||
https://api.github.com/events
|
||||
@@ -362,7 +362,7 @@ The following example uses the "[Create an issue](/rest/issues/issues#create-an-
|
||||
```shell copy
|
||||
curl \
|
||||
--request POST \
|
||||
--url "{% data variables.product.api_url_code %}/repos/{% ifversion ghes %}REPO-OWNER/REPO-NAME{% else %}octocat/Spoon-Knife{% endif %}/issues" \
|
||||
--url "{% data variables.product.rest_url %}/repos/{% ifversion ghes %}REPO-OWNER/REPO-NAME{% else %}octocat/Spoon-Knife{% endif %}/issues" \
|
||||
--header "Accept: application/vnd.github+json" \
|
||||
--header "X-GitHub-Api-Version: 2022-11-28" \
|
||||
--header "Authorization: Bearer YOUR-TOKEN" \
|
||||
@@ -402,11 +402,11 @@ Create an access token to authenticate your request. You can save your token and
|
||||
### 4. Make a request with Octokit.js
|
||||
|
||||
1. Import `octokit` in your script. For example, `import { Octokit } from "octokit";`. For other ways to import `octokit`, see [the Octokit.js README](https://github.com/octokit/octokit.js/#readme).
|
||||
1. Create an instance of `Octokit` with your token.{% ifversion ghes %} Set the base URL to `{% data variables.product.api_url_code %}`. Replace `HOSTNAME` with the name of {% data variables.location.product_location %}.{% endif %} Replace `YOUR-TOKEN` with your token.
|
||||
1. Create an instance of `Octokit` with your token.{% ifversion ghes %} Set the base URL to `{% data variables.product.rest_url %}`. Replace `HOSTNAME` with the name of {% data variables.location.product_location %}.{% endif %} Replace `YOUR-TOKEN` with your token.
|
||||
|
||||
```javascript copy
|
||||
const octokit = new Octokit({ {% ifversion ghes %}
|
||||
baseUrl: "{% data variables.product.api_url_code %}",{% endif %}
|
||||
baseUrl: "{% data variables.product.rest_url %}",{% endif %}
|
||||
auth: 'YOUR-TOKEN'
|
||||
});
|
||||
```
|
||||
@@ -653,7 +653,7 @@ For example, you can use `>` to redirect the response to a file. In the followin
|
||||
|
||||
```shell copy
|
||||
curl --request GET \
|
||||
--url "{% data variables.product.api_url_code %}/repos/REPO-OWNER/REPO-NAME/issues?per_page=2" \
|
||||
--url "{% data variables.product.rest_url %}/repos/REPO-OWNER/REPO-NAME/issues?per_page=2" \
|
||||
--header "Accept: application/vnd.github+json" \
|
||||
--header "Authorization: Bearer YOUR-TOKEN" > data.json
|
||||
```
|
||||
|
||||
@@ -57,7 +57,7 @@ Primary rate limits for OAuth access tokens generated by a {% data variables.pro
|
||||
OAuth apps can also use their client ID and client secret to fetch public data. For example:
|
||||
|
||||
```shell
|
||||
curl -u YOUR_CLIENT_ID:YOUR_CLIENT_SECRET -I {% data variables.product.api_url_pre %}/meta
|
||||
curl -u YOUR_CLIENT_ID:YOUR_CLIENT_SECRET -I {% data variables.product.rest_url %}/meta
|
||||
```
|
||||
|
||||
For these requests, the rate limit is 5,000 requests per hour per {% data variables.product.prodname_oauth_app %}. If the app is owned by a {% data variables.product.prodname_ghe_cloud %} organization, the rate limit is 15,000 requests per hour.
|
||||
|
||||
@@ -34,7 +34,7 @@ An example of this is the API to manage commits. For more information, see "[AUT
|
||||
It is possible to supply a `Time-Zone` header, which defines a timezone according to the [list of names from the Olson database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
||||
|
||||
```shell
|
||||
curl -H "Time-Zone: Europe/Amsterdam" -X POST {% data variables.product.api_url_pre %}/repos/github-linguist/linguist/contents/new_file.md
|
||||
curl -H "Time-Zone: Europe/Amsterdam" -X POST {% data variables.product.rest_url %}/repos/github-linguist/linguist/contents/new_file.md
|
||||
```
|
||||
|
||||
This means that we generate a timestamp for the moment your API call is made, in the timezone this header defines.
|
||||
|
||||
@@ -22,7 +22,7 @@ Here's a sample request sent from a browser hitting
|
||||
`http://example.com`:
|
||||
|
||||
```shell
|
||||
$ curl -I {% data variables.product.api_url_pre %} -H "Origin: http://example.com"
|
||||
$ curl -I {% data variables.product.rest_url %} -H "Origin: http://example.com"
|
||||
HTTP/2 302
|
||||
Access-Control-Allow-Origin: *
|
||||
Access-Control-Expose-Headers: ETag, Link, x-ratelimit-limit, x-ratelimit-remaining, x-ratelimit-reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
|
||||
@@ -31,7 +31,7 @@ Access-Control-Expose-Headers: ETag, Link, x-ratelimit-limit, x-ratelimit-remain
|
||||
This is what the CORS preflight request looks like:
|
||||
|
||||
```shell
|
||||
$ curl -I {% data variables.product.api_url_pre %} -H "Origin: http://example.com" -X OPTIONS
|
||||
$ curl -I {% data variables.product.rest_url %} -H "Origin: http://example.com" -X OPTIONS
|
||||
HTTP/2 204
|
||||
Access-Control-Allow-Origin: *
|
||||
Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With
|
||||
@@ -46,7 +46,7 @@ You can send a `?callback` parameter to any GET call to have the results
|
||||
wrapped in a JSON function. This is typically used when browsers want to embed {% data variables.product.product_name %} content in web pages and avoid cross-domain problems. The response includes the same data output as the regular API, plus the relevant HTTP Header information.
|
||||
|
||||
```shell
|
||||
$ curl {% data variables.product.api_url_pre %}?callback=foo
|
||||
$ curl {% data variables.product.rest_url %}?callback=foo
|
||||
|
||||
> /**/foo({
|
||||
> "meta": {
|
||||
@@ -55,7 +55,7 @@ $ curl {% data variables.product.api_url_pre %}?callback=foo
|
||||
> "x-ratelimit-remaining": "4966",
|
||||
> "x-ratelimit-reset": "1372700873",
|
||||
> "Link": [ // pagination headers and other links
|
||||
> ["{% data variables.product.api_url_pre %}?page=2", {"rel": "next"}]
|
||||
> ["{% data variables.product.rest_url %}?page=2", {"rel": "next"}]
|
||||
> ]
|
||||
> },
|
||||
> "data": {
|
||||
@@ -78,7 +78,7 @@ function foo(response) {
|
||||
}
|
||||
|
||||
var script = document.createElement('script');
|
||||
script.src = '{% data variables.product.api_url_code %}?callback=foo';
|
||||
script.src = '{% data variables.product.rest_url %}?callback=foo';
|
||||
|
||||
document.getElementsByTagName('head')[0].appendChild(script);
|
||||
</script>
|
||||
|
||||
@@ -96,7 +96,7 @@ For example, this script gets all of the issues from the `octocat/Spoon-Knife` r
|
||||
import { Octokit } from "octokit";
|
||||
|
||||
const octokit = new Octokit({ {% ifversion ghes %}
|
||||
baseUrl: "{% data variables.product.api_url_code %}",
|
||||
baseUrl: "{% data variables.product.rest_url %}",
|
||||
{% endif %}});
|
||||
|
||||
const data = await octokit.paginate("GET /repos/{owner}/{repo}/issues", {
|
||||
@@ -123,7 +123,7 @@ The `getPaginatedData` function makes a request to an endpoint with `octokit.req
|
||||
import { Octokit } from "octokit";
|
||||
|
||||
const octokit = new Octokit({ {% ifversion ghes %}
|
||||
baseUrl: "{% data variables.product.api_url_code %}",
|
||||
baseUrl: "{% data variables.product.rest_url %}",
|
||||
{% endif %}});
|
||||
|
||||
async function getPaginatedData(url) {
|
||||
|
||||
Reference in New Issue
Block a user