1

We've discovered cartodb and we want to use it in our project, but in the API documentation we've only seen the sql.execute() method (docs) in order to insert a now row in a table.

Is this the way to insert points dynamically in our map?

1 Answer 1

1

You can't execute write queries from the javascript client code, in order to insert a point in a table you need to write your own backend server, like:

http://{account}.cartodb.com/api/v2/sql?q=INSERT INTO test_table (column_name, column_name_2, the_geom) VALUES ('this is a string', 11, ST_SetSRID(ST_Point(-110, 43),4326))&api_key={Your API key}

or use postgres functions with security definers:

http://blog.cartodb.com/post/53510434258/read-and-write-to-cartodb-with-the-leaflet-draw-plugin

3
  • Hi Javi, thanks for your answer. But if I invoke correctly this API url you're giving to me with $.ajax.post() for example, I would be invoking a write query from my javasript client code, wouldn't I? :-)
    – josal
    Commented Apr 29, 2014 at 8:52
  • @josal If you do that from client side you will expose the api_key to everyone and that's something you don't want to do (except really special cases) Commented Apr 29, 2014 at 13:26
  • It's true. So, the process would be to do this call from my backend, perfect. Now I understand. developers.cartodb.com/documentation/sql-api.html. Thanks!
    – josal
    Commented Apr 29, 2014 at 15:23

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.