WebHook: What am I doing wrong? Ruby

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"

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?

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!

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