Search code examples
autodesk-forgeautodesk-model-derivative

Unable to translate created object using autodesk forge derivativesApi


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"
}

Solution

  • 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