Develop > Retrieve information from HP Codar using RESTful calls

Retrieve information from Codar using RESTful calls

The following sections provide information about using Codar RESTful API calls.

Communication with Codar

Solution developers communicate with Codar over HTTP or HTTPS and parse the data structures returned by Codar. The default port for communication with Codar is port 8444.

API data is returned in JSON format. You need to set the HTTP headers Content-Type:application/json and accept:application/json for the call you are making.

Authentication with an integration account

Authentication is handled using HTTP basic authentication. The authentication value is provided in the API call via the Authorization header. The Codar Integration User role is used for integrating third party tools like Jenkins to access Codar for pipeline management. From the Organization tab of the Codar console, you can configure the user access control for Codar Integration User. Users of this role have permission to create, update, deploy, promote, delete, and reject packages.

Users of this role are commonly used in Jenkins integration to create packages and execute release gate actions during continuous package promotion. Administrator has to associate this role to the first stage in pipeline management to ensure packages are created and release gate actions are executed

When exercising an API call from an HTTP client or from the interactive API content, the Authorization header is automatically generated using the credentials you supply when you log into Codar as it will be required to get permission to make RESTful calls.

When exercising an API call from your application's code, you must create the Authorization header. Supply the Base64 encoded value of the <username>:<password> string for the user you will use for authentication.

Executing RESTful calls

Codar RESTful API calls can be exercised through an HTTP client as described in Exercising API calls using an HTTP client or programmatically from an application. The API calls can also be exercised through the interactive content as explained in Exercising API calls using the interactive content. Some calls have more strict permission requirements, such as administrator level permissions, so you must supply the appropriate credentials.

The base URL for the API is https://<host>:<port>/csa/api/, which is appended with the specific URI for the API call. For example, to access the API for managing application deployments, you would use the URL: https://<host>:<port>/csa/api/codar/app-deploy, substituting the host and port information appropriate for your Codar environment.

Exercising API calls using an HTTP client

Though you can issue RESTful calls through any typical HTTP client (browser), you will likely find it more convenient to use a client designed especially for developers making RESTful calls. These are often referred to as REST clients. A REST client organizes the information you will work with when making RESTful calls: headers, methods, request and response bodies, and so on. A REST client makes it easier to compose and submit requests to the Codar RESTful service APIs, as well as for viewing server responses.

A number of REST clients are available. You can add the REST Console plug-in for Google™ Chrome, for example, as follows:

  1. Start Google Chrome.
  2. Open Chrome Web Store.
  3. Use search box to search for REST Console.
  4. Click the + Free button, then click the Add button in the dialog box that appears.

Example configuration of REST Console plug-in:

Configure the basic authorization in the Authorization tab using a username and password. See Authentication with an integration account for more information. This user must have privileges to access Codar's RESTful APIs.

Example REST Console authorization:

If the plug-in is configured correctly, you will see output in the Response Body tab similar to the following when you issue a request:

Exercising API calls using the interactive content

In addition to being exercised programmatically or through an HTTP client, the Codar API can be exercised through the “Try it out!” feature in the interactive API content. You will be prompted to log in to Codar to access this content. Basic authentication and authorization required to make RESTful calls will be configured as part of the login process.

The interactive content is presented in a web interface, and can be accessed at https://<host>:<port>/csa/apidocs.jsp from a browser, substituting the host and port information appropriate for your Codar environment.

The following is example content. The app-lifecycle call has been expanded in this example:

Expanded view of an API call

The content provides developers easy access to the following items:

  • URI syntax for each call
  • Required or optional query parameters
  • The data type of each parameter
  • Model and schema information, if applicable
  • Interactive "Try it out!" dialogs that let you submit calls to your server, see the results, and understand how you need to construct your REST URIs and any request body.

Perform the following steps to try an API call.

  1. From an Codar instance, launch the interactive API content from a browser at https://<host>:<port>/csa/apidocs.jsp.
  2. If you are not already logged into Codar, you will be prompted to log in. You must have appropriate authority to exercise Codar RESTful calls.
  3. Locate the app-design API call. Click on the call title to expand it.
  4. Click on the codar/app-design/list GET method to view the complete documentation for this call.

    Exanded view of an API call

  5. Enter values for the start-index and page-size parameters. By default, the response for this API is to list all application designs starting with the start index of zero.
  6. Click on the Try it out! button.
  7. You should now see the request URL that was sent, as well as the response body, response code and response headers for your request as shown here.

    API Request Results

Not every API call will be this simple to exercise, but this example demonstrates how the interactive API content is presented, and how RESTful calls can easily be made from this interface. In some situations you will need to make other API calls first to get information necessary for parameters or a request body.

Making API calls from an application

RESTful calls can be made from application code. Preparation for making these calls is similar to making them from an HTTP client. Authentication and authorization requirements as explained in Communication with Codar must be met.

You also need to set the HTTP headers Content-Type:application/json and accept:application/json as appropriate for the call you are making.