0

I'm writing to Uservoice articles via API. I write using following code:

    data = {
      :article =>
        {
          :question => question_name,
          :answer_html => html,
          :published => true
        }
    }

    site = "http://myapp.uservoice.com"

    puts "Remote site = #{site}"
    consumer = OAuth::Consumer.new(APP_CONFIG["uservoice"]["key"],
      APP_CONFIG["uservoice"]["secret"],
      {:site => site})

    accesstoken = OAuth::AccessToken.new(consumer,
     user.helpdesk["uservoice"]["oauth_token"],
     user.helpdesk["uservoice"]["oauth_token_secret"])

    response = JSON.parse(accesstoken.post("/api/v1/articles.json", data).body)
    flow.uservoice_id = response['article']['id']
    flow.save!
    puts "Save successful at #{response['article']['url']}"

This works. But when I want to do an update i.e PUT,

    response = JSON.parse(accesstoken.put("/api/v1/articles/#{article_id}.json", data))

I get a

{"errors"=>{"type"=>"unauthorized", "message"=>"Admin required: Not signed or not admin. Unverified; Signature verification failed; User not signed: oauthenticate failed"}}

As response. I am an admin as well. Writing (POST) works, but updating doesn't.

Kevin Campion
  • 2,223
  • 2
  • 23
  • 29
Alagu
  • 2,864
  • 3
  • 26
  • 40

1 Answers1

0

Don't forget to log in as an admin (or owner).

accesstoken.login_as_owner do |owner|
  posted_response = owner.post("/api/v1/articles/#{article_id}.json", data)
end

Look the section "Get the access token of the account owner and post responses" at https://developer.uservoice.com/docs/api/ruby-sdk/

Kevin Campion
  • 2,223
  • 2
  • 23
  • 29