1
votes

I am trying to work with node.js client library for accessing googleAPI (https://github.com/google/google-api-nodejs-client). I am trying to insert bucket and object using google cloud storage API. I can successfully list the buckets of my project's storage. Also can retrieve specific bucket from the storage. But unable to insert the bucket or object.

Code which do the API call:

 googleapis.discover('storage', 'v1').execute(function(err,client){
    if(err)
     {
         console.log(err);
     }
  //insert bucket
  client.storage.buckets.insert({'project': "myproject_id",
                                 'resource': {'name': "mystorage-bucket"}})
                                  .withAuthClient(auth)
                                  .execute(function(err,result){
                                  console.log('error :',err,'inserted:',result);
                                 });

This is what shows in the log:

    error : { errors: 
                    [ { domain: 'global', 
                        reason: 'required', 
                        message: 'Required' } ],
              code: 400,
              message: 'Required' } inserted: null

Any indication what is "Required", how to provide it?

1

1 Answers

0
votes

The resource object should go as the second parameter of .insert like so:

client.storage.buckets.insert({ 
  'project': "myproject_id"
},
{
  'name': "mystorage-bucket"
}).withAuthClient(auth).execute(callback);