Skip to content

Instantly share code, notes, and snippets.

Last active Apr 27, 2016
What would you like to do?
Using the UserVoice API v2 with a trusted client
require 'net/http'
require 'json'
# For now you must use a trusted API client, never place your API credentials
# for a trusted client in an insecure location. Especially not in JavaScript on
# the client side.
client_key = "YOUR_API_CLIENT_KEY"
client_secret = "YOUR_API_CLIENT_SECRET"
host = ""
# Get an OAuth token
uri = URI("https://#{host}/api/v2/oauth/token")
req =
grant_type: 'client_credentials',
client_id: client_key,
client_secret: client_secret,
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) {|http|
token = JSON.parse(res.body)['access_token']
# Make your request
uri = URI("https://#{host}/api/v2/admin/users/current")
req =
req['Authorization'] = "Bearer #{token}"
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) {|http|
http.use_ssl = true
puts res.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment