第2章 API Reference
The full API reference is available on your Satellite Server at https://satellite.example.com/apidoc/v2.html
. Be aware that even though versions 1 and 2 of the Satellite 6 API are available, Red Hat only supports version 2.
2.1. Understanding the API Syntax リンクのコピーリンクがクリップボードにコピーされました!
The built-in API reference shows the API route, or path, preceded by an HTTP verb:
HTTP_VERB API_ROUTE
HTTP_VERB API_ROUTE
To work with the API, construct a command using the curl
command syntax and the API route from the reference document:
- 1
- To use
curl
for the API call, specify an HTTP verb with the--request
option. For example,--request POST
. - 2
- Add the
--insecure
option to skip SSL peer certificate verification check. - 3
- Provide user credentials with the
--user
option. - 4
- For
POST
andPUT
requests, use the--data
option to pass JSON formatted data. For more information, see 「Passing JSON Data to the API Request」. - 5 6
- When passing the JSON data with the
--data
option, you must specify the following headers with the--header
option. For more information, see 「Passing JSON Data to the API Request」. - 7
- When downloading content from Satellite Server, specify the output file with the
--output
option. - 8
- Use the API route in the following format:
https://satellite.example.com/katello/api/activation_keys
. In Satellite 6, version 2 of the API is the default. Therefore it is not necessary to usev2
in the URL for API calls. - 9
- Redirect the output to the Python
json.tool
module to make the output easier to read.
2.1.1. Using the GET HTTP Verb リンクのコピーリンクがクリップボードにコピーされました!
Use the GET HTTP verb to get data from the API about an existing entry or resource.
Example
This example requests the amount of Satellite hosts:
Example request:
curl --request GET --insecure --user sat_username:sat_password \ https://satellite.example.com/api/hosts | python -m json.tool
$ curl --request GET --insecure --user sat_username:sat_password \
https://satellite.example.com/api/hosts | python -m json.tool
Example response:
The response from the API indicates that there are two results in total, this is the first page of the results, and the maximum results per page is set to 20. For more information, see 「Understanding the JSON Response Format」.
2.1.2. Using the POST HTTP Verb リンクのコピーリンクがクリップボードにコピーされました!
Use the POST HTTP verb to submit data to the API to create an entry or resource. You must submit the data in JSON format. For more information, see 「Passing JSON Data to the API Request」.
Example
This example creates an activation key.
Create a test file, for example,
activation-key.json
, with the following content:{"organization_id":1, "name":"TestKey", "description":"Just for testing"}
{"organization_id":1, "name":"TestKey", "description":"Just for testing"}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create an activation key by applying the data in the
activation-key.json
file:Example request:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example response:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Verify that the new activation key is present. In the Satellite web UI, navigate to Content > Activation keys to view your activation keys.
2.1.3. Using the PUT HTTP Verb リンクのコピーリンクがクリップボードにコピーされました!
Use the PUT HTTP verb to change an existing value or append to an existing resource. You must submit the data in JSON format. For more information, see 「Passing JSON Data to the API Request」.
Example
This example updates the TestKey
activation key created in the previous example.
Edit the
activation-key.json
file created previously as follows:{"organization_id":1, "name":"TestKey", "description":"Just for testing","max_hosts":"10" }
{"organization_id":1, "name":"TestKey", "description":"Just for testing","max_hosts":"10" }
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the changes in the JSON file:
Example request:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example response:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - In the Satellite web UI, verify the changes by navigating to Content > Activation keys.
2.1.4. Using the DELETE HTTP Verb リンクのコピーリンクがクリップボードにコピーされました!
To delete a resource, use the DELETE verb with an API route that includes the ID of the resource you want to delete.
Example
This example deletes the TestKey
activation key which ID is 2:
Example request:
curl --header "Accept:application/json,version=2" \ --header "Content-Type:application/json" --request DELETE \ --user sat_username:sat_password --insecure \ https://satellite.example.com/katello/api/activation_keys/2 \ | python -m json.tool
$ curl --header "Accept:application/json,version=2" \
--header "Content-Type:application/json" --request DELETE \
--user sat_username:sat_password --insecure \
https://satellite.example.com/katello/api/activation_keys/2 \
| python -m json.tool
Example response:
2.1.5. Relating API Error Messages to the API Reference リンクのコピーリンクがクリップボードにコピーされました!
The API uses a RAILs format to indicate an error:
Nested_Resource.Attribute_Name
Nested_Resource.Attribute_Name
This translates to the following format used in the API reference:
Resource[Nested_Resource_attributes][Attribute_Name_id]
Resource[Nested_Resource_attributes][Attribute_Name_id]