Skip to content

Commit

Permalink
Combine product name variables for REST and GraphQL API base URLs (#5…
Browse files Browse the repository at this point in the history
…0521)
  • Loading branch information
lecoursen authored May 10, 2024
1 parent aef6bc2 commit e977bce
Show file tree
Hide file tree
Showing 40 changed files with 99 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Once a workflow reaches a job that references an environment that has the custom

```shell
curl --request POST \
--url "{% data variables.product.api_url_code %}/app/installations/INSTALLATION_ID/ACCESS_TOKENS" \
--url "{% data variables.product.rest_url %}/app/installations/INSTALLATION_ID/ACCESS_TOKENS" \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer {jwt}" \
--header "Content-Type: application/json" \
Expand Down
4 changes: 2 additions & 2 deletions content/actions/learn-github-actions/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ We strongly recommend that actions use variables to access the filesystem rather
{%- ifversion actions-oidc-custom-claims %}
| `GITHUB_ACTOR_ID` | {% data reusables.actions.actor_id-description %} |
{%- endif %}
| `GITHUB_API_URL` | Returns the API URL. For example: `{% data variables.product.api_url_code %}`.
| `GITHUB_API_URL` | Returns the API URL. For example: `{% data variables.product.rest_url %}`.
| `GITHUB_BASE_REF` | The name of the base ref or target branch of the pull request in a workflow run. This is only set when the event that triggers a workflow run is either `pull_request` or `pull_request_target`. For example, `main`. |
| `GITHUB_ENV` | The path on the runner to the file that sets variables from workflow commands. The path to this file is unique to the current step and changes for each step in a job. For example, `/home/runner/work/_temp/_runner_file_commands/set_env_87406d6e-4979-4d42-98e1-3dab1f48b13a`. For more information, see "[AUTOTITLE](/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable)." |
| `GITHUB_EVENT_NAME` | The name of the event that triggered the workflow. For example, `workflow_dispatch`. |
| `GITHUB_EVENT_PATH` | The path to the file on the runner that contains the full event webhook payload. For example, `/github/workflow/event.json`. |
| `GITHUB_GRAPHQL_URL` | Returns the GraphQL API URL. For example: `{% data variables.product.graphql_url_code %}`.
| `GITHUB_GRAPHQL_URL` | Returns the GraphQL API URL. For example: `{% data variables.product.graphql_url %}`.
| `GITHUB_HEAD_REF` | The head ref or source branch of the pull request in a workflow run. This property is only set when the event that triggers a workflow run is either `pull_request` or `pull_request_target`. For example, `feature-branch-1`. |
| `GITHUB_JOB` | The [job_id](/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_id) of the current job. For example, `greeting_job`. |
| `GITHUB_OUTPUT` | The path on the runner to the file that sets the current step's outputs from workflow commands. The path to this file is unique to the current step and changes for each step in a job. For example, `/home/runner/work/_temp/_runner_file_commands/set_output_a50ef383-b063-46d9-9157-57953fc9f3f0`. For more information, see "[AUTOTITLE](/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter)." |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
- name: Create issue using REST API
run: |
curl --request POST \
--url {% data variables.product.api_url_code %}/repos/${% raw %}{{ github.repository }}{% endraw %}/issues \
--url {% data variables.product.rest_url %}/repos/${% raw %}{{ github.repository }}{% endraw %}/issues \
--header 'authorization: Bearer ${% raw %}{{ secrets.GITHUB_TOKEN }}{% endraw %}' \
--header 'content-type: application/json' \
--data '{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The query below searches for audit log events created on Jan 1st, 2022 in the `a
```shell
curl -H "Authorization: Bearer TOKEN" \
--request GET \
"{% data variables.product.api_url_code %}/enterprises/avocado-corp/audit-log?phrase=created:2022-01-01&page=1&per_page=100"
"{% data variables.product.rest_url %}/enterprises/avocado-corp/audit-log?phrase=created:2022-01-01&page=1&per_page=100"
```

