Your curl
command has a Content-Type set. None of the Ruby code you posted has that.
I'm guessing the app cannot detect and parse the JSON given to it.
Question
So, if I execute the following command, it works fine:
curl -X POST --compressed -H "Content-Type:application/json" \
-H 'x-api-user: USER_ID' \
-H 'x-api-key: API_TOKEN' \
-d '{"text":"from the api!","type":"todo"}' \
https://habitrpg.com/api/v1/user/task
I tried getting HTTParty to work, but their documentation on compressed connections is basically non-existent at my level of understanding. I have tried NET/HTTP and I can establish a connection, but the API keeps giving me errors that my data is wrong (it says I haven't given it a valid type). Here is the code I am using:
data = {:text => "from the app dog", :type => "todo"}
uri = URI.parse("https://habitrpg.com/api/v1/user/task")
http = Net::HTTP.new(uri.host, uri.port)
http.set_debug_output($stdout)
http.use_ssl = true
resp = http.post(uri.request_uri, data, {"x-api-user" => USER_ID, "x-api-key" => API_TOKEN})
resp.body
I have also tried all of the following for the data:
data = {:text => "from the app dog", :type => "todo"}.to_json.to_s
data = "{\"text\":\"from the app dog\",\"type\":\"todo\"}"
data = "'" + "{\"text\":\"from the app dog\",\"type\":\"todo\"}" + "'"
And probably three or four other things that I can't identify anymore. Does anyone have any suggestions? I am at a total loss.
Solution
Your curl
command has a Content-Type set. None of the Ruby code you posted has that.
I'm guessing the app cannot detect and parse the JSON given to it.