3

I'm working with the Buffer App API with HTTParty to try and add posts via the /updates/create method, but the API seems to ignore my "text" parameter and throws up an error. If I do it via cURL on the command line it works perfectly. Here's my code:

class BufferApp
    include HTTParty
    base_uri 'https://api.bufferapp.com/1'

    def initialize(token, id)
        @token = token
        @id = id
    end

    def create(text)
        BufferApp.post('/updates/create.json', :query =>  {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
    end 
end

And I'm running the method like this:

BufferApp.new('{access_token}', '{profile_id}').create('{Text}')

I've added debug_output $stdout to the class and it seems to be posting OK:

POST /1/updates/create.json?text=Hello%20there%20why%20is%20this%20not%20working%3F&profile_ids[]={profile_id}&access_token={access_token} HTTP/1.1\r\nConnection: close\r\nHost: api.bufferapp.com\r\n\r\n"

But I get an error. Am I missing anything?

Pezholio
  • 2,439
  • 5
  • 27
  • 41
  • Not all error messages are alike. They usually contain at least a hint of what the problem is, and sometimes spell it out completely. In other words, please provide it. – Mark Thomas Feb 16 '12 at 11:57
  • Ah, OK, here you go: `"{\"success\":false,\"message\":\"Nice try, but you need to write something!\",\"code\":1004}"` This is an API error, rather than a HTTP one obviously – Pezholio Feb 16 '12 at 12:00

1 Answers1

19

I reviewed the API, and the updates expect the JSON to be in the POST body, not the query string. Try :body instead of :query:

    def create(text)
        BufferApp.post('/updates/create.json', :body => {"text" => text, "profile_ids[]" => @id, "access_token" => @token})
    end
Mark Thomas
  • 37,131
  • 11
  • 74
  • 101