Help

iNVALID_REQUEST_BODY with ruby

Topic Labels: API
2657 2
cancel
Showing results for 
Search instead for 
Did you mean: 
ahzep1790
4 - Data Explorer
4 - Data Explorer

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.

2 Replies 2
goksan
6 - Interface Innovator
6 - Interface Innovator

Hi @ahzep1790 👋

I'm not super familiar with Ruby but it looks like you're URI encoding rather than serializing as JSON string.

Thank you, I changed to JSON and still getting a different error:

 

{"error":{"type":"INVALID_REQUEST_UNKNOWN","message":"Invalid request: parameter validation failed. Check your request data."}}

But in the end, I've fixed it by downloading HTTParty which lets me do requests with no issues, thanks eitherway!