Accessing the Session ID with the viewer

To start with, I’m not a react developer, so perhaps I’m overstepping what I can do.

Summary: I can’t get the accurate Session ID anywhere.

I am injecting this bundle into the page: https://viewer.shapediver.com/v3/2.9.13/bundle.js

I am initializing the Session with:

const session = await SDV.createSession({
    ticket: "{{getVar "shapeDiverTicket"}}",
    modelViewUrl: "https://sdr7euc1.eu-central-1.shapediver.com",
});

I need access to the session ID to facilitate a file upload.

When I call session.id at a later time, I see the value is different than what what returned from the ticket/ API call.

The value that is returned from fetching this property is a GUID automatically created. The value in the ticket/ API is never made available through session.id.

What am I doing wrong? Is this a limitation of the CDN bundle instead of using React?

Do you mean the call to SDV.createSession ?

Maybe you are calling SDV.createSession multiple times?

Are you using React?

Please share a reproducible example.

Hello, here is the code: https://codesandbox.io/p/sandbox/shapediver-1-lnht2c?file=%2Findex.html%3A32%2C70

I’ve stripped it back to a proof of concept. You can see on the left the session.id value. On the right, you can see the session ID from the API request.

If I send a request to:

`${session.modelViewUrl}/api/v2/session/${sessionId}/file/upload`

If I use the sessionId from the API, I get a response. Otherwise, I get this error:

There are several problems I spotted:

  1. You are trying to upload an image, but your model doesn’t seem to have an image file input. Please use this component in your Grasshopper model: Import Bitmap
  2. It’s easier to use the API of the file parameter directly instead of making the API call yourself. This CodeSandBox shows how to do that: https://codesandbox.io/p/sandbox/file-upload-7no5p7?file=%2Fsrc%2Findex.ts

I can fix your code once you fixed item 1 (image input).

I was wrong about the file input, had missed it.

Here you can find the fixed CodeSandBox: https://codesandbox.io/p/sandbox/shapediver-1-forked-fvsnhf

Unfortunately, I can’t access that sandbox. Would you mind please reviewing the permissions? Thank you.

Please try again, should work now!

Thank you! I can indeed confirm that this worked. I appreciate it.