IBM Cloudability

 View Only

 https://api.cloudability.com/v3/vendors failed by 401

Jump to  Best Answer
  • Cloudability
Apptio Community Member's profile image
Apptio Community Member posted Fri August 06, 2021 09:13 PM
I get my API Key as (APIs) Getting Started with Cloudability APIs | Cloudability said, then I try my API Key with access api: https://api.cloudability.com/v3/vendors by Curl: 

curl https://api.cloudability.com/v3/vendors -u 'My_API_Key:'

But I got 401 error as following,  could you help look into my issue, I guess you can troubleshoot it by the traceid.
{
"error": {
"status": 401,
"code": "unauthorized",
"messages": ["Unauthorized"],
"uniqueid": "a3b52bee-f714-11eb-a78a-8a08c8363f2c",
"typeid": "de0c8df22a40437ef3f0dce33714bc3a",
"traceid": "a37799af-f714-11eb-a78a-8a08c8363f2c"
}
}​

#Cloudability
Apptio Community Member's profile image
Apptio Community Member  Best Answer
Hi Yong - I agree with Suresh's response that you'll want to also engage with your TAM if there is one on your account as troubleshooting like this may require some back & forth with a person that has access to your organization's account.

One pointer I can give, as a TAM myself, is to look at the format of the API Key that you're using.  When passing the API Key through as a header, you'll want to make sure that the API Key has been base64 encoded.  However, if you're passing it through like a USERNAME by using the "-u" with your cURL, you'll want to use the raw API Key as it shows in Cloudability.  I'll give examples below to illustrate.

Before we get to the Example cURL, here's some things to consider in how I'm building it : 
  • URL = https://api.cloudability.com/v3/vendors
  • "RAW" Cloudability API Key (as it appears in Cloudability) : 123456789ABCDEFG
  • "Base64 Encoded" Cloudability API Key : MTIzNDU2Nzg5QUJDREVGRzo=


Example cURL :
curl --location --request GET 'https://api.cloudability.com/v3/vendors' \
--header 'Authorization: Basic MTIzNDU2Nzg5QUJDREVGRzo='

If you're wanting to pass it using a cURL specifically using the "-u" instead of "--header", it will need to look something like this :
curl 'https://api.cloudability.com/v3/vendors' -u '123456789ABCDEFG:'

Note that in the second example, there is a colon (:) after the encoded API Key, and I'm using the RAW API Key.  This is because the cURL being written in that format (a key:value pair) is designed to pass a username and a password together. The API Key works as a username in this context, and there's no password, so that's why there isn't anything after the colon.

In the first example, because it's being passed as a header using BASIC Auth, the API Key must be base64 encoded, and there's no need for the colon because a password is not expected in this format of API call.

Just to be certain I had everything formatted properly before posting this response, I did try both of the above cURLs (using real API Keys instead of the fake ones I used above), and it did result in the desired response.  My guess is that you may have either been trying to use the Cloudability API Key without a colon (for the -u method) or forgetting to encode it into base64 (for the header method).


#Cloudability
Suresh Sawlani's profile image
Suresh Sawlani
Hi @yong zou

I have tried to check this internally. There could be multiple reasons for the issue your experiencing.

May I recommend you to reach out to your TAM, if you have one, else raise a support ticket so that they can investigate this jointly with you and follow this through to resolution.

Hope that helps. ​
#Cloudability
Apptio Community Member's profile image
Apptio Community Member

I had the same issue, how i fixed it was you need to make sure you have ":" at the end of your My_API_Key.  It was very confusing as -u is for user, but we are using an APIkey in the request. 

So make sure you have the : at the end of the request, i also had the same issue in coding the api in python, and put in a "" for the password in the auth part, which fixed my issue as well. 


#Cloudability
Apptio Community Member's profile image
Apptio Community Member

I have tried the example from previous answer from Phillip and Paul but got the same error 401 response.
I raised the ticket to support yesterday and found out the solution on my own after several tries.

You can try to call the API by Curl using format as below :

curl https://api.cloudability.com/v3/vendors -u [api_key]
example : curl https://api.cloudability.com/v3/vendors -u 123456789ABCDEFG

And when the password dialogue is prompted, you can just hit the enter button.

Update: Adding colon at the end of [api_key] will not trigger the password dialogue
curl https://api.cloudability.com/v3/vendors -u 123456789ABCDEFG:


#Cloudability