Search code examples
javaandroidcloudant

Cloudant Unathorized request


I've been trying to work this problem out about accessing my cloudant DB from IBM-bluemix services. I've set my URL in Android studio like this:

URL url = new URL("https://XXXX-XXXX-XXXX-XXXX-XXXX-bluemix.cloudant.com");

And then trying to access it by:

CloudantClient client =  ClientBuilder.url(url)
                .username("myusername")
                .password("mypassword")
                .build();

However, When i try to access/modify anything within my database, ex:

client.createDB("test_DB");

I get the error:

Error: unauthorized. Reason: one of _admin, server_admin is required for this request.

What am i missing? I've seen many different ways to approach querying from cloudant, but this is the closest i've gotten.

Have i just completely misunderstood how querying from an existing database works?


Solution

  • If you are using a Cloudant legacy API key you won't be able to perform account administrator level actions, such as listing or creating databases because the legacy API keys are associated with specific databases not the account. If that is the type of credentials you are using you can initialize the client in the way you have done and get the existing database via:

    Database db = client.database("test_DB", false);