# When closing call getting ObjecterrorCode: 5007 "INSUFFICIENT\_PRIVILEGES"

**URL:** <https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961>\
**Category:** UI ToolKit\
**Created:** [April 4, 2025, 6:37pm UTC](https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961 "2025-04-04T18:37:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcocarosi](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@marcocarosi](https://devforum.zoom.us/u/marcocarosi)\
**Post date:** [April 4, 2025, 6:37pm UTC](https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961/1 "2025-04-04T18:37:32Z")

</div>

(Posted on github as well)  
I am getting the following error every time I close a session:

```auto
@zoom_videosdk-ui-toolkit.js?v=dc969869:33346 Uncaught (in promise)
ObjecterrorCode: 5007
reason: "only host can do the operation"
type: "INSUFFICIENT_PRIVILEGES"

```

This error happens only with @zoom/videosdk-ui-toolkit version 2.1.10-1, it does not happen with version 2.1.0-1

You can replicate this error with the sample apps, like the React sample app:  
`videosdk-ui-toolkit-react-sample`  
or the Angular sample app:  
`videosdk-ui-toolkit-angular-sample`

The issue gets triggered during session cleanup, at the following instruction :

```auto
uitoolkit.closeSession(sessionContainer)

```

After a first call, all subsequent attempts to start a session fail.

I checked the uitoolkit test page. There this issue does not occur.  
By looking at the js script, the `uitoolkit.onSessionClosed` callback function does not call  
⁠ `uitoolkit.closeSession(sessionContainer)⁠`.  
Instead, there is another callback that is not suggested in the documentation guides:

```auto
  ...
  uitoolkit.onSessionDestroyed(sessionDestroyed) 
  ...

  const sessionDestroyed = () => {
    console.log("session destroyed");
    uitoolkit.destroy();
  };

```

Questions:  
Do we need to use the `uitoolkit.destroy` instead of `uitoolkit.closeSession` ?  
If that is the case, I would have expected to call `uitoolkit.destroy` when the `uitoolkit.onSessionClosed` is fired.  
Documentation is not clear, can you please shed some lights on this?

---

<div class="post-metadata">

**Author:** ![ticorrian.heard](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ticorrian.heard/32/70213_2.png) [@ticorrian.heard](https://devforum.zoom.us/u/ticorrian.heard)\
**Post date:** [April 7, 2025, 3:28pm UTC](https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961/3 "2025-04-07T15:28:47Z")

</div>

Hi @marcocarosi I’m taking a look at this issue with my team now. I will get back to you with an update shortly.

---

<div class="post-metadata">

**Author:** ![ticorrian.heard](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ticorrian.heard/32/70213_2.png) [@ticorrian.heard](https://devforum.zoom.us/u/ticorrian.heard)\
**Post date:** [April 9, 2025, 2:23pm UTC](https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961/4 "2025-04-09T14:23:20Z")

</div>

Hi @marcocarosi I’m not able to replicate this issue in our react sample app.

This is the code I am using:

```auto
async function joinSession() {
    await getVideoSDKJWT();
    console.log(config);
    if (sessionContainer) {
      uitoolkit.joinSession(sessionContainer, config);
      sessionContainer && uitoolkit.onSessionClosed(sessionClosed);
    }
  }

  const sessionClosed = () => {
    console.log("session closed");
    sessionContainer && uitoolkit.closeSession(sessionContainer);
    document.getElementById("join-flow")!.style.display = "block";
  };

```

Would you be able to test from that sample app and let me know if is working there?

---

<div class="post-metadata">

**Author:** ![marcocarosi](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@marcocarosi](https://devforum.zoom.us/u/marcocarosi)\
**Post date:** [April 9, 2025, 7:08pm UTC](https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961/5 "2025-04-09T19:08:10Z")

</div>

Hi Ticorrian, thank you for you reply.  
I am using the react sample app `videosdk-ui-toolkit-react-sample` available in github.

There the code is not exactly the one you are using (App.tsx)

```ts
  function getVideoSDKJWT() {
    sessionContainer = document.getElementById(
      "sessionContainer"
    ) as HTMLDivElement;
    document.getElementById("join-flow")!.style.display = "none";
    fetch(authEndpoint, {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ sessionName: config.sessionName, role: role }),
    })
      .then((response) => {
        return response.json();
      })
      .then((data) => {
        if (data.signature) {
          console.log(data.signature);
          config.videoSDKJWT = data.signature;
          joinSession();
        } else {
          console.log(data);
        }
      })
      .catch((error) => {
        console.log(error);
      });
  }

  function joinSession() {
    console.log(config);
    if (sessionContainer) {
      uitoolkit.joinSession(sessionContainer, config);
      sessionContainer && uitoolkit.onSessionClosed(sessionClosed);
    }
  }

  const sessionClosed = () => {
    console.log("session closed");
    sessionContainer && uitoolkit.closeSession(sessionContainer);
    document.getElementById("join-flow")!.style.display = "block";
  };

```

I checked again with the github sample app, and the issue is still there.  
Just to be sure, I also modified the original code to accommodate the async/await paradigm in your code:

```ts
  async function getVideoSDKJWT() {
    sessionContainer = document.getElementById(
      "sessionContainer"
    ) as HTMLDivElement;
    document.getElementById("join-flow")!.style.display = "none";
    return fetch(authEndpoint, {
      method: "POST",
      headers: {"Content-Type": "application/json"},
      body: JSON.stringify({sessionName: config.sessionName, role: role}),
    })
      .then((response) => {
        return response.json();
      })
      .then((data) => {
        if (data.signature) {
          console.log(data.signature);
          config.videoSDKJWT = data.signature;
          // joinSession();
        } else {
          console.log(data);
        }
      })
      .catch((error) => {
        console.log(error);
      });
  }

  async function joinSession() {
    await getVideoSDKJWT();
    console.log(config);
    if (sessionContainer) {
      uitoolkit.joinSession(sessionContainer, config);
      sessionContainer && uitoolkit.onSessionClosed(sessionClosed);
    }
  }

  const sessionClosed = () => {
    console.log("session closed");
    sessionContainer && uitoolkit.closeSession(sessionContainer);
    document.getElementById("join-flow")!.style.display = "block";
  };

```

But also in this case I am getting the same error:

```auto
errorCode: 5007
reason: "only host can do the operation"
type: "INSUFFICIENT_PRIVILEGES"

```

Again, the error occurs when you do Leave Session or End Session. And after the first session, all subsequent attempts to do Join Session bring you to an empty browser window.

Hopefully my (sorry maybe too long ☺) reply helps.

---

<div class="post-metadata">

**Author:** ![marcocarosi](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@marcocarosi](https://devforum.zoom.us/u/marcocarosi)\
**Post date:** [April 10, 2025, 5:53pm UTC](https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961/6 "2025-04-10T17:53:47Z")

</div>

Hi Ticorrian,  
in the mean time I got a reply from `endazoom`, (Enda Zhang?) one of the maintainers of the `zoom/videosdk-ui-toolkit-web` github repository, on the bug I opened in GitHub before posting here.  
It is issues #52, let me copy it here for convenience (I guess I cannot add links to this chat):

> Thanks for the feedback! The closeSession() API should only be used by the session host, and it will end the session for other users. If the user role type is not host (role type not equal to 1, you will get this error). We will improve the documentation in later releases.  
> If you want to open another new session, please destroy the current instance first.

That confirms the need of the `uitoolkit.destroy()` call before creating another session.  
Not sure why I am getting the error on the sample app, since the role is always 1.

---

<div class="post-metadata">

**Author:** ![ticorrian.heard](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ticorrian.heard/32/70213_2.png) [@ticorrian.heard](https://devforum.zoom.us/u/ticorrian.heard)\
**Post date:** [April 15, 2025, 3:33pm UTC](https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961/7 "2025-04-15T15:33:54Z")

</div>

Hi @marcocarosi thanks for that info! I’ll work with Enda to get this better documented. Regarding the error youre receiving, are you sure the role being passed in the signature is 1? Also, there should be a host status in the participant list when you join as a host. Can you confirm if you see that?

 ![image](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/5/0/503651a1335c54829cd5f2358e081802d64a015f.png)

---

<div class="post-metadata">

**Author:** ![Waqas](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/waqas/32/68799_2.png) [@Waqas](https://devforum.zoom.us/u/Waqas)\
**Post date:** [April 28, 2025, 12:41pm UTC](https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961/8 "2025-04-28T12:41:07Z")

</div>

Hi @ticorrian.heard

“@zoom/videosdk-ui-toolkit”: “^2.1.10-2”  
“react”: “18.2.0”,  
“react-dom”: “18.2.0”,  
“volta”: {  
“node”: “20.11.1”  
}

I’m encountering a similar issue to the one discussed earlier. I have reviewed your suggestions and ensured that from the backend, the `role_type: 1` (host) is correctly being passed during video call initiation.

```auto
{
  "app_key": "",
  "cloud_recording_option": 0,
  "exp": 1745842506,
  "iat": 1745838906,
  "role_type": 1,
  "tpc": "1444161-f5a4e4a7",
  "user_identity": "675534",
  "version": 1
}

```

On the frontend, in the user component, I can also see the “Host” label correctly displayed next to my user, which confirms that the role assignment appears to be working.

However, when I attempt to end or leave the call, I consistently receive the following exception:

```auto
videosdk-ui-toolkit.min.umd.js:811 Uncaught (in promise)

{
  type: 'INSUFFICIENT_PRIVILEGES',
  reason: 'only host can do the operation',
  errorCode: 5007
}

```

This suggests that, although I am displayed as the host, the SDK internally does not seem to recognize me as having sufficient privileges to perform host-specific operations like ending the call.

I have already tried the basic troubleshooting steps, including verifying the role assignment and ensuring that the session is properly initialized.

Could you please help me understand why this mismatch might be happening, and if there are any additional checks or configurations required on either the frontend or backend side to properly grant host privileges when joining the session?

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![ticorrian.heard](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ticorrian.heard/32/70213_2.png) [@ticorrian.heard](https://devforum.zoom.us/u/ticorrian.heard)\
**Post date:** [April 28, 2025, 4:40pm UTC](https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961/9 "2025-04-28T16:40:11Z")

</div>

Hi @Waqas@marcocarosi I did some more testing on this and was able to replicate the issue. It seems the issues occurs regardless of when you call the uitoolkit.closeSession(sessionContainer) method so it does not look like a race condition issue. I reached out to our tooling team to confirm this could be an underlying issue. I’ll reach back out shortly after they’ve had some time to investigate.

---

<div class="post-metadata">

**Author:** ![ticorrian.heard](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ticorrian.heard/32/70213_2.png) [@ticorrian.heard](https://devforum.zoom.us/u/ticorrian.heard)\
**Post date:** [May 5, 2025, 6:35pm UTC](https://devforum.zoom.us/t/when-closing-call-getting-objecterrorcode-5007-insufficient-privileges/130961/10 "2025-05-05T18:35:57Z")

</div>

@Waqas @marcocarosi I spoke with Enda, one of engineers on the uitoolkit team, and he confirmed that `uitoolkit.closeSession(sessionContainer);` is not needed in the onSessionClosed listener. The reason is because the moment onSessionClose() event is fired, the session has already been ended and you cannot end a session that has been ended already.

We put in a request to update the docs to reflect this behavior and hopefully avoid future confusion.
