Introduction
Informatica Cloud offers several APIs which lets you access the information of your organization from Informatica Cloud Repository. We have discussed about what is Informatica Cloud REST API and REST API in general in our previous article – Overview of Informatica Cloud (IICS) REST API. Please refer the article if you are new to REST API concepts.
There are several ways to access the Informatica Cloud REST API. In this article let us discuss how to access the Informatica Cloud REST API from command line using the cURL utility.
What is CURL?
cURL stands for client URL is a command-line tool and library for transferring data with URLs.
- It lets you talk to a server by specifying the location (in the form of a URL) and the data you want to send.
- It supports a number of protocols including HTTP, HTTPS, FTP, and many more which makes it a great tool for interacting with APIs.
- It is highly portable and is compatible with almost every operating system and hardware that exist today.
How to install CURL on Windows?
Starting with Windows 10, cURL is made available as part of OS. It is already set up, and you can start using it right away.
To verify if cURL is installed, Open the command prompt, and type below command.
curl --help
If there are no errors, and displays all the options of curl, it’s installed on your Windows 10.
If for some reason you do not find CURL installed on your Windows OS, you can easily download it from the source website.
How to install CURL on Ubuntu Linux?
To install CURL on Ubuntu Linux
1. First update the system and get latest stable curl version for Ubuntu.
$ sudo apt update
$ sudo apt upgrade
2. Type the following apt command to install CURL
$ sudo apt install curl
3. To verify CURL is installed, run the follow command
curl --help
If there are no errors, and displays all the options of curl, it’s installed on your Ubuntu Linux.
How to make IICS REST API calls using CURL?
As a standard procedure to access any information of your Org from Informatica Cloud Repository, you need to first login by providing the user credentials. Get the sessionID from the response and use it in subsequent REST API calls.
To login in to your Informatica Cloud Org using REST API Version2 resource with North America as POD region, below are request details that needs to be present in your login call
Request Method: POST
Request URL: https://dm-us.informaticacloud.com/ma/api/v2/user/login
Headers:
Content-Type: application/json
Accept: application/json
Body:
{
"@type": "login",
"username": "your-username",
"password": "your-password"
}
To make a login call using cURL, use the below command options
-X : HTTP Method with endpoint URL
-H : Headers
-d : Body
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d "{\""@type\"":\""login\"",\""username\"":\""your-username\"",\""password\"": \""your-password\""}" https://dm-us.informaticacloud.com/ma/api/v2/user/login
![IICS Login call using cURL](https://thinketl.com/wp-content/uploads/2021/11/53-1-curl-login-1024x156.png)
From the response, collect the serverUrl and icSessionId details to use in subsequent calls.
For example, to verify the status of Secure Agent using cURL, use the following request.
Request Method: GET
Request URL: <serverUrl>/api/v2/agent
Headers:
Accept: application/json
icSessionId: <icSessionId>
To verify Secure Agent status using cURL use the below command
curl -X GET -H "Accept: application/json" -H "icSessionId: 3SS7Pve09iRdvnvvspMnKN" https://usw5.dm-us.informaticacloud.com/saas/api/v2/agent
![GET IICS Secure Agent Status using cURL](https://thinketl.com/wp-content/uploads/2021/11/53-2-curl-agent-status-1024x125.png)
The response shows that the Secure Agent is up and running.
How to extract CURL code from Postman?
Postman is a popular REST API Client which helps developers to build, test and modify APIs. Postman provides an option to extract the code of API request made from it in multiple programming languages.
To extract the cURL code of login request from Postman follow below steps.
1. Execute the login call from Postman.
2. Once the login call is successful, click on code.
![](https://thinketl.com/wp-content/uploads/2021/11/53-3-Postman-login.png)
3. Choose cURL code from the list of option available. By default, the cURL code available in Postman is in a different format.
![](https://thinketl.com/wp-content/uploads/2021/11/53-4-open-settings.png)
4. To make the code simple, click on Settings. Disable all the options except Follow redirects and Trim request body fields.
![](https://thinketl.com/wp-content/uploads/2021/11/53-5-Enable-Settings.png)
5. Once done with the settings, go back to the generated code and copy the code snippet.
![](https://thinketl.com/wp-content/uploads/2021/11/53-6-copy-code-snippet.png)
The login code extracted from the Postman will be as below
curl -L -X POST 'https://dm-us.informaticacloud.com/ma/api/v2/user/login' -H 'Content-Type: application/json' -H 'Accept: application/json' --data-raw '{
"@type": "login",
"username": "your-username",
"password": "your-password"}'
This code will not directly work with curl command-line utility, to make it work follow below steps
- Replace all Single quotes with Double quotes.
- Escape all the double quotes that are in body tag (–data-raw/d) with a backward slash \.
- Arrange everything in a single line.
Here is the final modified code
curl -L -X POST "https://dm-us.informaticacloud.com/ma/api/v2/user/login" -H "Content-Type: application/json" -H "Accept: application/json" --data-raw "{\"@type\": \"login\",\"username\": \" your-username \",\"password\": \" your-password \"}"
Run the modified code from command-line.
Conclusion
Postman is a popular API testing tool which is a best way to test the Informatica Cloud APIs. But it cannot be used to automate a process using the Informatica Cloud REST API resources. This can be solved using the cURL.
You can package these cURL commands into a script and read the response of the API calls within the script to take actions.
Ex: Monitor Secure Agent and its Services Status in the real time, Get the Activity log details, Read Audit logs etc.
Since cURL commands can be easily extracted from Postman, use Postman to test the APIs first and extract the cURL code from it to use in the scripts.
After running the curl command, it just goes to a hang state, How long will the curl command run?
Not much. Have you tried testing it from Postman?
thanks its useful link