require 'net/http' require 'uri'

INSTANCEURL = 'http://try.discourse.org/t/online-learning/108.json' APIUSERNAME = 'YOURUSERNAME' APIKEY = 'YOURAPIKEY'

def send_request

url = URI.parse(INSTANCE_URL)
request = Net::HTTP::Put.new(url.path)
request.set_form_data({'api_username' => API_USERNAME, 'api_key' => API_KEY, 'category_id' => 5})
http = Net::HTTP.new(url.host, url.port)
response = http.request(request)

if response.code == '200'
  puts "Success!"
else
  puts "Error"
end

end

send_request

This post is also available on DEV.