Installing and Using cURL

The examples within this document use cURL to show 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 show how to install cURL on an Oracle Linux 8 system.

  1. Verify whether cURL is already installed on the system.

    sudo dnf info curl

    If the package is installed, you see it in the Installed Packages List. If you don't have it installed, you see it listed in the Available Packages list. If cURL isn't available in any repo, enable the ol8_baseos_latest repo and repeat this step.

  2. Install cURL if not already installed.

    sudo dnf install curl

You're 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. Or, 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 hasn't been set and the connection is insecure. This option isn't 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 the 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: Mon, 12 Aug 2024 16:56:44 GMT
Content-Type: application/json
Content-Length: 1952
Connection: keep-alive
Vary: Accept, Accept-Language, Origin
Allow: GET, POST, HEAD, OPTIONS
X-API-Product-Version: 23.7.0
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
X-API-Request-Id: af9121bf2bb748d08c60696334d4ea72
Access-Control-Expose-Headers: X-API-Request-Id
Strict-Transport-Security: max-age=15768000

{"count":2,"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":false,"delete":false}},"created":"2024-08-12T16:46:26.217924Z","modified":"2024-08-12T16:48:34.750654Z","username":"admin","first_name":"","last_name":"","email":"admin@example.com","is_superuser":true,"is_system_auditor":false,"password":"$encrypted$","ldap_dn":"","last_login":"2024-08-12T16:48:34.750654Z","external_account":null,"auth":[]},{"id":2,"type":"user","url":"/api/v2/users/2/","related":{"teams":"/api/v2/users/2/teams/","organizations":"/api/v2/users/2/organizations/","admin_of_organizations":"/api/v2/users/2/admin_of_organizations/","projects":"/api/v2/users/2/projects/","credentials":"/api/v2/users/2/credentials/","roles":"/api/v2/users/2/roles/","activity_stream":"/api/v2/users/2/activity_stream/","access_list":"/api/v2/users/2/access_list/","tokens":"/api/v2/users/2/tokens/","authorized_tokens":"/api/v2/users/2/authorized_tokens/","personal_tokens":"/api/v2/users/2/personal_tokens/"},"summary_fields":{"user_capabilities":{"edit":true,"delete":false}},"created":"2024-08-12T16:49:57.582764Z","modified":null,"username":"automationuser","first_name":"automationuser","last_name":"Automation","email":"automation@account.com","is_superuser":false,"is_system_auditor":true,"password":"$encrypted$","ldap_dn":"","last_login":null,"external_account":null,"auth":[]}]}