# WebHook: What am I doing wrong? Ruby

**URL:** <https://discuss.dev.twitch.com/t/webhook-what-am-i-doing-wrong-ruby/14847>\
**Category:** API\
**Created:** [March 20, 2018, 9:00am UTC](https://discuss.dev.twitch.com/t/webhook-what-am-i-doing-wrong-ruby/14847 "2018-03-20T09:00:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kallelundgren93](https://avatars.discourse-cdn.com/v4/letter/k/b5ac83/32.png) [@kallelundgren93](https://discuss.dev.twitch.com/u/kallelundgren93)\
**Post date:** [March 20, 2018, 9:00am UTC](https://discuss.dev.twitch.com/t/webhook-what-am-i-doing-wrong-ruby/14847/1 "2018-03-20T09:00:19Z")

</div>

Hi guys, currently I have this code:

```
class TwitchService
  TWITCH_ENDPOINT = URI.parse("https://api.twitch.tv/helix/webhooks/hub")

  class << self
    def subscribe_user_events(user_id, callback_url)
      data = {
        "hub.mode": :subscribe,
        "hub.topic": "https://api.twitch.tv/helix/streams?user_id=#{user_id}",
        "hub.callback": "#{callback_url}",
        "hub.lease_seconds": 864000,
        "hub.secret": "234"
        }

      response_body = post(data.to_json)
    end

    def post(body)
      connection = get_connection
      request = Net::HTTP::Post.new(TWITCH_ENDPOINT)
      request.content_type = "application/json"
      request["Client-ID"] = "thisexistsbutnotshowingit"
      request.body = body
      connection.request(request).body
    end

    # Return a connection against Twitchs servers
    def get_connection
      https = Net::HTTP.new(TWITCH_ENDPOINT.host, TWITCH_ENDPOINT.port)
      https.use_ssl = true
      https.read_timeout = 1000
      https.verify_mode = OpenSSL::SSL::VERIFY_NONE
      https
    end
  end
end

```

If i unset for example hub.topic, I get this:  
`"{\"error\":\"Bad Request\",\"status\":400,\"message\":\"hub.topic is required\"}"`

Which is how it should be, but when i’m sending it correctly i’m expecting a:  
`202 Accepted || 200 ok`

But I don’t get any response, so what have I’ve done wrong? I’m not so experienced, so hoping it’s just a small newbie mistake somewhere.

EDIT:  
Added https.set\_debug\_output($stdout) in my def get\_connection and get the 202 response:

```
-> "HTTP/1.1 202 Accepted\r\n"
```

---

<div class="post-metadata">

**Author:** ![Dist](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/dist/32/7192_2.png) [@Dist](https://discuss.dev.twitch.com/u/Dist)\
**Post date:** [March 20, 2018, 11:37am UTC](https://discuss.dev.twitch.com/t/webhook-what-am-i-doing-wrong-ruby/14847/2 "2018-03-20T11:37:29Z")

</div>

So you are getting a 202 on the initial subscription request, do you then have a handler set up for Twitch’s GET request to your callback URL that’ll deal with the subscription verification and respond with the challenge?

---

<div class="post-metadata">

**Author:** ![kallelundgren93](https://avatars.discourse-cdn.com/v4/letter/k/b5ac83/32.png) [@kallelundgren93](https://discuss.dev.twitch.com/u/kallelundgren93)\
**Post date:** [March 20, 2018, 12:04pm UTC](https://discuss.dev.twitch.com/t/webhook-what-am-i-doing-wrong-ruby/14847/3 "2018-03-20T12:04:40Z")

</div>

Working on that now, but got stuck on this because I missed to add `.set_debug_output`. So I was expecting a response, but wasn’t recieving it. When I finish up the subscription request (with verification) and worker for renewing the subscription when it’s about to run out. I will write a new post in this thread with my full implementation, and it maybe can help someone else!

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [April 19, 2018, 12:04pm UTC](https://discuss.dev.twitch.com/t/webhook-what-am-i-doing-wrong-ruby/14847/4 "2018-04-19T12:04:43Z")

</div>

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