# Rancher API wss connection

**URL:** <https://forums.suse.com/t/rancher-api-wss-connection/2902>\
**Category:** Rancher 1.x\
**Created:** [May 24, 2016, 10:22pm UTC](https://forums.suse.com/t/rancher-api-wss-connection/2902 "2016-05-24T22:22:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashos](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@ashos](https://forums.suse.com/u/ashos)\
**Post date:** [May 24, 2016, 10:22pm UTC](https://forums.suse.com/t/rancher-api-wss-connection/2902/1 "2016-05-24T22:22:24Z")

</div>

Hi

I’ve been playing with the Rancher API- Im sending a command to a container to execute some commands in the shell.

I get back my response from the API:  
“url”: “wss://XXX.XX.XXX.132:9998/v1/exec/”,  
“token”: \<\>

I then understand, for the commands I have sent to be executed on the container I need to connect with WSS. Here are where my problems start.

Im trying to use a WSS client using the following syntax:  
wss://URL/v1/exec/?token=token\_From\_api\_call

Which is just giving me errors in all the clients I try- I’ve even tried using the request that I captured the Rancher UI and I still cant connect.

Does it look like Im doing anything wrong? I can open a shell in Rancher UI and see Status Code:101 Switching Protocols if I have chrome developer tools open

Also does anyone happen to have an example of using cUrl to connect to the WSS address?

Many thanks in advanced

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [May 25, 2016, 5:43am UTC](https://forums.suse.com/t/rancher-api-wss-connection/2902/2 "2016-05-25T05:43:19Z")

</div>

curl doesn’t really support websockets… If you have nodejs installed `npm install -g wscat` is an easy client:

`wscat -n wss://xxx.xx.xxx.132:9998/v1/exec?token=longstringoftoken`

Since you’re getting back wss:// you must have SSL setup, but you have an IP address rather than a hostname. So any certificate check is going to fail, and my guess is your client is requiring that the certificate match. (ignoring that is what `-n` does for `wscat`)

---

<div class="post-metadata">

**Author:** ![ashos](https://avatars.discourse-cdn.com/v4/letter/a/858c86/32.png) [@ashos](https://forums.suse.com/u/ashos)\
**Post date:** [May 25, 2016, 9:30am UTC](https://forums.suse.com/t/rancher-api-wss-connection/2902/3 "2016-05-25T09:30:33Z")

</div>

Hi Vincent

Thanks for getting back to me.

Yes I do have SSL setup with a self signed cert.

I’ve installed wscat and tried  
wscat -c -n wss://XXX.XX.XXX.XXX:9998/v1/exec?token=token\_string

Which gives me  
error: Error: unexpected server response (401)

Does the token string need to be base 64 encoded?

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [May 25, 2016, 4:54pm UTC](https://forums.suse.com/t/rancher-api-wss-connection/2902/4 "2016-05-25T16:54:39Z")

</div>

No it’s just the same token from the previous response. 401 is unauthorized; the tokens are only good for 5 minutes, so you need to generate and use it fairly quickly. And the time on the rancher/server and the host that is running the container you’re connecting to need to be approximately accurate.
