# iTwin and createTilesetfromiModelId

**URL:** <https://community.cesium.com/t/itwin-and-createtilesetfromimodelid/38392>\
**Category:** CesiumJS\
**Created:** [February 4, 2025, 3:41pm UTC](https://community.cesium.com/t/itwin-and-createtilesetfromimodelid/38392 "2025-02-04T15:41:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hilmar.retief](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hilmar.retief/32/14037_2.png) [@hilmar.retief](https://community.cesium.com/u/hilmar.retief)\
**Post date:** [February 4, 2025, 3:41pm UTC](https://community.cesium.com/t/itwin-and-createtilesetfromimodelid/38392/1 "2025-02-04T15:41:22Z")

</div>

Iven been experimenting with visualizing an iModel using a custom app (not Ion). And for a while it worked fine, until yesterday when the generated token appears to no longer be accepted in the iTwinData.createTilesetFromiModelId() call.  
Did something change yesterday?

I now consistently get this error on the following line of code:  
**const mytiles = await ITwinData.createTilesetFromIModelId**

“Uncaught (in promise) RangeError: Invalid array length  
at new DynamicEnvironmentMapManager (chunk-K5RKBSQI.js?v=4ea5af89:85967:38)  
at new Cesium3DTileset (chunk-K5RKBSQI.js?v=4ea5af89:126203:33)  
at Cesium3DTileset.fromUrl (chunk-K5RKBSQI.js?v=4ea5af89:127131:19)  
at async fetchToken”

**Here is the code snippet:**

```auto
    useEffect(() => {
        const fetchToken = async () => {
            const returnedData = await fetchGET('https://api.cesium.com/itwin/token');
            const { access_token: mytoken } = await returnedData;
            setToken(mytoken);
            console.log(`Latest token: ${mytoken}`);
            ITwinPlatform.defaultAccessToken = mytoken;
            const mytiles = await ITwinData.createTilesetFromIModelId('669dde67-eb69-4e0b-bcf2-f722eee94746');

            const myurl = mytiles?.resource?.url as string;
            setUrl(myurl);
        };

        fetchToken();
    }, []);

```

---

<div class="post-metadata">

**Author:** ![Gabby\_Getz](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/gabby_getz/32/7838_2.png) [@Gabby\_Getz](https://community.cesium.com/u/Gabby_Getz)\
**Post date:** [February 7, 2025, 9:51pm UTC](https://community.cesium.com/t/itwin-and-createtilesetfromimodelid/38392/2 "2025-02-07T21:51:25Z")

</div>

Hi @hilmar.retief!

Nothing should be changing with CesiumJS, unless the library version is updated.

We did release a new version of CesiumJS on Feb 3. Did you install the new version? For example, if you have installed it with npm, did you run `npm install`?

---

<div class="post-metadata">

**Author:** ![hilmar.retief](https://sea2.discourse-cdn.com/cesium/user_avatar/community.cesium.com/hilmar.retief/32/14037_2.png) [@hilmar.retief](https://community.cesium.com/u/hilmar.retief)\
**Post date:** [February 7, 2025, 10:39pm UTC](https://community.cesium.com/t/itwin-and-createtilesetfromimodelid/38392/3 "2025-02-07T22:39:09Z")

</div>

Thanks Gabby. I did update to the latest, and there was also an issue related to async updates in React, specifically I wanted to use TypeScript with useEffect. So, I still have a question on that, but for now if I set the initial state of the “url” to a known value.  
The reason it complained about the empty array was because the token was sometimes null.
