"The caller does not have permission" error when creating new project using node gcloud

8.7k views Asked by At

I'm using node.js google api (npm gcloud package) to create a new project. this is a beta API. I'm getting an error: "The caller does not have permission" stack:

ApiError: The caller does not have permission at new util.ApiError (C:\app\bundle\a2\node_modules\gcloud\lib\common\util.js:92:10) at Object.parseHttpRespBody (C:\app\bundle\a2\node_modules\gcloud\lib\common\util.js:170:30) at Object.handleResp (C:\app\bundle\a2\node_modules\gcloud\lib\common\util.js:110:18) at C:\app\bundle\a2\node_modules\gcloud\lib\common\util.js:422:12 at Request.onResponse [as _callback] (C:\app\bundle\a2\node_modules\gcloud\node_modules\retry-request\index.js:117:7) at Request.init.self.callback (C:\app\bundle\a2\node_modules\gcloud\node_modules\request\request.js:199:22) at Request.emit (events.js:110:17) at Request. (C:\app\bundle\a2\node_modules\gcloud\node_modules\request\request.js:1036:10) at Request.emit (events.js:129:20) at IncomingMessage. (C:\app\bundle\a2\node_modules\gcloud\node_modules\request\request.js:963:12)

I already enabled "Google Cloud Resource Manager API". Other calls works OK. What may be the problem?

2

There are 2 answers

2
Zack Butcher On BEST ANSWER

The Cloud Resource Manager's projects.create method is invite only per their documentation:

The projects.create() method is in the Alpha stage. It might be changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy. Access to this feature is currently invite-only. For an invitation, contact our sales team.

1
Stephen On

For that method, you must be authenticated as yourself, i.e. a service account JSON file won't work here. The only way to do that that I know of is by installing the gcloud SDK (https://cloud.google.com/sdk) and running gcloud auth login. When you instantiate gcloud, don't provide any credentials, only your project ID:

var gcloud = require('gcloud');
var resource = gcloud.resource({ projectId: 'grape-spaceship-123' });

// Now this should work:
resource.createProject('grape-spaceship-124', function(err, project) {});

Related material: