I'm trying to do a simple post request with Ruby and net/http but it keeps throwing the same error, here's my code:
require 'uri'
require 'net/http'
data = {
fields: {
"Video Title" : "Top 10 funniest videos of 2022"
}
}
uri = URI(https.....)
headers = {
'Authorization': 'xxxxx',
'Content-Type': 'application/json'
}
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
response = http.post(uri.path, URI.encode_www_form((data), headers)
puts response.body
# {"error":{"type":"INVALID_REQUEST_BODY", "message":"Could not parse request"}}
I've tried a bunch of things from google including downloading Ruby air table gems but they always throw the same error, I have a hunch that the object is not properly structured, If I send an empty object I get a different error:
data = {}
....
response = http.post(uri.path, URI.encode_www_form((data), headers)
puts response.body
# {"error":{"type":"INVALID_REQUEST_MISSING_IELDS", "message":"Could not find field \\"fields\\" in the request body"}}
I've also tried adding typecast:true but still doesn't work, google says it's a pretty common error so I've tried a lot of solutions that I've found online but nothing seems to work.