Setup command line tools to work with IBM Cloudant

  • 06 May, 2018

Command line tools are always welcome.  Today i need to setup my MAC to work with IBM Cloudant

Install curl on your MAC if you haven’t done it yet.

1 - You need to setup the Cloudant DB using your IBM Cloud account.

2 - Go to service credentials and get your username, password and hostname

Sample: "username": "xxxx-xxx-xxx-bluemix", "password": "yourcloudantpassword", "host": "xxxx-xxx-xxx-bluemix.cloudant.com"

3 - Test the connection

curl –v –u xxxx-xxx-xxx-bluemix 'https://xxxx-xxx-xxx-bluemix.cloudant.com'

The command will prompt for the password: yourcloudantpassword

You will see a lot off lines but pay attention on the line Authorization: Basic. This will be used to setup acurl (authorized curl) to avoid type the password every time you use curl.

\* Using HTTP2, server supports multi-use \* Connection state changed (HTTP/2 confirmed) \* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0 \* Server auth using Basic with user ’ xxxx-xxx-xxx-bluemix’ \* Using Stream ID: 1 (easy handle 0x7fabd0805800) > GET / HTTP/2 > Host: xxxx-xxx-xxx-bluemix.cloudant.com > Authorization: Basic asddadasdDASDdaDadaDSERQERQRQERQEDSGSFDGSFDG==

4 - Edit the .bash_profile or .bashrc file in any text editor. For example, from the command line, issue the following command: open –e .bash_profile

5 - Add the following line to the file, then save the file. alias acurl="curl -s --proto '=https' -g -H 'Authorization: Basic asddadasdDASDdaDadaDSERQERQRQERQEDSGSFDGSFDG=='"

6 - On the terminal run : source .bash_profile

7 - Issue a command using the new alias. For example, issue a command to view your account information. acurl -X GET 'https://xxxx-xxx-xxx-bluemix.cloudant.com'

TIP: The hostname is not friendly you can edit your hosts file and create an alias:

On MAC terminal type: sudo vi /etc/hosts

ping your hostname to get the ip address

add a line like this one bellow:

  xxxx-xxx-xxx -bluemix.cloudant.com  keniodb.cloudant.com

Save the hosts file

test the connection

acurl -X GET 'https://keniodb.cloudant.com

Related Posts

Error when run dnf install rpm-build

  • 31 Mar, 2025

I was installing the IBM MQ Server on a linux box yesterday. I got the error bellow: \root@gateway MQServer\ dnf install rpm-build
Updating Subscription Management repositories.
Instana 14 B/s |

Error when run dnf install rpm-buildRead More

How to Fix Error 513 When Unzipping Large Files on macOS

  • 25 Mar, 2025

If you’ve ever tried to unzip a large file on macOS and encountered the mysterious "Error 513," you’re not alone. This pesky error can pop up unexpectedly, leaving you scratching your head and wonderi

How to Fix Error 513 When Unzipping Large Files on macOSRead More

Python script to organize photos

  • 03 Mar, 2025

"I have lots of photo files. Since 2006, when I purchased my first digital camera, the number of photos has grown quickly, and after getting an iPhone, the number of photos exploded. With the high nu

Python script to organize photosRead More