# Webhooks & Server-to-server Oauth: Websocket fails to connect

**URL:** <https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974>\
**Category:** API and Webhooks\
**Tags:** webhooks, oauth\
**Created:** [June 5, 2022, 12:37am UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974 "2022-06-05T00:37:46Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![callum.katene](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/callum.katene/32/31881_2.png) [@callum.katene](https://devforum.zoom.us/u/callum.katene)\
**Post date:** [June 5, 2022, 12:37am UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974/1 "2022-06-05T00:37:46Z")

</div>

**Description**  
I am creating a WebHooks-type app that uses server-to-server Oauth authentication.

 ![AppDefinition](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/0/7/07e61e8c686a9d50ebbd59fed6931b2d0ed26c4c.png)

I am following the Server-to-server Oauth guidelines ([here](https://marketplace.zoom.us/docs/guides/build/server-to-server-oauth-app/#use-account-credentials-to-get-an-access-token)), but when I attempt to open the websocket, I always get this response:

```auto
{"module":"build_connection","success":false,"content":"token is empty","header":{}}

```

I am seeing `token is empty` even though I am setting the Request Header **Authorization** with a valid bearer token.

**Process**  
I make an initial call to `https://zoom.us/oauth/token?grant_type=account_credentials&account_id={accountId}` as per the instructions [here](https://marketplace.zoom.us/docs/guides/build/server-to-server-oauth-app/#use-account-credentials-to-get-an-access-token). This is successful and I am able to retrieve a valid token; example follows:

```auto
{"access_token":[REDACTED]",
"token_type":"bearer",
"expires_in":3599,
"scope":"phone:read:admin phone_e911:read:admin user:read:admin user:write:admin"}

```

I then create the websocket endpoint, using the URL specified in the `App Feature` section of the app definition:

 ![AppFeature](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/0/a/0a593d96de3bfd8145befbdbcf09d0af13f26ca5.png)  
I can see the Authorization header in the socket definition.

```auto
 map[Authorization:[Bearer [REDACTED]] Token:[REDACTED]]

```

… but the websocket connect attempt always returns:

```auto
{"module":"build_connection","success":false,"content":"token is empty","header":{}}

```

… and then disconnects.

**Error**  
The websocket connection attempt always returns:

```auto
{"module":"build_connection","success":false,"content":"token is empty","header":{}}

```

… and then disconnects.

**API Endpoint/s?**

`wss://ws.zoom.us/ws?subscriptionId=XXXXXXXXXX`  
`https://zoom.us/oauth/token?grant_type=account_credentials&account_id=XXXXXXXXXX`

**How To Reproduce**  
As per the **Process** section above.

**Additional context**  
Server is coded in Go, using the `github.com/sacOO7/gowebsocket` package, which itself relies on `github.com/gorilla/websocket`

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [June 7, 2022, 1:22am UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974/2 "2022-06-07T01:22:06Z")

</div>

@callum.katene,

Thank you for posting in the Developer Forum. It seems like the access token is not being passed into the request as expected. Since you have the access token, you should be able to make requests against Zoom API. Could you share more details about the intended flow? Specifically, what is the expected result on a successful WebSocket connect attempt? Would you be able to share a snippet of code that is preventing you from leveraging the access token to make a request?

> [@callum.katene](#):
>
> I am seeing `token is empty` even though I am setting the Request Header **Authorization** with a valid bearer token.

Have you tried to manually/hardcode the access token at the websocket connect attempt step?

## Also, to align with our security practices, we ask that you omit your Personal Identifiable Information when posting on the forum.

---

<div class="post-metadata">

**Author:** ![callum.katene](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/callum.katene/32/31881_2.png) [@callum.katene](https://devforum.zoom.us/u/callum.katene)\
**Post date:** [June 7, 2022, 3:43am UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974/3 "2022-06-07T03:43:43Z")

</div>

Hello, and thanks for taking the time to reply.

> Could you share more details about the intended flow?

Sure. We have been using Webhooks apps for a while to get event data. We created a new app using Server to server OAuth, and see that we can choose either rest or websockets. We have chosen websockets because this is a realtime application, and the consistent connection should improve the event latency.  
So:

1. Make a call to `https://zoom.us/oauth/token` to retrieve a token. This step is successful and a valid token is returned.
2. Establish a websocket connection to the wss URL specified in the app’s Feature section. I am **assuming** that we need to add the retrieved token as an Authorization header in this connection attempt. However, I have not found any documentation relating to websockets that states this. If you have a pointer for me it would be much appreciated.

> Specifically, what is the expected result on a successful WebSocket connect attempt?

At the very least we would expect a response indicating a successful connection. The response we get is of an **unsuccessful** connection, and then a disconnect.

> Would you be able to share a snippet of code that is preventing you from leveraging the access token to make a request?

Certainly. In the below:

- **accountId, clientId** and **clientSecret** are the values from the App Credentials section
- **ws** is a string holding the Endpoint URL from the app Feature section
- **gws** is a reference to the [Gorilla Websocket](https://github.com/gorilla/websocket) package.

```auto
func main2() {
	var err error
	accessToken, err = GetAccessToken(accountId, clientId, clientSecret)
	if err != nil {
		log.Fatalf("Could not get an access token: %v", err)
	}
	f("Token: %v", accessToken)

	header := http.Header{
		"Host": {"ws.zoom.us"},
		"Content-Type": {"application/json"},
		"Authorization": {"Bearer " + accessToken.AccessToken},
	}

	f("Header: %v", header)
	c, _, err := gws.DefaultDialer.Dial(ws, header)
	if err != nil {
		log.Fatal("dial:", err)
	}
	defer c.Close()

	done := make(chan struct{})

	interrupt := make(chan os.Signal, 1)
	signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM)

	go func() {
		defer close(done)
		for {
			_, message, err := c.ReadMessage()
			f("Message: %v", string(message))
			if err != nil {
				log.Println("read:", err)
				interrupt <- syscall.SIGTERM
				return
			}
			log.Printf("recv: %s", message)
		}
	}()

```

Here is the log output:

```auto

2022/06/07 15:40:34 Token: {[REDACTED] bearer 3599 phone:read:admin phone_e911:read:admin user:read:admin user:write:admin}
2022/06/07 15:40:34 connecting to wss://ws.zoom.us/ws?subscriptionId=XXXXXXXXXXXX
2022/06/07 15:40:34 Header: map[Authorization:[Bearer [REDACTED]] Content-Type:[application/json] Host:[ws.zoom.us]]
2022/06/07 15:40:35 Message: {"module":"build_connection","success":false,"content":"token is empty","header":{}}
2022/06/07 15:40:35 recv: {"module":"build_connection","success":false,"content":"token is empty","header":{}}
2022/06/07 15:40:35 Message: 
2022/06/07 15:40:35 read: websocket: close 1000 (normal): Bye
2022/06/07 15:40:35 interrupt

```

---

<div class="post-metadata">

**Author:** ![callum.katene](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/callum.katene/32/31881_2.png) [@callum.katene](https://devforum.zoom.us/u/callum.katene)\
**Post date:** [June 7, 2022, 5:42pm UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974/5 "2022-06-07T17:42:49Z")

</div>

There you go.

Thank you very much. I’ll give that a try.

Where should I have found the documentation for that?

---

<div class="post-metadata">

**Author:** ![ojus.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ojus.zoom/32/734_2.png) [@ojus.zoom](https://devforum.zoom.us/u/ojus.zoom)\
**Post date:** [June 7, 2022, 5:49pm UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974/6 "2022-06-07T17:49:11Z")

</div>

@callum.katene the websockets feature is in beta at the moment. Please DM me if you are interested in learning more.

Thanks

---

<div class="post-metadata">

**Author:** ![callum.katene](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/callum.katene/32/31881_2.png) [@callum.katene](https://devforum.zoom.us/u/callum.katene)\
**Post date:** [June 7, 2022, 9:46pm UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974/7 "2022-06-07T21:46:25Z")

</div>

I would like to learn more. Can’t see how to DM unfortunately - still a little new to this.

What’s the best way to contact you?

Thanks,

---

<div class="post-metadata">

**Author:** ![ojus.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ojus.zoom/32/734_2.png) [@ojus.zoom](https://devforum.zoom.us/u/ojus.zoom)\
**Post date:** [June 14, 2022, 11:54pm UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974/8 "2022-06-14T23:54:12Z")

</div>

@callum.katene sorry for the delay here. We will be sending more info regarding WebSockets Beta soon

---

<div class="post-metadata">

**Author:** ![callum.katene](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/callum.katene/32/31881_2.png) [@callum.katene](https://devforum.zoom.us/u/callum.katene)\
**Post date:** [June 15, 2022, 1:03am UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974/9 "2022-06-15T01:03:33Z")

</div>

That would be great, thanks. WebSockets offers significant advantages, so looking forward to doing more with this.

---

<div class="post-metadata">

**Author:** ![ojus.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ojus.zoom/32/734_2.png) [@ojus.zoom](https://devforum.zoom.us/u/ojus.zoom)\
**Post date:** [June 21, 2022, 8:42pm UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974/10 "2022-06-21T20:42:54Z")

</div>

Hi @callum.katene

Please fill out [this form](https://docs.google.com/forms/d/1wJ2AJs3INMFxn7p5XVTwzXbJscgpHMiNx2EDIQ7satY/edit?ts=62acdd1d) if you are interested in the websockets beta. Thank you for your patience

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [July 22, 2022, 6:43am UTC](https://devforum.zoom.us/t/webhooks-server-to-server-oauth-websocket-fails-to-connect/69974/11 "2022-07-22T06:43:28Z")

</div>

Closed on July 22, 2022, 6:43am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
