# How to use Rancher 2 WebSocket API?

**URL:** <https://forums.suse.com/t/how-to-use-rancher-2-websocket-api/11053>\
**Category:** SUSE Rancher Prime\
**Created:** [July 9, 2018, 8:46am UTC](https://forums.suse.com/t/how-to-use-rancher-2-websocket-api/11053 "2018-07-09T08:46:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![michielkempen](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/michielkempen/32/4272_2.png) [@michielkempen](https://forums.suse.com/u/michielkempen)\
**Post date:** [July 9, 2018, 8:46am UTC](https://forums.suse.com/t/how-to-use-rancher-2-websocket-api/11053/1 "2018-07-09T08:46:48Z")

</div>

Hi there

Rancher 2 is amazing, but unfortunately, for now, it lacks some documentation. As a complete newcomer to the world of Rancher, this can be a real hassle. For the past few hours I have been trying to interact with the WebSocket API, but with no luck. There are a handful of articles on this topic available on the internet, but they all cover version 1 of the Rancher API.

It would be really helpful if someone here could give me a little more insight in how the WebSocket API works, how authentication is performed, and which endpoints can be consumed.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![cjellick](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/cjellick/32/2876_2.png) [@cjellick](https://forums.suse.com/u/cjellick)\
**Post date:** [July 9, 2018, 4:58pm UTC](https://forums.suse.com/t/how-to-use-rancher-2-websocket-api/11053/2 "2018-07-09T16:58:24Z")

</div>

Hi,

What are you trying to accomplish with the websocket API? What endpoint are you trying to hit?

/Craig

---

<div class="post-metadata">

**Author:** ![michielkempen](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/michielkempen/32/4272_2.png) [@michielkempen](https://forums.suse.com/u/michielkempen)\
**Post date:** [July 9, 2018, 5:24pm UTC](https://forums.suse.com/t/how-to-use-rancher-2-websocket-api/11053/3 "2018-07-09T17:24:34Z")

</div>

Hi Craig

Thanks for replying!

My goal is to listen to the `resource.change` events sent over de WebSocket API, in order to dynamically update a 3rd-party JavaScript client. The endpoint I’m trying to hit is `/v3/subscribe`.

---

<div class="post-metadata">

**Author:** ![alfrye](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@alfrye](https://forums.suse.com/u/alfrye)\
**Post date:** [December 6, 2018, 3:19pm UTC](https://forums.suse.com/t/how-to-use-rancher-2-websocket-api/11053/4 "2018-12-06T15:19:30Z")

</div>

Did you ever get this issue resolved? I am also trying to use the Rancher 2.0 websocket API and was able to a connection but after a few a little while I am getting a socket closed with error 1006. I also noticed that the rancher ui is using web sockets as well and when I look at the request from the chrome dev tools it appears that the many ws connections are happening to url `/v3/subscribe?socketId=x’

do you know what the socketId is used for?

Alan

---

<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:** [December 6, 2018, 4:05pm UTC](https://forums.suse.com/t/how-to-use-rancher-2-websocket-api/11053/5 "2018-12-06T16:05:10Z")

</div>

There’s not really much to this… You connect and start receiving change event objects.

Authentication is the same as the rest of the API, token in the `Authorization` header as basic or bearer (or `R_SESS` cookie instead, which the UI uses for all auth, your can’t set arbitrary headers in the browser ws client).

`/v3/subscribe` is for global level things (e.g. projects and clusters themselves)  
`/v3/clusters/<id>/subscribe` for cluster level things (e.g. nodes)  
`/v3/projects/<id>/subscribe` for project level things (e.g. workloads)

`socketId` is used by the UI to keep track of the connections and has no meaning to you or the server. It’s just a counter that goes up each time a websocket is opened.
