How to filter returned rows when calling the Coda API

Hey there!

I am trying to use the “Filter query” as explained in the API docs, but with Javascript, but keep on running into errors.

Is anyone familiar on how to structure the “query” parameters inside of the URL?

The query at the end of the url is: “query=c-6euPSWeAb9:‘A113’”

My code currently looks like this:

function listSpecificRows(){
  $(document).ready(function() {
    $.ajax({
      url: "https://coda.io/apis/v1/docs/"+ WarehouseMapId + "/tables/" + TestTableId + "/rows" + "query=c-6euPSWeAb9:'A113'" ,
      type: "GET",
      headers: {"Authorization": 'Bearer TOKEN'},
      success: function(result) {
        console.log(result);
      },
      error: function(error) {
        console.log(error);
      }
    });
  });
};

Hey I found a solution for that the trick, is to build the data you want to add to your request in a string and then parse it to transform it in a json readable by the API. So in your case:

var token = ‘your token*’;

var keyColumn = ‘c-6euPSWeAb9’;
var filterValue = ‘A113’;

// the escape backslashes are here to make sure the parse is done the right way
var queryString = ‘{“query”:’ + ‘"’ + keyColumn + ‘:\"’ + filterValue + ‘\""}’;

var queryJson = JSON.parse(queryString );

function listSpecificRows(){
$(document).ready(function() {
$.ajax({
url: “https://coda.io/apis/v1/docs/”+ WarehouseMapId + “/tables/” + TestTableId + “/rows”
type: “GET”,
headers: {“Authorization”: 'Bearer '+ token},
data: queryJson,
success: function(result) {
console.log(result);
},
error: function(error) {
console.log(error);
}
});
});
};

You see the idea it’s not optimal but that’s the only thing that works for me.
if you want to hard code it thought you need a json that looks like that:

{“query”:“c-6euPSWeAb9: ‘A113’”}

be sure to have the required number of quotes :slight_smile:

Best,

G.

Not sure if @Galdric_Fleury answer solved your issue, but looks to be an error in your code? If you are concatenating a URL you are still gonna need the “?” character before your first query param:

url: "https://coda.io/apis/v1/docs/"+ WarehouseMapId + "/tables/" + TestTableId + "/rows" + "?" + "query=c-6euPSWeAb9:'A113'"