Question

Queries#post endpoint only returning "400 Bad Request"

  • 27 October 2016
  • 3 replies
  • 226 views

I am trying to run a query using the API and no matter what I do I cannot seem to get anything but a 400 response back. Even sending an empty body (which the API docs says is optional) still gives me a 400.


Here are the params I am sending in the post body:


{
"id"=>4253,
"view"=>"product",
"fields"=>["product.count", "product.type", "product.firstseen_hour"],
"pivots"=>["product.type"], "filters"=>{"date"=>"product.firstseen_date"},
"filter_expression"=>nil, "sorts"=>["product.type", "product.firstseen_hour desc"],
"limit"=>"500", "column_limit"=>"50", "total"=>nil, "row_total"=>nil,
"runtime"=>1.4479999542236328, "vis_config"=>{"stacking"=>"normal",
"show_value_labels"=>false, "label_density"=>25, "legend_position"=>"center",
"x_axis_gridlines"=>false, "y_axis_gridlines"=>true, "show_view_names"=>true,
"limit_displayed_rows"=>false, "y_axis_combined"=>true, "show_y_axis_labels"=>true,
"show_y_axis_ticks"=>true, "y_axis_tick_density"=>"default",
"y_axis_tick_density_custom"=>5, "show_x_axis_label"=>true, "show_x_axis_ticks"=>true,
"x_axis_scale"=>"auto", "y_axis_scale_mode"=>"linear", "ordering"=>"none",
"show_null_labels"=>false, "show_totals_labels"=>true, "show_silhouette"=>false,
"totals_color"=>"#808080", "show_null_points"=>true, "point_style"=>"none",
"interpolation"=>"linear", "type"=>"looker_column", "series_types"=>{},
"column_spacing_ratio"=>"", "column_group_spacing_ratio"=>"",
"colors"=>"palette: Default", "series_colors"=>{}, "hide_legend"=>true},
"visible_ui_sections"=>"data,fields", "slug"=>"<redacted>", "dynamic_fields"=>nil,
"client_id"=>"<redacted>", "share_url"=>"https://<redacted>.looker.com/x/9C7nNR6",
"expanded_share_url"=>"https://<redacted>.looker.com/explore/<redacted>/product?fields=product.count,product.type,product.firstseen_hour&pivots=product.type&sorts=product.type,product.firstseen_hour+desc&limit=500&column_limit=50&query_timezone=America%2FLos_Angeles&vis=%7B%22stacking%22%3A%22normal%22%2C%22show_value_labels%22%3Afalse%2C%22label_density%22%3A25%2C%22legend_position%22%3A%22center%22%2C%22x_axis_gridlines%22%3Afalse%2C%22y_axis_gridlines%22%3Atrue%2C%22show_view_names%22%3Atrue%2C%22limit_displayed_rows%22%3Afalse%2C%22y_axis_combined%22%3Atrue%2C%22show_y_axis_labels%22%3Atrue%2C%22show_y_axis_ticks%22%3Atrue%2C%22y_axis_tick_density%22%3A%22default%22%2C%22y_axis_tick_density_custom%22%3A5%2C%22show_x_axis_label%22%3Atrue%2C%22show_x_axis_ticks%22%3Atrue%2C%22x_axis_scale%22%3A%22auto%22%2C%22y_axis_scale_mode%22%3A%22linear%22%2C%22ordering%22%3A%22none%22%2C%22show_null_labels%22%3Afalse%2C%22show_totals_labels%22%3Atrue%2C%22show_silhouette%22%3Afalse%2C%22totals_color%22%3A%22%23808080%22%2C%22show_null_points%22%3Atrue%2C%22point_style%22%3A%22none%22%2C%22interpolation%22%3A%22linear%22%2C%22type%22%3A%22looker_column%22%2C%22series_types%22%3A%7B%7D%2C%22column_spacing_ratio%22%3A%22%22%2C%22column_group_spacing_ratio%22%3A%22%22%2C%22colors%22%3A%22palette%3A+Default%22%2C%22series_colors%22%3A%7B%7D%2C%22hide_legend%22%3Atrue%7D&filter_config=%7B%7D&show=data%2Cfields&origin=share-expanded",
"query_timezone"=>"America/Los_Angeles", "model"=>"<redacted>"
}

I am sending the queries to this endpoint:


https://<redacted>.looker.com:19999/api/3.0/queries


The logs I see state roughly this:


RestClient.post "https://<redacted>.looker.com:19999/api/3.0/queries", 3426 byte(s) length, "Accept"=>"*/*", "Accept-Encoding"=>"gzip, deflate", "Authorization"=>"token <redacted>", "Content-Length"=>"3426", "Content-Type"=>"application/x-www-form-urlencoded", "User-Agent"=>"rest-client/2.0.0 (darwin15.6.0 x86_64) ruby/2.3.1p112"
# => 400 BadRequest | application/json 81 bytes
400 Bad Request

I can get existing queries just fine and do other queries like retrieving looks and dashboards. It’s simply this call that fails continually for me. Any help is greatly appreciated!


3 replies

This error was due to the fact that I was not converting my params hash into a json encoded string and so the Ruby rest-client gem was sending the data as a form submit. This is why it was giving a 400 error.

Userlevel 2

Glad you figured it out, and thanks for posting your resolution!


Which Ruby client are you using? (just curious)


Thanks,

-Danny

Hi Danny,

I wrote my own API client because it needed to integrate with an existing API we were already building and the official SDK remains unpublished for some reason and we could not get it to install through Bundler which is required by our continuous integration service.

Reply