0

I'm trying to build an application by using the autodesk-forge-api's. To start with I created an App inside my Autodesk configuration to receive an "ClientID" and a "Client Secret" which are required to make API calls.

Somehow, when I try to use the createBucket-API call, which is documentet here I get an answer bad request 400 and I dont't know why.

here is my API call:

let oAuth2TwoLegged = new ForgeSDK.AuthClientTwoLegged(clientId, 
  clientSecret, [
  'data:read',
  'data:write',
  'bucket:create',
  'bucket:read',
  'data:write',
  'data:read',
  'viewables:read'           
], autoRefresh);

oAuth2TwoLegged.authenticate().then(function(credentials){

  var HubsApi = new ForgeSDK.HubsApi(); //Hubs Client
  var BucketsApi = new ForgeSDK.BucketsApi(); //Buckets Client

  BucketsApi.createBucket({bucketKey :"Test", policyKey: "transient"},{}, oAuth2TwoLegged, credentials).then((response) => {
    console.log(' new BUCKET: ', response)
  }).catch((err) => {
    console.log('ERROR BLA: ', err)
  });

}).catch((err) => {
  console.log('oauth error: ', err)
})

Does anyone have a suggestion what I might doing wrong?

when I use a different call, for example this:

BucketsApi.getBuckets({}, oAuth2TwoLegged, credentials).then(function(response){
   console.log('buckets: ', response.body);
  }, function(err){
    console.error(err);
});

it works...

EDIT

If I do the following:

BucketsApi.createBucket(xyda_select_rtl, {'bucketKey' :'xyda_select_rtl', 
   'policyKey': 'transient'}, oAuth2TwoLegged, credentials).then((response) => {
    console.log(' new BUCKET: ', response)
  }).catch((err) => {
    console.log('ERROR BLA: ', err)
});

I get xyda_select_rtl is not defined!?!

When I add:

var xyda_select_rtl;

I get the error Missing the required parameter 'postBuckets' when calling createBucket

Ehhm.... yeah :-/

ST80
  • 3,565
  • 16
  • 64
  • 124

2 Answers2

1

You need to come up with a unique name for your buckets, sorry for that bad news. It's not so bad that you think. For example simply add your client_id to the bucket name:

"test-tAp1fqjjtcgqS4CKpCYDjAyNbKW4IVCC"

Or use a random guid generated by code:

function guid() {

    var d = new Date().getTime();

    var guid = 'xxxx-xxxx-xxxx'.replace(
      /[xy]/g,
      function (c) {
        var r = (d + Math.random() * 16) % 16 | 0;
        d = Math.floor(d / 16);
        return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16);
      });

    return guid;
  }

Then use it to generate a bucket name:

var bucketKey = "test-" + guid()
Felipe
  • 4,325
  • 1
  • 14
  • 19
0

It seems that your bucket key is duplicated, or your client id and client secrete have invalid characters. Please check those parameters in your app. And the name of the Bucket, I.e. the bucket key should be global unique. If the name you passed to the Post /buckets is existed, you will get error, too. I’d suggest you to use the naming pattern in this way:

Test + { Your Bucket Key }

Hope it helps.

Eason Kang
  • 6,155
  • 1
  • 7
  • 24
  • hmm this gives me "Test is not defined" – ST80 Nov 13 '17 at 13:24
  • What did give you “Test is not defined”? The global means Forge OSS don’t allow there has one more bucket named “Test” on server side. If you didn’t see that bucket in your app, it might be token by other developers. You can check it via Get ‘/buckets/Test’. – Eason Kang Nov 13 '17 at 13:30
  • ok? but that would be very very inflexible, how can I know what others call their buckets? Check my edited question above. – ST80 Nov 13 '17 at 13:40
  • You can’t do the latest call, the first parameter is the API payload. It should contain bucketKey and policyKey, I.e. the first API call is correct, but the value in your bucketKey is duplicated to the Forge OSS. You should change the bucketKey value in your createBuckey payload. – Eason Kang Nov 13 '17 at 14:08