|
| 1 | +:_content-type: REFERENCE |
| 2 | +[id="using-the-api"] |
| 3 | += Using the {productname} API |
| 4 | + |
| 5 | +After you have created an application and generated an OAuth 2 access token with the desired settings, you can pass in the access token to `GET`, `PUT`, `POST`, or `DELETE` settings by using the API from the CLI. Generally, a {productname} API command looks similar to the following example: |
| 6 | + |
| 7 | +[source,terminal] |
| 8 | +---- |
| 9 | +$ curl -X GET -H "Authorization: Bearer <your_access_token>" <1> |
| 10 | + https://<quay-server.example.com>/api/v1/<example>/<endpoint>/ <2> |
| 11 | +---- |
| 12 | +<1> The OAuth 2 access token that was generated through the {productname} UI. |
| 13 | +<2> The URL of your {productname} deployment and the desired API endpoint. |
| 14 | + |
| 15 | +All {productname} APIs are documented in the link:https://docs.redhat.com/en/documentation/red_hat_quay/{productname}/html-single/red_hat_quay_api_guide/index#red_hat_quay_application_programming_interface_api[{productname} Application Programming Interface (API)] chapter. Understanding how they are documented is crucial to successful invocation. Take, for example, the following entry for the `createAppToken` API endpoint: |
| 16 | + |
| 17 | +[source,text] |
| 18 | +---- |
| 19 | +*createAppToken* <1> |
| 20 | +Create a new app specific token for user. <2> |
| 21 | +
|
| 22 | +*POST /api/v1/user/apptoken* <3> |
| 23 | +
|
| 24 | +**Authorizations: **oauth2_implicit (**user:admin**) <4> |
| 25 | +
|
| 26 | + Request body schema (application/json) |
| 27 | +
|
| 28 | +*Path parameters* <5> |
| 29 | +
|
| 30 | +Name: **title** |
| 31 | +Description: Friendly name to help identify the token. |
| 32 | +Schema: string |
| 33 | +
|
| 34 | +*Responses* <6> |
| 35 | +
|
| 36 | +|HTTP Code|Description |Schema |
| 37 | +|201 |Successful creation | |
| 38 | +|400 |Bad Request |<<_apierror,ApiError>> |
| 39 | +|401 |Session required |<<_apierror,ApiError>> |
| 40 | +|403 |Unauthorized access |<<_apierror,ApiError>> |
| 41 | +|404 |Not found |<<_apierror,ApiError>> |
| 42 | +|=== |
| 43 | +---- |
| 44 | +<1> The name of the API endpoint. |
| 45 | +<2> A brief description of the API endpoint. |
| 46 | +<3> The API endpoint used for invocation. |
| 47 | +<4> The authorizations required to use the API endpoint. |
| 48 | +<5> The available paths to be used with the API endpoint. In this example, `title` is the only path to be used with the `POST /api/v1/user/apptoken` endpoint. |
| 49 | +<6> The API responses for this endpoint. |
| 50 | + |
| 51 | +In order to use an API endpoint, you pass in your access token and then include the appropriate fields depending on your needs. The following procedure shows you how to use the `POST /api/v1/user/apptoken` endpoint. |
| 52 | + |
| 53 | +.Prerequisites |
| 54 | + |
| 55 | +* You have access to the {productname} API, which entails having already created an OAuth 2 access token. |
| 56 | +* You have set `BROWSER_API_CALLS_XHR_ONLY: false` in your `config.yaml` file. |
| 57 | +
|
| 58 | +.Procedure |
| 59 | + |
| 60 | +* Create a user application by entering the link:https://docs.redhat.com/en/documentation/red_hat_quay/3.13/html-single/red_hat_quay_api_guide/index#appspecifictokens[`POST /api/v1/user/apptoken`] API call: |
| 61 | ++ |
| 62 | +[source,terminal] |
| 63 | +---- |
| 64 | +$ curl -X POST \ |
| 65 | + -H "Authorization: Bearer <access_token>" <1> |
| 66 | + -H "Content-Type: application/json" \ |
| 67 | + -d '{ |
| 68 | + "title": "MyAppToken" <2> |
| 69 | + }' \ |
| 70 | + "http://quay-server.example.com/api/v1/user/apptoken" <3> |
| 71 | +---- |
| 72 | +<1> The Oauth access token. |
| 73 | +<2> The name of your application token. |
| 74 | +<3> The URL of your {productname} deployment appended with the `/api/v1/user/apptoken` endpoint. |
| 75 | ++ |
| 76 | +.Example output |
| 77 | ++ |
| 78 | +[source,terminal] |
| 79 | +---- |
| 80 | +{"token": {"uuid": "6b5aa827-cee5-4fbe-a434-4b7b8a245ca7", "title": "MyAppToken", "last_accessed": null, "created": "Wed, 08 Jan 2025 19:32:48 -0000", "expiration": null, "token_code": "K2YQB1YO0ABYV5OBUYOMF9MCUABN12Y608Q9RHFXBI8K7IE8TYCI4WEEXSVH1AXWKZCKGUVA57PSA8N48PWED9F27PXATFUVUD9QDNCE9GOT9Q8ACYPIN0HL"}} |
| 81 | +---- |
| 82 | +
|
| 83 | +.Verification |
| 84 | + |
| 85 | +. On the {productname} UI, click your username in the navigation pane -> *Account Settings*. The name of your application appears under the *Docker CLI and other Application Tokens* heading. For example: |
| 86 | ++ |
| 87 | +image::application-token.png[Application token] |
0 commit comments