You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/github-cli/github-cli/quickstart.md
+2-21
Original file line number
Diff line number
Diff line change
@@ -19,26 +19,7 @@ shortTitle: Quickstart
19
19
20
20
## Prerequisites
21
21
22
-
1. Install {% data variables.product.prodname_cli %} on macOS, Windows, or Linux. For more information, see [Installation](https://github.com/cli/cli#installation) in the {% data variables.product.prodname_cli %} repository.
23
-
1. Authenticate with {% data variables.product.company_short %} by running this command from your terminal.{% ifversion ghes or ghae %} Replace `HOSTNAME` with the name of {% data variables.location.product_location %}. For example, `octo-inc.ghe.com`.{% endif %}
24
-
25
-
{%- ifversion fpt or ghec %}
26
-
27
-
```shell
28
-
gh auth login
29
-
```
30
-
31
-
{%- else %}
32
-
33
-
```shell
34
-
gh auth login --hostname HOSTNAME
35
-
```
36
-
37
-
{%- endif %}
38
-
39
-
1. Follow the on-screen prompts.
40
-
41
-
{% data variables.product.prodname_cli %} automatically stores your Git credentials for you when you choose HTTPS as your preferred protocol for Git operations and answer "yes" to the prompt asking if you would like to authenticate to Git with your {% data variables.product.prodname_dotcom %} credentials. This can be useful as it allows you to use `git push`, `git pull`, and so on, without needing to set up a separate credential manager or use SSH.
22
+
{% data reusables.rest-api.github-cli-install-and-auth %}
42
23
43
24
## Some useful commands
44
25
@@ -101,7 +82,7 @@ You can change configuration settings and add aliases or extensions, to make {%
101
82
- Enter `gh config set SUBCOMMANDS` to configure {% data variables.product.prodname_cli %}'s settings, replacing `SUBCOMMANDS` with the setting you want to adjust.
102
83
103
84
For example, you can specify the text editor that's used when a {% data variables.product.prodname_cli %} command requires you to edit text - such as when you add the body text for a new issue you're creating. To set your preferred text editor to {% data variables.product.prodname_vscode %} enter `gh config set editor "code -w"`. The `-w` (or `--wait`) flag in this example causes the command to wait for the file to be closed in {% data variables.product.prodname_vscode %} before proceeding with the next step in your terminal.
104
-
85
+
105
86
For more information, see [`gh config set`](https://cli.github.com/manual/gh_config_set).
106
87
107
88
- Define aliases for commands that you commonly run. For example, if you run `gh alias set prd "pr create --draft"`, you will then be able to run `gh prd` to quickly open a draft pull request. For more information, see [`gh alias`](https://cli.github.com/manual/gh_alias).
Copy file name to clipboardExpand all lines: content/rest/overview/authenticating-to-the-rest-api.md
+54-3
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,9 @@ shortTitle: Authenticating
18
18
19
19
Many REST API endpoints require authentication or return additional information if you are authenticated. Additionally, you can make more requests per hour when you are authenticated.
20
20
21
-
You can authenticate your request by sending a token in the `Authorization` header of your request. In the following example, replace `YOUR-TOKEN` with a reference to your token:
21
+
To authenticate your request, you will need to provide an authentication token with the required scopes or permissions. There a few different ways to get a token: You can create a {% data variables.product.pat_generic %}, generate a token with a {% data variables.product.prodname_github_app %}, or use the built-in `GITHUB_TOKEN` in a {% data variables.product.prodname_actions %} workflow.
22
+
23
+
After creating a token, you can authenticate your request by sending the token in the `Authorization` header of your request. For example, in the folllowing request, replace `YOUR-TOKEN` with a reference to your token:
22
24
23
25
```shell
24
26
curl --request GET \
@@ -33,7 +35,11 @@ curl --request GET \
33
35
34
36
{% endnote %}
35
37
36
-
If you try to use a REST API endpoint without a token or with a token that has insufficient permissions, you will receive a `404 Not Found` or `403 Forbidden` response.
38
+
### Failed login limit
39
+
40
+
If you try to use a REST API endpoint without a token or with a token that has insufficient permissions, you will receive a `404 Not Found` or `403 Forbidden` response. Authenticating with invalid credentials will initially return a `401 Unauthorized` response.
41
+
42
+
After detecting several requests with invalid credentials within a short period, the API will temporarily reject all authentication attempts for that user (including ones with valid credentials) with a `403 Forbidden` response. For more information, see "[AUTOTITLE](/rest/overview/rate-limits-for-the-rest-api)."
37
43
38
44
## Authenticating with a {% data variables.product.pat_generic %}
39
45
@@ -93,6 +99,50 @@ If you are the owner of a {% data variables.product.prodname_github_app %} or {%
93
99
94
100
If you want to use the API in a {% data variables.product.prodname_actions %} workflow, {% data variables.product.company_short %} recommends that you authenticate with the built-in `GITHUB_TOKEN` instead of creating a token. You can grant permissions to the `GITHUB_TOKEN` with the `permissions` key. For more information, see "[AUTOTITLE](/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token)."
95
101
102
+
If this is not possible, you can store your token as a secret and use the name of your secret in your {% data variables.product.prodname_actions %} workflow. For more information about secrets, see "[AUTOTITLE](/actions/security-guides/encrypted-secrets)."
103
+
104
+
### Authenticating in a {% data variables.product.prodname_actions %} workflow using {% data variables.product.prodname_cli %}
105
+
106
+
To make an authenticated request to the API in a {% data variables.product.prodname_actions %} workflow using {% data variables.product.prodname_cli %}, you can store the value of `GITHUB_TOKEN` as an environment variable, and use the `run` keyword to execute the {% data variables.product.prodname_cli %} `api` subcommand. For more information about the `run` keyword, see "[AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun)."
107
+
108
+
In the following example workflow, replace `PATH` with the path of the endpoint. For more information about the path, see "[AUTOTITLE](/rest/guides/getting-started-with-the-rest-api?tool=cli#path)."{% ifversion ghes or ghae %} Replace `HOSTNAME` with the name of {% data variables.location.product_location %}.{% endif %}
109
+
110
+
```yaml
111
+
jobs:
112
+
use_api:
113
+
runs-on: ubuntu-latest
114
+
permissions: {}
115
+
steps:
116
+
- env:
117
+
GH_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
118
+
run: |
119
+
gh api /PATH
120
+
```
121
+
122
+
### Authenticating in a {% data variables.product.prodname_actions %} workflow using `curl`
123
+
124
+
To make an authenticated request to the API in a {% data variables.product.prodname_actions %} workflow using `curl`, you can store the value of `GITHUB_TOKEN` as an environment variable, and use the `run` keyword to execute a `curl` request to the API. For more information about the `run` keyword, see "[AUTOTITLE](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun)."
125
+
126
+
In the following example workflow, replace `PATH` with the path of the endpoint. For more information about the path, see "[AUTOTITLE](/rest/guides/getting-started-with-the-rest-api?tool=cli#path)."{% ifversion ghes or ghae %} Replace `HOSTNAME` with the name of {% data variables.location.product_location %}.{% endif %}
127
+
128
+
```yaml copy
129
+
jobs:
130
+
use_api:
131
+
runs-on: ubuntu-latest
132
+
permissions: {}
133
+
steps:
134
+
- env:
135
+
GH_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %}
136
+
run: |
137
+
curl --request GET \
138
+
--url "{% data variables.product.api_url_code %}/PATH" \
139
+
--header "Authorization: Bearer $GH_TOKEN"
140
+
```
141
+
142
+
### Authenticating in a {% data variables.product.prodname_actions %} workflow using JavaScript
143
+
144
+
For an example of how to authenticate in a {% data variables.product.prodname_actions %} workflow using JavaScript, see "[AUTOTITLE](/rest/guides/scripting-with-the-rest-api-and-javascript#authenticating-in-github-actions)."
145
+
96
146
## Authenticating with username and password
97
147
98
148
{% ifversion ghes %}
@@ -114,4 +164,5 @@ Authentication with username and password is not supported. If you try to authen
Copy file name to clipboardExpand all lines: content/rest/overview/resources-in-the-rest-api.md
-204
Original file line number
Diff line number
Diff line change
@@ -12,167 +12,6 @@ topics:
12
12
- API
13
13
---
14
14
15
-
{% ifversion api-date-versioning %}
16
-
17
-
## API version
18
-
19
-
Available resources may vary between REST API versions. You should use the `X-GitHub-Api-Version` header to specify an API version. For more information, see "[AUTOTITLE](/rest/overview/api-versions)."
20
-
21
-
{% endif %}
22
-
23
-
## Schema
24
-
25
-
{% ifversion fpt or ghec %}All API access is over HTTPS, and{% else %}The API is{% endif %} accessed from `{% data variables.product.api_url_code %}`. All data is
26
-
sent and received as JSON.
27
-
28
-
```shell
29
-
$ curl -I {% data variables.product.api_url_pre %}/users/octocat/orgs
The documentation provides an example response for each API method. The example
83
-
response illustrates all attributes that are returned by that method.
84
-
85
-
## Authentication
86
-
87
-
{% data variables.product.company_short %} recommends that you create a token to authenticate to the REST API. For more information about which type of token to create, see "[AUTOTITLE](/rest/overview/authenticating-to-the-rest-api)."
88
-
89
-
You can authenticate your request by sending a token in the `Authorization` header of your request:
90
-
91
-
```shell
92
-
curl --request GET \
93
-
--url "{% data variables.product.api_url_code %}/octocat" \
**Note:** {% data reusables.getting-started.bearer-vs-token %}
101
-
102
-
{% endnote %}
103
-
104
-
If you try to use a REST API endpoint without a token or with a token that has insufficient permissions, you will receive a `404 Not Found` or `403 Forbidden` response.
105
-
106
-
{% ifversion fpt or ghes or ghec %}
107
-
108
-
### OAuth2 key/secret
109
-
110
-
{% data reusables.apps.deprecating_auth_with_query_parameters %}
111
-
112
-
```shell
113
-
curl -u my_client_id:my_client_secret '{% data variables.product.api_url_pre %}/user/repos'
114
-
```
115
-
116
-
Using your `client_id` and `client_secret` does _not_ authenticate as a user, it will only identify your {% data variables.product.prodname_oauth_app %} to increase your rate limit. Permissions are only granted to users, not applications, and you will only get back data that an unauthenticated user would see. Don't leak your {% data variables.product.prodname_oauth_app %}'s client secret to your users.
117
-
118
-
{% ifversion ghes %}
119
-
You will be unable to authenticate using your OAuth2 key and secret while in private mode, and trying to authenticate will return `401 Unauthorized`. For more information, see "[AUTOTITLE](/admin/configuration/configuring-your-enterprise/enabling-private-mode)".
120
-
{% endif %}
121
-
{% endif %}
122
-
123
-
{% ifversion fpt or ghec %}
124
-
125
-
For more information about rate limits for {% data variables.product.prodname_oauth_apps %}, see "[AUTOTITLE](/rest/overview/rate-limits-for-the-rest-api)."
126
-
127
-
{% endif %}
128
-
129
-
### Failed login limit
130
-
131
-
Authenticating with invalid credentials will return `401 Unauthorized`:
You can issue a `GET` request to the root endpoint to get all the endpoint categories that the REST API supports:
@@ -186,20 +25,6 @@ $ curl {% ifversion fpt or ghae or ghec %}
186
25
187
26
See the guide on "[AUTOTITLE](/graphql/guides/using-global-node-ids)" for detailed information about how to find `node_id`s via the REST API and use them in GraphQL operations.
188
27
189
-
## HTTP verbs
190
-
191
-
Where possible, the {% data variables.product.product_name %} REST API strives to use appropriate HTTP verbs for each
192
-
action. Note that HTTP verbs are case-sensitive.
193
-
194
-
Verb | Description
195
-
-----|-----------
196
-
`HEAD`| Can be issued against any resource to get just the HTTP header info.
197
-
`GET`| Used for retrieving resources.
198
-
`POST`| Used for creating resources.
199
-
`PATCH`| Used for updating resources with partial JSON data. For instance, an Issue resource has `title` and `body` attributes. A `PATCH` request may accept one or more of the attributes to update the resource.
200
-
`PUT`| Used for replacing resources or collections. For `PUT` requests with no `body` attribute, be sure to set the `Content-Length` header to zero.
201
-
`DELETE`|Used for deleting resources.
202
-
203
28
## Hypermedia
204
29
205
30
All resources may have one or more `*_url` properties linking to other
@@ -221,35 +46,6 @@ gem:
221
46
>> tmpl.expand all: 1, participating: 1
222
47
=> "/notifications?all=1&participating=1"
223
48
224
-
{% ifversion fpt or ghec %}
225
-
226
-
## User agent required
227
-
228
-
All API requests MUST include a valid `User-Agent` header. Requests with no `User-Agent`
229
-
header will be rejected. We request that you use your {% data variables.product.product_name %} username, or the name of your
230
-
application, for the `User-Agent` header value. This allows us to contact you if there are problems.
231
-
232
-
Here's an example:
233
-
234
-
```shell
235
-
User-Agent: Awesome-Octocat-App
236
-
```
237
-
238
-
curl sends a valid `User-Agent` header by default. If you provide an invalid `User-Agent` header via curl (or via an alternative client), you will receive a `403 Forbidden` response:
239
-
240
-
```shell
241
-
$ curl -IH 'User-Agent: ' {% data variables.product.api_url_pre %}/meta
242
-
> HTTP/1.0 403 Forbidden
243
-
> Connection: close
244
-
> Content-Type: text/html
245
-
246
-
> Request forbidden by administrative rules.
247
-
> Please make sure your request has a User-Agent header.
248
-
> Check for other possible causes.
249
-
```
250
-
251
-
{% endif %}
252
-
253
49
## Cross origin resource sharing
254
50
255
51
The API supports Cross Origin Resource Sharing (CORS) for AJAX requests from
0 commit comments