Reputation: 1213
I get an error when I run CURL in the terminal. The error is like this:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "parseError",
"message": "Parse Error"
}
],
"code": 400,
"message": "Parse Error"
}
}
Here my CURL code :
ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
--header 'Content-Type: application/json' \
--data '{"exportContext":
{"fileType": "CSV",
"uri": "gs://project-initial-db/test_gutil.csv",
"databases": ["my_db"] },
"csvExportOptions":
{"selectQuery":"SELECT * FROM `trans_channel` INTO OUTFILE "test_gutil.csv" CHARACTER SET "utf8mb4" FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY "\"" ESCAPED BY "\\" LINES TERMINATED BY "\n";"}}' \
-X POST \
https://www.googleapis.com/sql/v1beta4/projects/project-11/instances/project-db/export
Does anybody know about this error?
I seek out about export to CSV using CURL on Google Cloud SQL, but I just get a little bit of information.
FYI, I have set the environment variable (GOOGLE_APPLICATION_CREDENTIALS) and the authentication is successful.
I will be grateful for any help you can provide. Thanks!
Upvotes: 2
Views: 743
Reputation: 1520
You are just missing a little something within thew field "cvsExportOptions", it should look like this:
"csvExportOptions":
{"selectQuery":"[YOUR_QUERY]"}
You may have more detailed information here, where you can also check if the curl is correct using the Try the API utility on the right of the page.
EDIT
Copying the api call from the Try this API utility I used for testing exactly as it was worked for me. Give this a try replacing the placeholders with your data
ACCESS_TOKEN="$(gcloud auth application-default print-access-token)"
curl --header "Authorization: Bearer ${ACCESS_TOKEN}" \
--header 'Content-Type: application/json' \
--data '{
"exportContext": {
"fileType": "CSV",
"uri": "gs://[YOUR_BUCKET]/[YOUR_PATH_TO_DUMP_FILE]",
"databases": [
"[YOUR_DATABASE]"
],
"csvExportOptions": {
"selectQuery": "[YOUR_QUERY]"
}
}
}' \
-X POST \
https://www.googleapis.com/sql/v1beta4/projects/[YOUR_PROJECT]/instances/[YOUR_INSTANCE]/export
Upvotes: 1