Search code examples
autodesk-forgeautodesk-model-derivative

How to form a "GET :urn/manifest/:derivativeurn" request?


I don't get how to download a created derivative from Forge.

Here is what I get from the "GET :urn/manifest" request:

{
"type": "manifest",
"hasThumbnail": "false",
"status": "success",
"progress": "complete",
"region": "US",
"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZGVyaXZhdGV0bXAvU3QlQzMlQTRuZGVyX1lfT2JlbiUyMHYxLmYzZA",
"version": "1.0",
"derivatives": [
    {
        "name": "Ständer_Y_Oben v1.f3d",
        "hasThumbnail": "false",
        "status": "success",
        "progress": "complete",
        "outputType": "obj",
        "children": [
            {
                "guid": "4064073b-a56c-4007-8b87-3cf87c821361",
                "type": "resource",
                "role": "obj",
                "status": "success",
                "progress": "complete",
                "mime": "application/octet-stream",
                "urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZGVyaXZhdGV0bXAvU3QlQzMlQTRuZGVyX1lfT2JlbiUyMHYxLmYzZA/output/files/6f7db9b2-925f-44b3-92e8-a5aeeb3954d2/Ständer_Y_Oben v1.obj"
            }
        ]
    }
]

So how to form a valid "GET :urn/manifest/:derivativeurn" request with that? The docs say "urn should be The Base64 (URL Safe) encoded design URN" and "derivativeurn should be The URL-encoded URN of the derivatives.".

For me this results in: https://developer.api.autodesk.com/modelderivative/v2/designdata/dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZGVyaXZhdGV0bXAvU3QlQzMlQTRuZGVyX1lfT2JlbiUyMHYxLmYzZA/manifest/urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZGVyaXZhdGV0bXAvU3QlQzMlQTRuZGVyX1lfT2JlbiUyMHYxLmYzZA/output/files/6f7db9b2-925f-44b3-92e8-a5aeeb3954d2/St%C3%A4nder_Y_Oben%20v1.obj

But the result always is the message "The requested derivative is not belongs to the design data.".

So what is wrong? The docs or me?

Regards, Michael


Solution

  • According to documentation of GET :urn/manifest/:derivativeurn, the derivativeurn should be escaped into a URL safe form since there are some reserved and unsafe keywords ( i.e. :, ., ? and = ) in this parameter. They will invalid your request to the Forge service. (Ref)

    Your file urn is: urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZGVyaXZhdGV0bXAvU3QlQzMlQTRuZGVyX1lfT2JlbiUyMHYxLmYzZA/output/files/6f7db9b2-925f-44b3-92e8-a5aeeb3954d2/Ständer_Y_Oben v1.obj

    To download this file, you have to transform it into this form: urn%3Aadsk.viewing%3Afs.file%3AdXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZGVyaXZhdGV0bXAvU3QlQzMlQTRuZGVyX1lfT2JlbiUyMHYxLmYzZA%2Foutput%2Ffiles%2F6f7db9b2-925f-44b3-92e8-a5aeeb3954d2%2FSt%C3%A4nder_Y_Oben%20v1.obj


    In JavaScript, the encodeURIComponent()(Ref) function can help you do this transformation. Here is a sample for you:

    encodeURIComponent('urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZGVyaXZhdGV0bXAvU3QlQzMlQTRuZGVyX1lfT2JlbiUyMHYxLmYzZA/output/files/6f7db9b2-925f-44b3-92e8-a5aeeb3954d2/Ständer_Y_Oben v1.obj')

    If you are coding in C#, Uri.EscapeDataString() (Ref) can help you to archive the same goal.