0

i want to use the autodesk forge viewer api in my php application in order to view ifc files so i used the forge-php-client sdk.everything works fine but the translating job doesn't and i'm getting this error : [404] Error connecting to the API (https://developer.api.autodesk.com/modelderivative/v2/designdata/job here the code:

/step1

        Configuration::getDefaultConfiguration()
                ->setClientId('xxxxxxxxxxxxxxxxxxxxxx')
                ->setClientSecret('xxxxxxxxxxxxxxxxxx');

        $twoLeggedAuth = new TwoLeggedAuth();
        $twoLeggedAuth->setScopes( [ 'bucket:create' ] );    

        $twoLeggedAuth->fetchToken();

        $tokenInfo = [
           'accessToken' => $twoLeggedAuth->getAccessToken(),
           'expiry'           => time() + $twoLeggedAuth->getExpiresIn(),
        ];

        //step2

        $twoLeggedAuth->setScopes( [ 'bucket:create' ] );
        $twoLeggedAuth->fetchToken();

        $apiInstance = new BucketsApi( $twoLeggedAuth );

        $bucket_info = array(
        'bucket_key' => 'nebnibim5'.time(),  
        'policy_key' => 'transient' 
        );
        $post_buckets = new PostBucketsPayload( $bucket_info );


        $result = $apiInstance->createBucket( $post_buckets, null );





        $twoLeggedAuth = new TwoLeggedAuth();
        $twoLeggedAuth->setScopes( [ 'data:write' ] );

        $twoLeggedAuth->fetchToken();

        $apiInstance = new ObjectsApi( $twoLeggedAuth );
        $bucket_key = $bucket_info['bucket_key']; 

        $filename = 'C:\wamp\www\nebnibim\storage\app\bibliothequeObjets\user69\13111006_IFCR2_Geo_Openings_1.ifc '; 
        $body = $filename;
        $file = new SplFileObject( $body );
        $content_length = $file->getSize();   
        $object_name = $file->getFilename();  

        //try {
        $result2 = $apiInstance->uploadObject( $bucket_key, $object_name, $content_length, $body, null, null );



        //step4
        $urn = 'urn:adsk.objects:os.object:nebnibim51548575979/13111006_IFCR2_Geo_Openings_1.ifc';
        $base64Urn = rtrim( strtr( base64_encode( $urn ), '+/', '-_' ), '=' );

        $twoLeggedAuth->setScopes( [ 'data:read', 'data:write' ] );
        $twoLeggedAuth->fetchToken();

        $apiInstance2 = new DerivativesApi( $twoLeggedAuth );

        $jobInput = array(
        'urn' => 'dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bmVibmliaW01MTU0ODU3NTk3OS8xMzExMTAwNl9JRkNSMl9HZW9fT3BlbmluZ3NfMS5pZmM'
        );

        $jobPayloadInput = new JobPayloadInput( $jobInput );

        $jobOutputItem = array(
        'type' => 'svf',
        'views' => array( '2d', '3d' )
        );

        $jobPayloadItem = new JobPayloadItem( $jobOutputItem );

        $jobOutput = [
        'formats' => array( $jobPayloadItem )        

        ];

        $jobPayloadOutput = new JobPayloadOutput( $jobOutput );


        $job = new JobPayload();

        $job->setInput( $jobPayloadInput );
        $job->setOutput( $jobPayloadOutput );
        $x_ads_force = false;

        $resultat= $apiInstance2->translate( $job,$x_ads_force );

1 Answer 1

0

Looks like you are still uploading to a bucket named after system time, only to call job on a hard coded urn pointing an object that’s uploaded to another bucket earlier - this would always result in a 404 error as the urn is incorrect.

Follow the code sample and docs here to fetch a list of the contents of an existing bucket, verify the objects really exist at the time of query in your bucket, take the objectId returned that’s guaranteed to be current and correct, and go from there.

You will need to upload the files again after 24 hours as the bucket you created is transient. See here for more on this - and that should be the reason for the error we are seeing now.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.