0

I am trying to translate an object after uploading it but I keep getting 400 Bad Request error.

I am using the forge-api-nodejs-client

here is how my code looks like

          var base64 = require('js-base64').Base64;

          objectsApi.uploadObject(
            bucket.bucketKey,
            file.originalname,
            file.size,
            file.buffer,
            {},
            oAuth2TwoLegged,
            credentials
          )
          .then(
            response => {
              const objectDetails = response.body;

              // objectId => urn:adsk.objects:os.object:d62db090-0c47-11e8-9a36-7bd06cedf058/Pawn.stl

              const job = {
                input: {
                  urn: base64.encode(objectDetails.objectId)
                },
                output: {
                  formats: [
                    {
                      type: "obj"
                    }
                  ]
                }
              };
              derivativesApi
                .translate(job, {}, oAuth2TwoLegged, credentials)
                .then(
                  data => {
                    res.send(data);
                  },
                  err => {
                    // it fails here with 400 status error
                    res.send(err);
                  }
                );
            },
            err => {
              res.send(err);
            }
          );

my job object looks like this:

{
  input:{
    urn: 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZDYyZGIwOTAtMGM0Ny0xMWU4LTlhMzYtN2JkMDZjZWRmMDU4L1Bhd24uc3Rs'
  },
  output: {
    formats: [
      type: "obj"
    ]
  }
}

the response

{
  statusCode: 400,
  statusMessage: "Bad Request"
}
Evan Lévesque
  • 3,115
  • 7
  • 40
  • 61
  • Does your keys have been activated for the use of all services. You need to have Model Derivative available in order for the translation to work. Can you check? Also here is a link that help you with what I'm suggesting. https://forge.autodesk.com/blog/where-are-my-apis – Jaime Rosales Feb 07 '18 at 21:32
  • @JaimeRosales yep it is activated in my application, otherwise I will get this error "You don't have permissions to access this API" – Evan Lévesque Feb 07 '18 at 21:37

2 Answers2

1

I have also a tutorial using the Forge NPM to do the whole process of creating bucket to upload file and translate it. I think the part you are having problems with is the uploading part

Check this https://github.com/jaimerosales/modelderivative-nodejs-tutorial/blob/master/uploader.js#L145

Jaime Rosales
  • 1,106
  • 1
  • 6
  • 8
0

Your payload is incorrect, it should look like below:

{
  input: {
    urn: "...place your design url here ..."
  },
  output:{
    force: false, // true if you want to force regenerate the obj, after new model upload for ex (optional)
    formats: [{
      type: 'obj',
      advanced: {
        modelGuid: "...",  // model GUID, required
        objectIds: [-1]    // array of dbIds to export, required. Pass [-1] to export full model, or specific dbIds ex: [49, 56, ...]
      }
    }],
    destination: {
      region: 'us'  // default, optional can be ['us', 'emea']
    }
  }
})

You need to perform additional API call to retrieve the model GUID: see GET :urn/metadata for more details

Felipe
  • 4,325
  • 1
  • 14
  • 19
  • using that urn to "GET :urn/manifest" or "GET :urn/metadata" returns a 404 error. and as per the docs that means 'Endpoint does not exist' :/ – Evan Lévesque Feb 07 '18 at 23:26
  • The endpoint definitely exists, it works fine on my side. You can use the SDK to invoke it, here is an example: https://github.com/Autodesk-Forge/forge-rcdb.nodejs/blob/master/src/server/api/services/DerivativesSvc.js#L73 – Felipe Feb 08 '18 at 09:05