{% else %}
Expand All @@ -59,23 +59,23 @@ The query below searches for audit log events created on Jan 1st, 2022 in the `a
```shell
curl --include -H "Authorization: Bearer TOKEN" \
--request GET \
"{% data variables.product.api_url_code %}/enterprises/avocado-corp/audit-log?phrase=created:2022-01-01&per_page=100"
"{% data variables.product.rest_url %}/enterprises/avocado-corp/audit-log?phrase=created:2022-01-01&per_page=100"
```

If there are more than 100 results, the `link` header will include URLs to fetch the next, first, and previous pages of results.

```text
link: <{% data variables.product.api_url_code %}/enterprises/13827/audit-log?%3A2022-11-01=&per_page=100&after=MS42NjQzODMzNTk5MjdlKzEyfDloQzBxdURzaFdVbVlLWjkxRU9mNXc%3D&before=>; rel="next",
<{% data variables.product.api_url_code %}/enterprises/13827/audit-log?%3A2022-11-01=&per_page=100&after=&before=>; rel="first",
<{% data variables.product.api_url_code %}/enterprises/13827/audit-log?%3A2022-11-01=&per_page=100&after=&before=MS42Njc4NDA2MjM4MzNlKzEyfExqeG5sUElvNEZMbG1XZHA5akdKTVE%3D>; rel="prev"
link: <{% data variables.product.rest_url %}/enterprises/13827/audit-log?%3A2022-11-01=&per_page=100&after=MS42NjQzODMzNTk5MjdlKzEyfDloQzBxdURzaFdVbVlLWjkxRU9mNXc%3D&before=>; rel="next",
<{% data variables.product.rest_url %}/enterprises/13827/audit-log?%3A2022-11-01=&per_page=100&after=&before=>; rel="first",
<{% data variables.product.rest_url %}/enterprises/13827/audit-log?%3A2022-11-01=&per_page=100&after=&before=MS42Njc4NDA2MjM4MzNlKzEyfExqeG5sUElvNEZMbG1XZHA5akdKTVE%3D>; rel="prev"
```

Copy the corresponding pagination link into your next request. For example:

```shell
curl -I -H "Authorization: Bearer TOKEN" \
--request GET \
"{% data variables.product.api_url_code %}/enterprises/13827/audit-log?%3A2022-11-01=&per_page=100&after=MS42Njc4NDA2MjM5NDFlKzEyfHRYa3AwSkxUd2xyRjA5bWxfOS1RbFE%3D&before="
"{% data variables.product.rest_url %}/enterprises/13827/audit-log?%3A2022-11-01=&per_page=100&after=MS42Njc4NDA2MjM5NDFlKzEyfHRYa3AwSkxUd2xyRjA5bWxfOS1RbFE%3D&before="
```

{% endif %}
Expand All @@ -89,7 +89,7 @@ The query below searches for audit log events for pull requests, where the event
```shell
curl -H "Authorization: Bearer TOKEN" \
--request GET \
"{% data variables.product.api_url_code %}/enterprises/avocado-corp/audit-log?phrase=action:pull_request+created:>=2022-01-01+actor:octocat"
"{% data variables.product.rest_url %}/enterprises/avocado-corp/audit-log?phrase=action:pull_request+created:>=2022-01-01+actor:octocat"
```

## Example 3: Events for Git activity in an enterprise, for a specific date and actor
Expand All @@ -101,5 +101,5 @@ The query below searches for audit log events for Git activity, where the event
```shell
curl -H "Authorization: Bearer TOKEN" \
--request GET \
"{% data variables.product.api_url_code %}/enterprises/avocado-corp/audit-log?phrase=created:>=2024-01-01+actor:octocat&include=git"
"{% data variables.product.rest_url %}/enterprises/avocado-corp/audit-log?phrase=created:>=2024-01-01+actor:octocat&include=git"
```
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ In the following example, replace `INSTALLATION_ACCESS_TOKEN` with an installati

```shell
curl --request GET \
--url "{% data variables.product.api_url_pre %}/meta" \
--url "{% data variables.product.rest_url %}/meta" \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer INSTALLATION_ACCESS_TOKEN" \
--header "X-GitHub-Api-Version: {{ allVersions[currentVersion].latestApiVersion }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If a REST API endpoint requires you to authenticate as an app, the documentation

```shell
curl --request GET \
--url "{% data variables.product.api_url_pre %}/app/installations" \
--url "{% data variables.product.rest_url %}/app/installations" \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer YOUR_JWT" \
--header "X-GitHub-Api-Version: {{ allVersions[currentVersion].latestApiVersion }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To use a JWT, pass it in the `Authorization` header of an API request. For examp

```shell
curl --request GET \
--url "{% data variables.product.api_url_pre %}/app" \
--url "{% data variables.product.rest_url %}/app" \
--header "Accept: application/vnd.github+json" \
--header "Authorization: Bearer YOUR_JWT" \
--header "X-GitHub-Api-Version: {{ allVersions[currentVersion].latestApiVersion }}"
Expand Down Expand Up @@ -128,7 +128,7 @@ payload = {
# {% data variables.product.prodname_github_app %}'s client ID
'iss': client_id{% else %}
# {% data variables.product.prodname_github_app %}'s app ID
'iss': app_id{% endif %}
'iss': app_id{% endif %}
}

# Create JWT
Expand Down Expand Up @@ -156,7 +156,7 @@ set -o pipefail
client_id=$1 # Client ID as first argument
{% else %}
app_id=$1 # App ID as first argument
{% endif %}
{% endif %}
pem=$( cat $2 ) # file path of the private key as second argument

now=$(date +%s)
Expand All @@ -175,7 +175,7 @@ header=$( echo -n "${header_json}" | b64enc )
payload_json='{
"iat":'"${iat}"',
"exp":'"${exp}"',
{% ifversion client-id-for-app %}"iss":'"${client_id}"'{% else %}"iss":'"${client_id}"'{% endif %}
{% ifversion client-id-for-app %}"iss":'"${client_id}"'{% else %}"iss":'"${client_id}"'{% endif %}
}'
# Payload encode
payload=$( echo -n "${payload_json}" | b64enc )
Expand Down Expand Up @@ -203,7 +203,7 @@ In the following example, replace `YOUR_PATH_TO_PEM` with the file path where yo
$client_id = YOUR_CLIENT_ID
{% else %}
$app_id = YOUR_APP_ID
{% endif %}
{% endif %}
$private_key_path = "YOUR_PATH_TO_PEM"

