Installing and Using cURL
The examples within this document use cURL to demonstrate how to access and use the Oracle Linux Automation Manager REST API.
Task 1: Install cURL
To connect securely to the server, you must install a version of cURL that provide an SSL certificate authority (CA) certificate file or bundle to authenticate against a CA certificate. For more information about CA Certificate authentication, see Authenticating.
The following procedure demonstrates how to install cURL on an Oracle Linux 8 system.
-
Check to see whether cURL is already installed on your system.
sudo dnf info curl
If the package is installed, you should see it in the Installed Packages List. If you do not have it installed, you should see it listed in the Available Packages list. If cURL is not available in any repo, enable the ol8_baseos_latest repo and repeat this step.
-
Install cURL if not already installed.
sudo dnf install curl
You are now ready to send requests using cURL.
Task 2: Invoke cURL
Invoke cURL and specify one or more of the command-line options defined in the following table, as required, to direct its execution.
cURL Option | Description |
---|---|
-i --include
|
Returns the header in the response. |
-H --header |
H --header: includes the header in the request. |
"Authorization: Bearer <token>"
|
Specifies the Oauth2 token required to run the command. |
-X <method>
|
Indicates the method of request (for example, GET, POST) followed by the API entity path. |
-d, --data @file.json
|
Identifies the file that contains the request body,
in JSON format, on the local machine. Alternatively, you can pass
the request body with
-d"{id=5,status='OK'} .
|
-F, --form @file.json
|
Identifies form data, in JSON format, on the local machine. |
-k |
Indicates that a CA authority has not been set and the connection is insecure. This option is not recommended. |
The syntax for cURL commands is as follows:
curl -i -H Authorization: Bearer <token> -X <method> https://<hostname or IP address>/api/v2/<resource-path>
In the previous example, <token> is the Oauth2 token generated for your user account, <method> is action, such as Get, Post, Delete, Put, Patch, and so on, <hostname or IP address> is the hostname or IP address of the Oracle Linux Automation Manager server, and <resource-path> is the resource path, such as users/ or credential_types/.
For example:
curl -i -H "Authorization: Bearer pVQoc51Apt4LNrXrNzoSbaMCDzjK8B" -X GET https://192.102.118.107/api/v2/users/ HTTP/1.1 200 OK Server: nginx/1.14.1 Date: Thu, 11 Nov 2021 15:36:59 GMT Content-Type: application/json Content-Length: 951 Connection: keep-alive Vary: Accept, Accept-Language, Origin, Cookie Allow: GET, POST, HEAD, OPTIONS X-API-Product-Version: 15.0.1 X-API-Product-Name: AWX X-API-Node: 100.102.118.107 X-API-Time: 0.024s Content-Language: en X-API-Total-Time: 0.059s Strict-Transport-Security: max-age=15768000 {"count":1,"next":null,"previous":null,"results":[{"id":1,"type":"user","url":"/api/v2/users/1/","related":{"teams":"/api/v2/users/1/teams/","organizations":"/api/v2/users/1/organizations/","admin_of_organizations":"/api/v2/users/1/admin_of_organizations/","projects":"/api/v2/users/1/projects/","credentials":"/api/v2/users/1/credentials/","roles":"/api/v2/users/1/roles/","activity_stream":"/api/v2/users/1/activity_stream/","access_list":"/api/v2/users/1/access_list/","tokens":"/api/v2/users/1/tokens/","authorized_tokens":"/api/v2/users/1/authorized_tokens/","personal_tokens":"/api/v2/users/1/personal_tokens/"},"summary_fields":{"user_capabilities":{"edit":true,"delete":false}},"created":"2021-11-11T14:20:55.451086Z","username":"admin","first_name":"","last_name":"","email":"daniel.carriere@oracle.com","is_superuser":true,"is_system_auditor":false,"ldap_dn":"","last_login":"2021-11-11T15:15:19.547219Z","external_account":null,"auth":[]}]}$