Script for Importing Feedback with UserVoice Admin API

Any interaction with the UserVoice Admin API requires a trusted API client. You can create one by following this guide.

Creating the Script

Create a Ruby file with the following, substituting your own data at the top. This example is in Ruby, however you can use any language of your choice to achieve the same result.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'net/http'
require 'net/https'
require 'json'

# Change 'feedback' to the name of your UserVoice subdomain (leaving the quotes)
subdomain = "feedback"
# Change "xxxe8ae9c6a3c039" to the bearer token you received in step 1 (leaving the quotes)
token = "xxxe8ae9c6a3c039"

# Put your data into a json object with fields matching this example
# The body and user email fields are required
feedback = {
  "body": "UserVoice is great, it helps me understand our customers needs perfectly!", # Required
  "user": {
    "email": "carterjackson@gmail.com",   # Required
    "name": "Carter Jackson"
  },
}

uri = URI.parse("https://#{subdomain}.uservoice.com/api/v2/admin/feedback_records")

response = Net::HTTP.post(uri, feedback.to_json, "Content-Type" => "application/json", "Authorization" => "Bearer #{token}")
body = JSON.parse(response.body)
if response.code == "200"
  puts "Success"
  puts "Response Code: 200"
  puts "id: #{ body['feedback_records'][0]['id'] }"
else
  puts "Failure"
  puts "Response Code: #{ response.code }"
  if response.code == '422'
    puts "Missing #{ body['errors'].keys.first }"
  elsif response.code == '401'
    puts "Invalid API token"
  end
end

Running the Script

You can now run the script! It should import your feedback into UserVoice for later use. The output will show the status of the import.

For a successful import, you will see the following output containing the ID of your new feedback record:

1
2
3
Success
Response Code: 200
id: 194823

For an unsuccessful import, you will see output showing what went wrong.

The following would indicate that the record did not include a body:

1
2
3
Failure
Response Code: 422
Missing body

If your API token is missing or incorrect, the response will resemble the following:

1
2
3
Failure
Response Code: 401
Invalid API token

Additional Information

For more complete documentation of the feedback_records endpoint, see the Admin API reference.

Didn’t find what you’re looking for?

Check out the UserVoice Help Center for more documentation.

Explore the Help Center