commit
4ab2adc25e
@ -25,7 +25,7 @@ Using cURL tool:
|
|||||||
```bash
|
```bash
|
||||||
curl -X POST -H "Content-Type: application/json" -d '{
|
curl -X POST -H "Content-Type: application/json" -d '{
|
||||||
"query": "{query}"
|
"query": "{query}"
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job?api_key={api_key}"
|
}' "https://{username}.carto.com/api/v2/sql/job?api_key={api_key}"
|
||||||
```
|
```
|
||||||
|
|
||||||
Using Node.js request client:
|
Using Node.js request client:
|
||||||
@ -35,7 +35,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job",
|
url: "https://{username}.carto.com/api/v2/sql/job",
|
||||||
qs: {
|
qs: {
|
||||||
"api_key": "{api_key}"
|
"api_key": "{api_key}"
|
||||||
},
|
},
|
||||||
@ -124,7 +124,7 @@ If you are using the Batch Query create operation for a cURL POST request, use t
|
|||||||
```bash
|
```bash
|
||||||
curl -X POST -H "Content-Type: application/json" -d '{
|
curl -X POST -H "Content-Type: application/json" -d '{
|
||||||
"query": "CREATE TABLE world_airports AS SELECT a.cartodb_id, a.the_geom, a.the_geom_webmercator, a.name airport, b.name country FROM world_borders b JOIN airports a ON ST_Contains(b.the_geom, a.the_geom)"
|
"query": "CREATE TABLE world_airports AS SELECT a.cartodb_id, a.the_geom, a.the_geom_webmercator, a.name airport, b.name country FROM world_borders b JOIN airports a ON ST_Contains(b.the_geom, a.the_geom)"
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are using the Batch Query create operation for a Node.js client POST request, use the following code:
|
If you are using the Batch Query create operation for a Node.js client POST request, use the following code:
|
||||||
@ -134,7 +134,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job",
|
url: "https://{username}.carto.com/api/v2/sql/job",
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
body: {
|
body: {
|
||||||
query: "CREATE TABLE world_airports AS SELECT a.cartodb_id, a.the_geom, a.the_geom_webmercator, a.name airport, b.name country FROM world_borders b JOIN airports a ON ST_Contains(b.the_geom, a.the_geom)"
|
query: "CREATE TABLE world_airports AS SELECT a.cartodb_id, a.the_geom, a.the_geom_webmercator, a.name airport, b.name country FROM world_borders b JOIN airports a ON ST_Contains(b.the_geom, a.the_geom)"
|
||||||
@ -177,7 +177,7 @@ BODY: {
|
|||||||
If you are using the Batch Query read operation for a cURL GET request, use the following code:
|
If you are using the Batch Query read operation for a cURL GET request, use the following code:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X GET "http://{username}.carto.com/api/v2/sql/job/{job_id}"
|
curl -X GET "https://{username}.carto.com/api/v2/sql/job/{job_id}"
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are a Batch Query read operation for a Node.js client GET request, use the following code:
|
If you are a Batch Query read operation for a Node.js client GET request, use the following code:
|
||||||
@ -187,7 +187,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job/{job_id}"
|
url: "https://{username}.carto.com/api/v2/sql/job/{job_id}"
|
||||||
};
|
};
|
||||||
|
|
||||||
request(options, function (error, response, body) {
|
request(options, function (error, response, body) {
|
||||||
@ -238,7 +238,7 @@ errors: [
|
|||||||
If you are using the Batch Query cancel operation for cURL DELETE request, use the following code:
|
If you are using the Batch Query cancel operation for cURL DELETE request, use the following code:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X DELETE "http://{username}.carto.com/api/v2/sql/job/{job_id}"
|
curl -X DELETE "https://{username}.carto.com/api/v2/sql/job/{job_id}"
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are using the Batch Query cancel operation for a Node.js client DELETE request, use the following code:
|
If you are using the Batch Query cancel operation for a Node.js client DELETE request, use the following code:
|
||||||
@ -248,7 +248,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job/{job_id}",
|
url: "https://{username}.carto.com/api/v2/sql/job/{job_id}",
|
||||||
};
|
};
|
||||||
|
|
||||||
request(options, function (error, response, body) {
|
request(options, function (error, response, body) {
|
||||||
@ -317,7 +317,7 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
"DROP TABLE airports",
|
"DROP TABLE airports",
|
||||||
"ALTER TABLE world_airports RENAME TO airport"
|
"ALTER TABLE world_airports RENAME TO airport"
|
||||||
]
|
]
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are using the Chained Batch Query operation for a Node.js client POST request, use the following code:
|
If you are using the Chained Batch Query operation for a Node.js client POST request, use the following code:
|
||||||
@ -327,7 +327,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job",
|
url: "https://{username}.carto.com/api/v2/sql/job",
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
body: {
|
body: {
|
||||||
"query": [
|
"query": [
|
||||||
@ -358,7 +358,7 @@ curl -X PUT -H "Content-Type: application/json" -d '{
|
|||||||
"ALTER TABLE world_airports RENAME TO airport",
|
"ALTER TABLE world_airports RENAME TO airport",
|
||||||
"UPDATE airports SET airport = upper(airport)"
|
"UPDATE airports SET airport = upper(airport)"
|
||||||
]
|
]
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job/{job_id}"
|
}' "https://{username}.carto.com/api/v2/sql/job/{job_id}"
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are using the Chained Batch Query operation for a Node.js client PUT request, use the following code:
|
If you are using the Chained Batch Query operation for a Node.js client PUT request, use the following code:
|
||||||
@ -368,7 +368,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job/{job_id}",
|
url: "https://{username}.carto.com/api/v2/sql/job/{job_id}",
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
body: {
|
body: {
|
||||||
query: [
|
query: [
|
||||||
@ -405,7 +405,7 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
"onerror": "UPDATE market_status SET status = 'outdated' WHERE table_name = 'nasdaq'"
|
"onerror": "UPDATE market_status SET status = 'outdated' WHERE table_name = 'nasdaq'"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
If query finishes successfully, then onsuccess fallback will be fired. Otherwise, onerror will be fired. You can define fallbacks per query:
|
If query finishes successfully, then onsuccess fallback will be fired. Otherwise, onerror will be fired. You can define fallbacks per query:
|
||||||
@ -423,7 +423,7 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
"onerror": "UPDATE market_status SET status = 'outdated' WHERE table_name = 'down_jones'"
|
"onerror": "UPDATE market_status SET status = 'outdated' WHERE table_name = 'down_jones'"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
...at the job level..
|
...at the job level..
|
||||||
@ -439,7 +439,7 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
"onsuccess": "UPDATE market_status SET status = 'updated', updated_at = NOW()",
|
"onsuccess": "UPDATE market_status SET status = 'updated', updated_at = NOW()",
|
||||||
"onerror": "UPDATE market_status SET status = 'outdated'"
|
"onerror": "UPDATE market_status SET status = 'outdated'"
|
||||||
}
|
}
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
If a query of a job fails (and onerror fallbacks for that query and job are defined), then Batch Queries runs the first fallback for that query. The job fallback runs next and sets the job as failed. Remaining queries will not be executed. Furthermore, Batch Queries will run the onsuccess fallback at the job level, if (and only if), every query has finished successfully.
|
If a query of a job fails (and onerror fallbacks for that query and job are defined), then Batch Queries runs the first fallback for that query. The job fallback runs next and sets the job as failed. Remaining queries will not be executed. Furthermore, Batch Queries will run the onsuccess fallback at the job level, if (and only if), every query has finished successfully.
|
||||||
@ -461,7 +461,7 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
}],
|
}],
|
||||||
"onerror": "INSERT INTO errors_log (job_id, error_message, date) VALUES ('<%= job_id %>', '<%= error_message %>', NOW())"
|
"onerror": "INSERT INTO errors_log (job_id, error_message, date) VALUES ('<%= job_id %>', '<%= error_message %>', NOW())"
|
||||||
}
|
}
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
More templates are coming soon.
|
More templates are coming soon.
|
||||||
|
@ -25,7 +25,7 @@ Using cURL tool:
|
|||||||
```bash
|
```bash
|
||||||
curl -X POST -H "Content-Type: application/json" -d '{
|
curl -X POST -H "Content-Type: application/json" -d '{
|
||||||
"query": "{query}"
|
"query": "{query}"
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job?api_key={api_key}"
|
}' "https://{username}.carto.com/api/v2/sql/job?api_key={api_key}"
|
||||||
```
|
```
|
||||||
|
|
||||||
Using Node.js request client:
|
Using Node.js request client:
|
||||||
@ -35,7 +35,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job",
|
url: "https://{username}.carto.com/api/v2/sql/job",
|
||||||
qs: {
|
qs: {
|
||||||
"api_key": "{api_key}"
|
"api_key": "{api_key}"
|
||||||
},
|
},
|
||||||
@ -124,7 +124,7 @@ If you are using the Batch Query create operation for a cURL POST request, use t
|
|||||||
```bash
|
```bash
|
||||||
curl -X POST -H "Content-Type: application/json" -d '{
|
curl -X POST -H "Content-Type: application/json" -d '{
|
||||||
"query": "CREATE TABLE world_airports AS SELECT a.cartodb_id, a.the_geom, a.the_geom_webmercator, a.name airport, b.name country FROM world_borders b JOIN airports a ON ST_Contains(b.the_geom, a.the_geom)"
|
"query": "CREATE TABLE world_airports AS SELECT a.cartodb_id, a.the_geom, a.the_geom_webmercator, a.name airport, b.name country FROM world_borders b JOIN airports a ON ST_Contains(b.the_geom, a.the_geom)"
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are using the Batch Query create operation for a Node.js client POST request, use the following code:
|
If you are using the Batch Query create operation for a Node.js client POST request, use the following code:
|
||||||
@ -134,7 +134,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job",
|
url: "https://{username}.carto.com/api/v2/sql/job",
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
body: {
|
body: {
|
||||||
query: "CREATE TABLE world_airports AS SELECT a.cartodb_id, a.the_geom, a.the_geom_webmercator, a.name airport, b.name country FROM world_borders b JOIN airports a ON ST_Contains(b.the_geom, a.the_geom)"
|
query: "CREATE TABLE world_airports AS SELECT a.cartodb_id, a.the_geom, a.the_geom_webmercator, a.name airport, b.name country FROM world_borders b JOIN airports a ON ST_Contains(b.the_geom, a.the_geom)"
|
||||||
@ -180,7 +180,7 @@ BODY: {
|
|||||||
If you are using the Batch Query read operation for a cURL GET request, use the following code:
|
If you are using the Batch Query read operation for a cURL GET request, use the following code:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X GET "http://{username}.carto.com/api/v2/sql/job/{job_id}"
|
curl -X GET "https://{username}.carto.com/api/v2/sql/job/{job_id}"
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are a Batch Query read operation for a Node.js client GET request, use the following code:
|
If you are a Batch Query read operation for a Node.js client GET request, use the following code:
|
||||||
@ -190,7 +190,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job/{job_id}"
|
url: "https://{username}.carto.com/api/v2/sql/job/{job_id}"
|
||||||
};
|
};
|
||||||
|
|
||||||
request(options, function (error, response, body) {
|
request(options, function (error, response, body) {
|
||||||
@ -241,7 +241,7 @@ errors: [
|
|||||||
If you are using the Batch Query cancel operation for cURL DELETE request, use the following code:
|
If you are using the Batch Query cancel operation for cURL DELETE request, use the following code:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -X DELETE "http://{username}.carto.com/api/v2/sql/job/{job_id}"
|
curl -X DELETE "https://{username}.carto.com/api/v2/sql/job/{job_id}"
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are using the Batch Query cancel operation for a Node.js client DELETE request, use the following code:
|
If you are using the Batch Query cancel operation for a Node.js client DELETE request, use the following code:
|
||||||
@ -251,7 +251,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job/{job_id}",
|
url: "https://{username}.carto.com/api/v2/sql/job/{job_id}",
|
||||||
};
|
};
|
||||||
|
|
||||||
request(options, function (error, response, body) {
|
request(options, function (error, response, body) {
|
||||||
@ -320,7 +320,7 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
"DROP TABLE airports",
|
"DROP TABLE airports",
|
||||||
"ALTER TABLE world_airports RENAME TO airport"
|
"ALTER TABLE world_airports RENAME TO airport"
|
||||||
]
|
]
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are using the Chained Batch Query operation for a Node.js client POST request, use the following code:
|
If you are using the Chained Batch Query operation for a Node.js client POST request, use the following code:
|
||||||
@ -330,7 +330,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job",
|
url: "https://{username}.carto.com/api/v2/sql/job",
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
body: {
|
body: {
|
||||||
"query": [
|
"query": [
|
||||||
@ -361,7 +361,7 @@ curl -X PUT -H "Content-Type: application/json" -d '{
|
|||||||
"ALTER TABLE world_airports RENAME TO airport",
|
"ALTER TABLE world_airports RENAME TO airport",
|
||||||
"UPDATE airports SET airport = upper(airport)"
|
"UPDATE airports SET airport = upper(airport)"
|
||||||
]
|
]
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job/{job_id}"
|
}' "https://{username}.carto.com/api/v2/sql/job/{job_id}"
|
||||||
```
|
```
|
||||||
|
|
||||||
If you are using the Chained Batch Query operation for a Node.js client PUT request, use the following code:
|
If you are using the Chained Batch Query operation for a Node.js client PUT request, use the following code:
|
||||||
@ -371,7 +371,7 @@ var request = require("request");
|
|||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
url: "http://{username}.carto.com/api/v2/sql/job/{job_id}",
|
url: "https://{username}.carto.com/api/v2/sql/job/{job_id}",
|
||||||
headers: { "content-type": "application/json" },
|
headers: { "content-type": "application/json" },
|
||||||
body: {
|
body: {
|
||||||
query: [
|
query: [
|
||||||
@ -408,7 +408,7 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
"onerror": "UPDATE market_status SET status = 'outdated' WHERE table_name = 'nasdaq'"
|
"onerror": "UPDATE market_status SET status = 'outdated' WHERE table_name = 'nasdaq'"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
If query finishes successfully, then onsuccess fallback will be fired. Otherwise, onerror will be fired. You can define fallbacks per query:
|
If query finishes successfully, then onsuccess fallback will be fired. Otherwise, onerror will be fired. You can define fallbacks per query:
|
||||||
@ -426,7 +426,7 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
"onerror": "UPDATE market_status SET status = 'outdated' WHERE table_name = 'down_jones'"
|
"onerror": "UPDATE market_status SET status = 'outdated' WHERE table_name = 'down_jones'"
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
...at the job level..
|
...at the job level..
|
||||||
@ -442,7 +442,7 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
"onsuccess": "UPDATE market_status SET status = 'updated', updated_at = NOW()",
|
"onsuccess": "UPDATE market_status SET status = 'updated', updated_at = NOW()",
|
||||||
"onerror": "UPDATE market_status SET status = 'outdated'"
|
"onerror": "UPDATE market_status SET status = 'outdated'"
|
||||||
}
|
}
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
If a query of a job fails (and onerror fallbacks for that query and job are defined), then Batch Queries runs the first fallback for that query. The job fallback runs next and sets the job as failed. Remaining queries will not be executed. Furthermore, Batch Queries will run the onsuccess fallback at the job level, if (and only if), every query has finished successfully.
|
If a query of a job fails (and onerror fallbacks for that query and job are defined), then Batch Queries runs the first fallback for that query. The job fallback runs next and sets the job as failed. Remaining queries will not be executed. Furthermore, Batch Queries will run the onsuccess fallback at the job level, if (and only if), every query has finished successfully.
|
||||||
@ -464,7 +464,7 @@ curl -X POST -H "Content-Type: application/json" -d '{
|
|||||||
}],
|
}],
|
||||||
"onerror": "INSERT INTO errors_log (job_id, error_message, date) VALUES ('<%= job_id %>', '<%= error_message %>', NOW())"
|
"onerror": "INSERT INTO errors_log (job_id, error_message, date) VALUES ('<%= job_id %>', '<%= error_message %>', NOW())"
|
||||||
}
|
}
|
||||||
}' "http://{username}.carto.com/api/v2/sql/job"
|
}' "https://{username}.carto.com/api/v2/sql/job"
|
||||||
```
|
```
|
||||||
|
|
||||||
More templates are coming soon.
|
More templates are coming soon.
|
||||||
|
@ -4,8 +4,8 @@ Copy queries allow you to use the [PostgreSQL copy command](https://www.postgres
|
|||||||
|
|
||||||
The support for copy is split across two API end points:
|
The support for copy is split across two API end points:
|
||||||
|
|
||||||
* `http://{username}.carto.com/api/v2/sql/copyfrom` for uploading data to CARTO
|
* `https://{username}.carto.com/api/v2/sql/copyfrom` for uploading data to CARTO
|
||||||
* `http://{username}.carto.com/api/v2/sql/copyto` for exporting data out of CARTO
|
* `https://{username}.carto.com/api/v2/sql/copyto` for exporting data out of CARTO
|
||||||
|
|
||||||
### Copy From
|
### Copy From
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ Assuming that you have already created the table, and that the CSV file is named
|
|||||||
-H "Transfer-Encoding: chunked" \
|
-H "Transfer-Encoding: chunked" \
|
||||||
-H "Content-Type: application/octet-stream" \
|
-H "Content-Type: application/octet-stream" \
|
||||||
--data-binary @upload_example.csv \
|
--data-binary @upload_example.csv \
|
||||||
"http://{username}.carto.com/api/v2/sql/copyfrom?api_key={api_key}&q=COPY+upload_example+(the_geom,+name,+age)+FROM+STDIN+WITH+(FORMAT+csv,+HEADER+true)"
|
"https://{username}.carto.com/api/v2/sql/copyfrom?api_key={api_key}&q=COPY+upload_example+(the_geom,+name,+age)+FROM+STDIN+WITH+(FORMAT+csv,+HEADER+true)"
|
||||||
|
|
||||||
To upload a larger file, using compression for a faster transfer, first compress the file, and then upload it with the content encoding set:
|
To upload a larger file, using compression for a faster transfer, first compress the file, and then upload it with the content encoding set:
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ To upload a larger file, using compression for a faster transfer, first compress
|
|||||||
-H "Transfer-Encoding: chunked" \
|
-H "Transfer-Encoding: chunked" \
|
||||||
-H "Content-Type: application/octet-stream" \
|
-H "Content-Type: application/octet-stream" \
|
||||||
--data-binary @upload_example.csv.gz \
|
--data-binary @upload_example.csv.gz \
|
||||||
"http://{username}.carto.com/api/v2/sql/copyfrom?api_key={api_key}&q=COPY+upload_example+(the_geom,+name,+age)+FROM+STDIN+WITH+(FORMAT+csv,+HEADER+true)"
|
"https://{username}.carto.com/api/v2/sql/copyfrom?api_key={api_key}&q=COPY+upload_example+(the_geom,+name,+age)+FROM+STDIN+WITH+(FORMAT+csv,+HEADER+true)"
|
||||||
|
|
||||||
|
|
||||||
#### Python Example
|
#### Python Example
|
||||||
@ -102,7 +102,7 @@ username = {api_key}
|
|||||||
upload_file = 'upload_example.csv'
|
upload_file = 'upload_example.csv'
|
||||||
q = "COPY upload_example (the_geom, name, age) FROM STDIN WITH (FORMAT csv, HEADER true)"
|
q = "COPY upload_example (the_geom, name, age) FROM STDIN WITH (FORMAT csv, HEADER true)"
|
||||||
|
|
||||||
url = "http://%s.carto.com/api/v2/sql/copyfrom" % username
|
url = "https://%s.carto.com/api/v2/sql/copyfrom" % username
|
||||||
with open(upload_file, 'rb') as f:
|
with open(upload_file, 'rb') as f:
|
||||||
r = requests.post(url, params={'api_key': api_key, 'q': q}, data=f, stream=True)
|
r = requests.post(url, params={'api_key': api_key, 'q': q}, data=f, stream=True)
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ The SQL needs to be URL-encoded before being embedded in the CURL command, so th
|
|||||||
curl \
|
curl \
|
||||||
--output upload_example_dl.csv \
|
--output upload_example_dl.csv \
|
||||||
--compressed \
|
--compressed \
|
||||||
"http://{username}.carto.com/api/v2/sql/copyto?q=COPY+upload_example+(the_geom,name,age)+TO+stdout+WITH(FORMAT+csv,HEADER+true)&api_key={api_key}"
|
"https://{username}.carto.com/api/v2/sql/copyto?q=COPY+upload_example+(the_geom,name,age)+TO+stdout+WITH(FORMAT+csv,HEADER+true)&api_key={api_key}"
|
||||||
|
|
||||||
#### Python Example
|
#### Python Example
|
||||||
|
|
||||||
@ -211,7 +211,7 @@ download_filename = 'download_example.csv'
|
|||||||
q = "COPY upload_example (the_geom, name, age) TO stdout WITH (FORMAT csv, HEADER true)"
|
q = "COPY upload_example (the_geom, name, age) TO stdout WITH (FORMAT csv, HEADER true)"
|
||||||
|
|
||||||
# request the download
|
# request the download
|
||||||
url = "http://%s.carto.com/api/v2/sql/copyto" % username
|
url = "https://%s.carto.com/api/v2/sql/copyto" % username
|
||||||
r = requests.get(url, params={'api_key': api_key, 'q': q}, stream=True)
|
r = requests.get(url, params={'api_key': api_key, 'q': q}, stream=True)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ paths:
|
|||||||
x-code-samples:
|
x-code-samples:
|
||||||
- lang: Curl
|
- lang: Curl
|
||||||
source: |
|
source: |
|
||||||
curl -X POST -H 'Content-Encoding: gzip' -H 'Transfer-Encoding: chunked' -H 'Content-Type: application/octet-stream' --data-binary @upload_example.csv.gz 'http://{username}.carto.com/api/v2/sql/copyfrom?q=COPY upload_example (the_geom,name,age) FROM stdin WITH (FORMAT csv,HEADER true)&api_key={api_key}'
|
curl -X POST -H 'Content-Encoding: gzip' -H 'Transfer-Encoding: chunked' -H 'Content-Type: application/octet-stream' --data-binary @upload_example.csv.gz 'https://{username}.carto.com/api/v2/sql/copyfrom?q=COPY upload_example (the_geom,name,age) FROM stdin WITH (FORMAT csv,HEADER true)&api_key={api_key}'
|
||||||
|
|
||||||
/sql/copyto:
|
/sql/copyto:
|
||||||
get:
|
get:
|
||||||
@ -272,7 +272,7 @@ paths:
|
|||||||
x-code-samples:
|
x-code-samples:
|
||||||
- lang: Curl
|
- lang: Curl
|
||||||
source: |
|
source: |
|
||||||
curl --output upload_example_dl.csv --compressed "http://{username}.carto.com/api/v2/sql/copyto?q=COPY upload_example (the_geom,name,age) TO stdout WITH(FORMAT csv,HEADER true)&api_key={api_key}"
|
curl --output upload_example_dl.csv --compressed "https://{username}.carto.com/api/v2/sql/copyto?q=COPY upload_example (the_geom,name,age) TO stdout WITH(FORMAT csv,HEADER true)&api_key={api_key}"
|
||||||
|
|
||||||
/sql/job:
|
/sql/job:
|
||||||
post:
|
post:
|
||||||
|
Loading…
Reference in New Issue
Block a user