3

I am using the Cloudant service via the Node.JS module, with the credentials provided via Bluemix VCAP_SERVICES (or a local copy). The instance is created with

var Cloudant = require('cloudant');
// var cloudantCreds obtained from process.env.VCAP_SERVICES
var username = cloudantCreds.username;
var password = cloudantCreds.password;
var cloudant = Cloudant({
    account:username, 
    password:password
});

I had written a function that would automatically create/delete a database when a user requested, and it successfully worked. This internally used

cloudant.db.create(databaseName, function(err, res){
     // Handle
});

However, recently I get an error:

'server_admin access is required for this request'

I am only using one set of credentials and one account. Using these credentials in the command line with curl allows me to successfully create/delete databases, but it seems to be unable to do this via the node.js module?

As far as I can remember, I haven't changed any code related to this function of my Node.js server.

What is causing me to now require server_admin access? From the nature of the error message, I am presumably authenticated, but not authorised?

Jake
  • 67
  • 6
  • I have just executed your code snippet with my admin account/password and I was able to create a new database from the Node.js application. When I swapped the credentials for a non-admin apikey/password I get `server_admin access is required for this request`. You can debug the request that is actually being made by doing: `DEBUG=nano node app.js` i.e. setting the `DEBUG` environment variable to `nano`. – Glynn Bird Jun 02 '16 at 14:23
  • Thanks for the comment about DEBUG, it helps. It appears that the issue is not with the functionality I've described above - that it turns out still works as expected in deployment. I get the error when running Mocha tests on the express object that triggers the above function, so presumably there is an error somewhere in the mocha set up. – Jake Jun 02 '16 at 16:49

2 Answers2

2

It turns out it was an error on my behalf, although Cloudant was not particularly informative.

I was trying to create databases with disallowed names, such as beginning with an underscore or containing a capital letter. Change the database name, and it all works correctly.

Jake
  • 67
  • 6
0

if your database is prefixed with underscore it will throw errors...

  • Can you differentiate your answer from the existing answer which gives the exact same information? – Avery Feb 16 '18 at 19:13