Process with the ShapeDiver Backend API to fetch the GLB files?

Hi,

Short stupid question… when working with the backend API of ShapeDiver I do not know how to fetch the GLB geometry output out of a session response. Could anyone assist me by pointing me to the method that I am suppose to use as an href.

const res = await sdk.session.init(ticket)

// sample first item of response
const url = Object.values(Object.values(response.outputs)[0].content)[0].href;

fetch(url, {
      mode: "no-cors",
    }).then((response) => {
      console.log(response); 
     //returns a status = 0 | response.ok = false
    });

Many Thanks,

Please note that your model most probably exposes several outputs. You might want to select the one you are looking for by its name. Related reading (there is also a video): Outputs on the API

As an example, this code would iterate through all the outputs and get the href to the first glb found:

let href = "";
for (const outputId in response.outputs) {
    const output = response.outputs[outputId];
    if (!output.content) continue;
    for (const item of output.content) {
        if (item.format === "glb") {
            href = item.href;
            break;
        }       
    }
    if (href) break;
}

Thanks Alex,

It is just one output: the geometry… that is why I was a bit direct on the process.
Output:

Model (just a box):

The link it outputs… is a 0.glb file that has nothing inside (3kb) while the original file as seen in the image above has a 2652kb of data representing a box:
https://sdr7euc1.eu-central-1.shapediver.com/cdn-asset-outputs/6b2cc358db2e54aea02043449b51e914/d139cffa7413ff2168f80a651195cec4/0.glb?Expires=1676297197&Key-Pair-Id=K30LJ55ETWFPXA&Signature=rYQsjXdl5MC-Zzx4bYzSf4WYMtnEKyG4XibPc5Ze8LjMdW0O8tR6-4Ig5HIdIQtoOoZecjPvyKZ8c7NwrbHfolwwS3P1rroH0jXeLxmmHrEhwCLt94D~aJY13ZxyosIIQ26brcntyMUJWrlDHRMLRu7S2BZ~V4KiF5SW3lj5Ik0r1y6gKK-dXQCumLyeNCkuy2Zv26yIuTMQqp-AoQdjINd8or2zPtltOAndD7sxyB9vN6Ynj2R8nBxelCqfdsACV5rE4FcnvZDS348gSD9qu1oG3Umr8WarlRfBHsWjlBj7ASwnnT9bLCYHWsMQcsv34Z3TQp606XLMboZxpT2tnA__

Is there anything I might be doing wrong on the setup? or does the fetching require credentials?

Thanks again,

These links are time limited, maybe it was already outdated once you triggered the download?
Did you inspect the response from fetch for errors?

For completeness: mode no-cors caused the problem, changing it to cors solved it.