0

Following a recent post which has been addressed using the extract.autodesk.io module (SVF model derivative downloaded as an (almost) empty ZIP file (Autodesk Forge)), I still have difficulties in downloading the SVF model derivative using simply the official forge-apis module, in a 2-legged context.

Here is a minimal sample of what I'm attempting to achieve:

var ForgeSDK = require("forge-apis");

/* The next four lines are filled with my credentials and URN values 
 * (this shouldn't be the problem, since getting the manifest for the URN
 * is performed successfully) */
var client_id = "...";
var client_secret = "...";
var urn = "...";
var derivative_urn = "...";

var derivatives = new ForgeSDK.DerivativesApi();
var autoRefresh = true;
var oAuth2TwoLegged = new ForgeSDK.AuthClientTwoLegged(client_id, 
    client_secret, [
        "data:read", "data:write", "bucket:read", "bucket:write"
    ], autoRefresh);

oAuth2TwoLegged.authenticate().then(function(credentials) {
    derivatives.getDerivativeManifest(urn, derivative_urn, {}, credentials, oAuth2TwoLegged).then(function(content) {
        console.log(content);
    }).catch(function(err) {
        if (err) {
            console.log(err);
        }
    })
});

I get the following error: { statusCode: 401, statusMessage: 'Unauthorized' }. Is it a scope issue?

Thanks a lot in advance!

P.S.: I know the extract.autodesk.io offers a nice way to do that, but I feel that using the bubble object is not so straightforward to transpose in another context. The forge-apis module should do the job seamlessly (or I'm missing something).

Update: Following Augusto's suggestion, I have used the most basic commands (i.e. cUrl) to download information from an IFC file. The first two commands below work successfully (donwload of the manifest and of a PNG screenshot file). The download of the SVF seems to work fine too, except that the ZIP file only contains two JSON files (manifest.json and metadata.json), as well as three empty directories (geometry, material, scene).

Here is the code:

# Get manifest for the IFC file
curl -X "GET" -H "Authorization: Bearer $TOKEN" -v "https://developer.api.autodesk.com/modelderivative/v2/designdata/$URN_IFC/manifest" > manifest.json

# Get a PNG related to the IFC file
curl -X "GET" -H "Authorization: Bearer $TOKEN" -v "https://developer.api.autodesk.com/modelderivative/v2/designdata/$URN_IFC/manifest/$URN_PNG" > image.png

# Get the SVF converted from the IFC file
curl -X "GET" -H "Authorization: Bearer $TOKEN" -v "https://developer.api.autodesk.com/modelderivative/v2/designdata/$URN_IFC/manifest/$URN_SVF" > output.zip

Any idea?

  • this seems like a URN/Bucket you cannot see, can you try a simple GET on that endpoint using Postman (or similar)? – Augusto Goncalves Aug 11 '17 at 11:43
  • Thanks Augusto for the suggestion. I have answered in the Edit (see Update). –  Aug 11 '17 at 13:07
  • thanks @Rajan, I'll be checking the code, but can you also confirm the package version 0.4.1? I know we did some fixes recently. https://www.npmjs.com/package/forge-apis – Augusto Goncalves Aug 11 '17 at 13:38
  • Yes, I use the 0.4.1 version of forge-apis. Thanks for your help. –  Aug 11 '17 at 13:41

2 Answers2

0

Looking at the implementation for npm forge-apis@0.4.1, the signature is:

this.getDerivativeManifest = function(urn, derivativeUrn, opts, oauth2client, credentials)

But it seems your code is using oauth2client and credentials in the opposite order. After this change, it works fine here.

var derivatives = new ForgeSDK.DerivativesApi();
var autoRefresh = true;
var oAuth2TwoLegged = new ForgeSDK.AuthClientTwoLegged(client_id, 
    client_secret, [
        "viewables:read"
    ], autoRefresh);

oAuth2TwoLegged.authenticate().then(function(credentials) {
    derivatives.getDerivativeManifest(urn, derivative_urn, {}, oAuth2TwoLegged, credentials).then(function(content) {
        console.log(content);
    }).catch(function(err) {
        if (err) {
            console.log(err);
        }
    })
});

Would suggest use only viewables:read scope as you don't need all those extra permissions (for this code, at least).

Augusto Goncalves
  • 8,493
  • 2
  • 17
  • 44
  • This is strange... I've checked both orders (for credentials and oauth2client), and the one you propose leads to "{ statusCode: 400, statusMessage: 'Bad Request' }", while mine leads to "{ statusCode: 401, statusMessage: 'Unauthorized' }". Anyway, I've also checked the simple generation of the token and I get "...\node_modules\forge-apis\src\auth\OAuth2.js:42 `throw specificScope[key] + " scope is not allowed"; viewables:read scope is not allowed"` => is it a scope issue related to the Forge account? –  Aug 11 '17 at 15:29
  • if I base64 encode the derivative URN, then I get `BadRequest`, check that. The `viewables:read scope is not allowed` probably means that you have an older version of the SDK, would suggest a fresh `npm install forge-apis@0.4.1 --save` – Augusto Goncalves Aug 11 '17 at 15:31
  • from your original code, the `bucket:write` is not allowed, another indicator that you may have a older version of the SDK (as it was working for you), see https://github.com/Autodesk-Forge/forge-api-nodejs-client/blob/master/src/auth/OAuth2TwoLegged.js#L45 and https://developer.autodesk.com/en/docs/oauth/v2/overview/scopes/ – Augusto Goncalves Aug 11 '17 at 15:35
  • Hmmm... I have made a fresh install of forge-apis, which allows me now to use the code you wrote (still odd, since my previous install already mentioned v0.4.1 in package.json, but anyways...). The problem is that we're back to my initial post, i.e. the download works now like with the cUrl command: no error (statusCode=200), a zip file is downloaded, but with empty directories in it (like described in the Update above). Could it be related to the way I write the buffer? –  Aug 12 '17 at 07:40
  • I write the buffer like this:`derivatives.getDerivativeManifest(urn, derivative_urn, {}, oAuth2TwoLegged, credentials).then(function(content) { var stream = fs.createWriteStream("svf.zip"); stream.write(content.body); stream.end(); }`. Thanks in advance. –  Aug 12 '17 at 07:40
0

After having updated the forge-apis NPM package to its latest version (0.4.1), I gave a new try to the bubble.js function from extract.autodesk.io, and it works fine now: I'm able to download the SVF file(s) effortlessly.

Thanks @Augusto for your help. Still curious to know why the "basic" cUrl method doesn't work as expected...