$header = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes((ConvertTo-Json -InputObject @{
Expand All @@ -214,7 +214,7 @@ $header = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes((Conve
$payload = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes((ConvertTo-Json -InputObject @{
iat = [System.DateTimeOffset]::UtcNow.AddSeconds(-10).ToUnixTimeSeconds()
exp = [System.DateTimeOffset]::UtcNow.AddMinutes(10).ToUnixTimeSeconds()
{% ifversion client-id-for-app %} iss = $client_id{% else %} iss = $app_id{% endif %}
{% ifversion client-id-for-app %} iss = $client_id{% else %} iss = $app_id{% endif %}
}))).TrimEnd('=').Replace('+', '-').Replace('/', '_');

$rsa = [System.Security.Cryptography.RSA]::Create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ Now that your app can generate a user access token, you can make API requests on

```ruby copy
def whoami
uri = URI("{% data variables.product.api_url_code %}/user")
uri = URI("{% data variables.product.rest_url %}/user")
begin
token = File.read("./.token").strip
Expand Down Expand Up @@ -675,7 +675,7 @@ This is the full code example that was outlined in the previous section. Replace
end
def whoami
uri = URI("{% data variables.product.api_url_code %}/user")
uri = URI("{% data variables.product.rest_url %}/user")
begin
token = File.read("./.token").strip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ These steps lead you through writing code to generate a user access token. To sk

```ruby copy
def user_info(token)
uri = URI("{% data variables.product.api_url_code %}/user")
uri = URI("{% data variables.product.rest_url %}/user")

result = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
body = {"access_token" => token}.to_json
Expand Down Expand Up @@ -332,7 +332,7 @@ def exchange_code(code)
end

def user_info(token)
uri = URI("{% data variables.product.api_url_code %}/user")
uri = URI("{% data variables.product.rest_url %}/user")

result = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
body = {"access_token" => token}.to_json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ the logged in user:

``` ruby
# fetch user information
auth_result = JSON.parse(RestClient.get('{% data variables.product.api_url_code %}/user',
auth_result = JSON.parse(RestClient.get('{% data variables.product.rest_url %}/user',
{:params => {:access_token => access_token}}))

# if the user authorized it, fetch private emails
if has_user_email_scope
auth_result['private_emails'] =
JSON.parse(RestClient.get('{% data variables.product.api_url_code %}/user/emails',
JSON.parse(RestClient.get('{% data variables.product.rest_url %}/user/emails',
{:params => {:access_token => access_token}}))
end

Expand Down Expand Up @@ -271,7 +271,7 @@ get '/' do
scopes = []

begin
auth_result = RestClient.get('{% data variables.product.api_url_code %}/user',
auth_result = RestClient.get('{% data variables.product.rest_url %}/user',
{:params => {:access_token => access_token},
:accept => :json})
rescue => e
Expand All @@ -292,7 +292,7 @@ get '/' do

if scopes.include? 'user:email'
auth_result['private_emails'] =
JSON.parse(RestClient.get('{% data variables.product.api_url_code %}/user/emails',
JSON.parse(RestClient.get('{% data variables.product.rest_url %}/user/emails',
{:params => {:access_token => access_token},
:accept => :json}))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ Accept: application/xml
The access token allows you to make requests to the API on a behalf of a user.

Authorization: Bearer OAUTH-TOKEN
GET {% data variables.product.api_url_code %}/user
GET {% data variables.product.rest_url %}/user

For example, in curl you can set the Authorization header like this:

```shell
curl -H "Authorization: Bearer OAUTH-TOKEN" {% data variables.product.api_url_pre %}/user
curl -H "Authorization: Bearer OAUTH-TOKEN" {% data variables.product.rest_url %}/user
```

## Device flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ If your {% data variables.product.prodname_oauth_app %} doesn't have access to a
Check headers to see what OAuth scopes you have, and what the API action accepts:

```shell
$ curl -H "Authorization: Bearer OAUTH-TOKEN" {% data variables.product.api_url_pre %}/users/codertocat -I
$ curl -H "Authorization: Bearer OAUTH-TOKEN" {% data variables.product.rest_url %}/users/codertocat -I
HTTP/2 200
X-OAuth-Scopes: repo, user
X-Accepted-OAuth-Scopes: user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ redirect_from:
| `GIT_COMMITTER_EMAIL` | The email for the "author" field of future `git` commits. |
| `GIT_COMMITTER_NAME` | The name for the "committer" field of future `git` commits. |
| `GITHUB_CODESPACES_PORT_FORWARDING_DOMAIN`| Returns the domain of the {% data variables.product.prodname_github_codespaces %} forwarded port. For example, `app.github.dev`. |
| `GITHUB_API_URL` | Returns the API URL. For example, `{% data variables.product.api_url_code %}`. |
| `GITHUB_GRAPHQL_URL` | Returns the GraphQL API URL. For example, `{% data variables.product.graphql_url_code %}`. |
| `GITHUB_API_URL` | Returns the API URL. For example, `{% data variables.product.rest_url %}`. |
| `GITHUB_GRAPHQL_URL` | Returns the GraphQL API URL. For example, `{% data variables.product.graphql_url %}`. |
| `GITHUB_REPOSITORY` | The owner and repository name. For example, `octocat/Hello-World`. |
| `GITHUB_SERVER_URL`| Returns the URL of the {% data variables.product.product_name %} server. For example, `https://{% data variables.product.product_url %}`. |
| `GITHUB_TOKEN` | A signed auth token representing the user in the codespace. You can use this to make authenticated calls to the GitHub API. For more information, see "[AUTOTITLE](/codespaces/reference/security-in-github-codespaces#authentication)." |
Expand Down
4 changes: 2 additions & 2 deletions content/graphql/guides/forming-calls-with-graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ To authenticate with an OAuth token from an {% data variables.product.prodname_o

The REST API has numerous endpoints; the GraphQL API has a single endpoint:

<pre>{% data variables.product.graphql_url_pre %}</pre>
<pre>{% data variables.product.graphql_url %}</pre>

The endpoint remains constant no matter what operation you perform.

Expand All @@ -61,7 +61,7 @@ curl -H "Authorization: bearer TOKEN" -X POST -d " \
{ \
\"query\": \"query { viewer { login }}\" \
} \
" {% data variables.product.graphql_url_code %}
" {% data variables.product.graphql_url %}
```

{% tip %}
Expand Down
4 changes: 2 additions & 2 deletions content/graphql/guides/introduction-to-graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ GraphQL is [introspective](https://graphql.org/learn/introspection/). This means
- You can also run an _introspection query_ of the schema via a `GET` request:

```shell
curl -H "Authorization: bearer TOKEN" {% data variables.product.graphql_url_pre %}
curl -H "Authorization: bearer TOKEN" {% data variables.product.graphql_url %}
```

{% note %}
Expand All @@ -130,7 +130,7 @@ GraphQL is [introspective](https://graphql.org/learn/introspection/). This means

```shell
$ curl -H "Authorization: bearer TOKEN" -H "Accept: application/vnd.github.v4.idl" \
{% data variables.product.graphql_url_pre %}
{% data variables.product.graphql_url %}
```

{% note %}
Expand Down
14 changes: 7 additions & 7 deletions content/graphql/guides/migrating-from-rest-to-graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Here are examples of each.
A single REST API call retrieves a list of your organization's members:

```shell
curl -v {% data variables.product.api_url_pre %}/orgs/:org/members
curl -v {% data variables.product.rest_url %}/orgs/:org/members
```

The REST payload contains excessive data if your goal is to retrieve only member names and links to avatars. However, a GraphQL query returns only what you specify:
Expand All @@ -62,13 +62,13 @@ query {
Consider another example: retrieving a list of pull requests and checking if each one is mergeable. A call to the REST API retrieves a list of pull requests and their [summary representations](/rest#summary-representations):

```shell
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/pulls
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/pulls
```

Determining if a pull request is mergeable requires retrieving each pull request individually for its [detailed representation](/rest#detailed-representations) (a large payload) and checking whether its `mergeable` attribute is true or false:

```shell
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/pulls/:number
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/pulls/:number
```

With GraphQL, you could retrieve only the `number` and `mergeable` attributes for each pull request:
Expand All @@ -93,10 +93,10 @@ query {
Querying with nested fields lets you replace multiple REST calls with fewer GraphQL queries. For example, retrieving a pull request along with its commits, non-review comments, and reviews using the **REST API** requires four separate calls:

```shell
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/pulls/:number
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/pulls/:number/commits
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/issues/:number/comments
curl -v {% data variables.product.api_url_pre %}/repos/:owner/:repo/pulls/:number/reviews
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/pulls/:number
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/pulls/:number/commits
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/issues/:number/comments
curl -v {% data variables.product.rest_url %}/repos/:owner/:repo/pulls/:number/reviews
```

Using the **GraphQL API**, you can retrieve the data with a single query using nested fields:
Expand Down
2 changes: 1 addition & 1 deletion content/graphql/guides/using-global-node-ids.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Let's walk through an example.
If you [request the authenticated user](/rest/users/users#get-the-authenticated-user):

```shell
curl -i --header "Authorization: Bearer YOUR-TOKEN" {% data variables.product.api_url_pre %}/user
curl -i --header "Authorization: Bearer YOUR-TOKEN" {% data variables.product.rest_url %}/user
```

you'll get a response that includes the `node_id` of the authenticated user:
Expand Down
Loading

0 comments on commit e977bce

Please sign in to comment.