Developer Blog

API - Creating a Forum

in API

A recent question to our support was how to use 2-legged OAuth to create a new forum, so as the first in a series of api examples here is some code to do exactly that:

#! /usr/bin/env ruby

require 'rubygems'
require "oauth"
require 'json'

# Trusted Client
KEY = 'CLIENT KEY'
SECRET = 'CLIENT SECRET'
SITE = 'http://your_subdomain.uservoice.com'

consumer = OAuth::Consumer.new(KEY, SECRET, :http_method => :post)
access_token = OAuth::AccessToken.new consumer

forum = {
  "forum[name]" => 'Exciting New Stuff'
}

response = access_token.post("#{SITE}/api/v1/forums.json", forum)
forum_hash = JSON.parse(response.body)

puts forum_hash.inspect

And that, as they say, is that!!! Simple huh?

~ Scott

Like us on Facebook Join us on Google+
blog comments powered by Disqus
product screenshot

Create a UserVoice account

Discover how easy it can be to provide great customer service

Try it for free