Kurt Gooden
Kurt Gooden

Reputation: 43

How do I export using Cloud SQL API from Cloud SQL instances owned by another project?

I am trying to export a table from a Cloud SQL database owned by another project. The calling project has access and can successfully list instances (using getItems()), but it when I try to export is returns "The client is not authorized to make this request."

Here is the code that I am using to export.

$client = new Google_Client();
$client->setAuth(new Google_Auth_AppIdentity($client));
$client->getAuth()>authenticateForScope('https://www.googleapis.com/auth/sqlservice.admin');
$client->getAuth()>authenticateForScope('https://www.googleapis.com/auth/cloud-platform');
$sqladmin = new Google_Service_SQLAdmin($client);
$postBody = new Google_Service_SQLAdmin_InstancesExportRequest();

//Set csv options
$csv_options = new Google_Service_SQLAdmin_ExportContextCsvExportOptions();
$csv_options->setSelectQuery('SELECT id FROM test.test;');

//set export context options.
$ec = new Google_Service_SQLAdmin_ExportContext();
$ec->setCsvExportOptions($csv_options);

$ec->setUri('gs://bucket/file.csv');

$postBody->setExportContext($ec);

$response = $sqladmin->instances->export('testing-project-xxxx', 'database', $postBody);

Upvotes: 0

Views: 238

Answers (1)

Majoka
Majoka

Reputation: 26

$response = $sqladmin->instances->export('testing-project-xxxx', 'database', $postBody);

Replace database name with instance name

Upvotes: 1

Related Questions