I have successfully installed CartoDB in Ubuntu 14.04 LTS and uploaded a point geometry dataset. I have created a HTML/JS application to access the layers from the local cartodb and visualize in the leaflet client application using cartodb.createLayer.

I need to display a chart by using the data from the uploaded layer. When I try using CartoDB SQL API, I get the CORS error. The details are below.

Can you let me know whether we need to include any configuration for CORS in local cartoDB?


$.getJSON('http://development.localhost.lan:3000/api/v2/sql?q=SELECT * FROM tablename & api_key = 1a77a491a96dff1c380fc869498587db105c5b65', function(data) {
  $.each(data.rows, function(key, val) {
    // do something!


Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://development.localhost.lan:3000/api/v2/sql?q=SELECT%20*%20FROM%20%22qgis_view_standard_all_permits_processed_current%22%20&%20api_key%20=%201a77a491a96dff1c380fc869498587db105c5b65. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).


The problem got resolved. The actual error was 2 things as described below.

Error 1 : The URL for accessing SQL API was wrong. The Correct URL is "http://development.localhost.lan:8080/api/v1/sql"

Error 2 : The access to the dataset was private. When I change to "public" I could access the query result.

But I am not sure why the private dataset is not accessible even though I give api_key along with the query

  • Hi Dinesh, do you mind marking the issue then as solved? – Jorge Sanz Feb 12 '18 at 9:18

The SQL API works for private dataset too when the api_key is sent along with the URL without any spaces in the URL as below.

http://development.localhost.lan:8080/api/v2/sql?q=SELECT * FROM tablename&api_key=1a77a491a96dff1c380fc869498587db105c5b65

Another option to circumvent CORS errors in a local installation is to use domainless URLs like http://local-installation/user/username/: https://cartodb.readthedocs.io/en/latest/configuration.html#domainless-urls If the cartoDB and the webserver can share the same hostname and port.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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