I want to create a CartoDB viz where the where parameter in my SQL statement changes dynamically at runtime.

When I share my CartoDB viz from the dashboard, I can't help but notice the the SQL statement is passed as a URL var.

I thought that was an easy way to dynamically change the where clause. After playing around though, I found out that the parameter is ignored (and for good reason, to guard against SQL injection), though other parms like showing the title/desc and the ne/sw latlongs are processed.

So I'm now trying to create a viz using the CartoDB API.

But for some reason, I can't get the creating visualizations at runtime example to work.

  • could you include the relevant lines of code in your non-working example? Here it is working fine, cartodb.github.io/cartodb.js/examples/leaflet_multilayer.html Jan 15, 2014 at 15:12
  • as a side comment, SQL is not being accepted as a param because there could be more than one sublayer in the visualization so it's not possible to know to what layer apply it Jan 15, 2014 at 17:06
  • Thanks! RTFM. Didn't realize that the inline examples were just code fragments. Still, you may want to consider adding the inline example in GitHub as well.
    – jnatividad
    Jan 15, 2014 at 21:36

1 Answer 1


you can do easier with viz.json, taking this example (https://github.com/CartoDB/cartodb.js/blob/develop/examples/easy.html) as starting point you can do:

  cartodb.createVis('map', 'http://documentation.cartodb.com/api/v2/viz/2b13c956-e7c1-11e2-806b-5404a6a683d5/viz.json', {
  .done(function(vis, layers) {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.