I’ve been following the tutorials available here http://132.72.155.230:3838/js/databases.html which show you have to set up a database in carto 2 and query it using sql requests. It seems simple enough to build a url that deal with the desired query.
Unfortunately carto2 has now changed to carto workplace (carto3), https://carto.com/ and whilst there still seems to be a carto api the documentation is complicated, with references to connections, access tokens ect. In spite of two attempts I’ve not been able to get my old sql queries running again.
Obviously I’m a beginner with post GIS but is someone with more experience able to tell me whether the simple functionality of carto2 is gone? you used to be able to simply upload a geojson database and easily query it with sql.
For example the below code used to pull a list of plans from a database in carto2
let carto_user = "michaeldorman";
let url = "https://" + carto_user+.carto.com/api/v2/sql?format=GeoJSON&q=";
let sqlQuery = "SELECT name_lat, the_geom FROM plants LIMIT 25";
fetch(url + sqlQuery)
.then(function(response) {
return response.json();
})
.then(function(data) {
L.geoJSON(data, {
onEachFeature: function(feature, layer) {
layer.bindPopup(feature.properties.name_lat);
}
}).addTo(map);
});
And should replaced in carto 3 by something like the following?:
var requestOptions = {
method: 'GET',
redirect: 'follow'
};
fetch("https://gcp-us-east1.api.carto.com/v3/sql/carto_dw/query?q=select * from carto-dw-ac-qesubrab.shared.plants ", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
The issue seems to be that the new code doesn’t define the user name and generates an error relating to a token:
“{"error":"Token not defined!","status":401,"message":"Token not defined!","originalError":{}“
Is there really no way to just upload the data and start doing sql queries on it anymore?