Comments (7)
@Josmorsot is ocurring with POST requests. FYI: I'm using v1.4.5
executeSQL({
query: 'SELECT 1',
credentials,
connection: 'carto_dw',
})
from carto-react.
Related with #524. Fixed in #525
from carto-react.
✅ v1.4.4 released
from carto-react.
@Josmorsot I think is not resolved.
The problem ocurrs when is not include any queryParameters, function will include by default [], the evaluation will be true and this one will include queryParameters: '[]', in case queryParemeters will be false, null or undefined, evaluation will return undefined and this will be included in queryParamseters as queryParameters: undefined . Both cases will return error from API
Source: https://github.com/CartoDB/carto-react/blob/master/packages/react-api/src/api/SQL.js:
function createRequest({ credentials, connection, query, opts = {}, queryParameters = [] }) {
const { abortController, ...otherOptions } = opts;
const { apiVersion = API_VERSIONS.V2 } = credentials;
const rawParams = {
client: CLIENT,
q: query?.trim(),
...otherOptions,
queryParameters: queryParameters ? JSON.stringify(queryParameters) : undefined
};
[.....]
}
I think an approach could be:
/**
* Create an 'SQL query' request
* (using GET or POST request, depending on url size)
*/
function createRequest({ credentials, connection, query, opts = {}, queryParameters = null }) {
const { abortController, ...otherOptions } = opts;
const { apiVersion = API_VERSIONS.V2 } = credentials;
const rawParams = {
client: CLIENT,
q: query?.trim(),
...otherOptions,
...(queryParameters && {queryParameters: JSON.stringify(queryParameters)})
};
if (apiVersion === API_VERSIONS.V3) {
rawParams.access_token = credentials.accessToken;
} else if (apiVersion === API_VERSIONS.V1 || apiVersion === API_VERSIONS.V2) {
rawParams.api_key = credentials.apiKey;
}
const requestOpts = { ...otherOptions };
if (abortController) {
requestOpts['signal'] = abortController.signal;
}
// Get request
const urlParamsForGet = Object.entries(rawParams).map(([key, value]) =>
encodeParameter(key, value)
);
const getUrl = generateApiUrl({
credentials,
connection,
parameters: urlParamsForGet
});
if (getUrl.length < REQUEST_GET_MAX_URL_LENGTH) {
return getRequest(getUrl, requestOpts);
}
// Post request
const urlParamsForPost =
apiVersion === API_VERSIONS.V3
? [`access_token=${credentials.accessToken}`, `client=${CLIENT}`]
: null;
const postUrl = generateApiUrl({
credentials,
connection,
parameters: urlParamsForPost
});
return postRequest(postUrl, rawParams, requestOpts);
}
from carto-react.
Hi @jantolg, is occurring with request through GET or POST? Can you share an example?
from carto-react.
I've just tried with:
executeSQL({
query: 'SELECT 1',
credentials,
connection: 'bqconn',
});
CURL => curl 'https://gcp-us-east1.api.carto.com/v3/sql/bqconn/query?client=carto-react&q=SELECT%201&queryParameters=%5B%5D&access_token=<TOKEN>' \ -H 'authority: gcp-us-east1.api.carto.com' \ -H 'accept: application/json' \ -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \ -H 'cache-control: no-cache' \ -H 'origin: https://127.0.0.1:3000' \ -H 'pragma: no-cache' \ -H 'referer: https://127.0.0.1:3000/' \ -H 'sec-ch-ua: "Google Chrome";v="107", "Chromium";v="107", "Not=A?Brand";v="24"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'sec-ch-ua-platform: "macOS"' \ -H 'sec-fetch-dest: empty' \ -H 'sec-fetch-mode: cors' \ -H 'sec-fetch-site: cross-site' \ -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36' \ --compressed
It works fine for me (with v1.4.5 and v1.4.6). Can you try to reproduce with latest version and share a curl or create a repo with an example?
from carto-react.
Fixed in v1.4.7
from carto-react.
Related Issues (20)
- FormulaWidget issue with mode global disabled HOT 14
- [RFC] Add a territory selector widget HOT 3
- [RFC] Save custom geometries created with the SpatialFilter HOT 2
- [RFC] Support for Drop a Pin HOT 3
- [RFC] Support for multi-language HOT 3
- [RFC] Comparative Widgets HOT 5
- [RFC] Save the state of the filters HOT 3
- [RFC] Spatial Filter HOT 11
- GeoJSON support in useCartoLayerProps HOT 1
- Remote executeModel doesn't work for POST requests HOT 4
- quadbinZoom error HOT 2
- Hygen is not working HOT 3
- [RFC] Widget size control HOT 1
- [RFC] Export AnimatedNumber component HOT 1
- [Bug] BarWidgetUI
- [RFC] Site Selection - Information element for widgets
- executeSQL function doesn't return the status error
- Allow passing decimal precision as a prop for CategoryWidgetUI HOT 4
- [Bug] ComparativeCategoryWidgetUI progress bar missing background color
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from carto-react.