Delete dataset
Stay organized with collections
Save and categorize content based on your preferences.
Delete a dataset.
Explore further
For detailed documentation that includes this code sample, see the following:
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis document provides code samples in Go, Java, Node.js, and Python demonstrating how to delete a dataset within the Cloud Healthcare API.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples use the Cloud Healthcare API client libraries and require Application Default Credentials (ADC) for authentication.\u003c/p\u003e\n"],["\u003cp\u003eEach code example specifies prerequisites, including setup instructions and links to relevant documentation for the corresponding language.\u003c/p\u003e\n"],["\u003cp\u003eThe process to delete a dataset involves creating a service client, constructing a request with the dataset name and executing the delete request.\u003c/p\u003e\n"],["\u003cp\u003eThe document directs users to further explore the Google Cloud sample browser for code examples related to other Google Cloud products.\u003c/p\u003e\n"]]],[],null,["# Delete dataset\n\nDelete a dataset.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Create and manage datasets](/healthcare-api/docs/datasets)\n- [Store healthcare data with client libraries](/healthcare-api/docs/store-healthcare-data-client-library)\n\nCode sample\n-----------\n\n### Go\n\n\nBefore trying this sample, follow the Go setup instructions in the\n[Cloud Healthcare API quickstart using\nclient libraries](https://cloud.google.com/healthcare-api/docs/store-healthcare-data-client-library).\n\n\nFor more information, see the\n[Cloud Healthcare API Go API\nreference documentation](https://pkg.go.dev/google.golang.org/api/healthcare/v1).\n\n\nTo authenticate to Cloud Healthcare API, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import (\n \t\"context\"\n \t\"fmt\"\n \t\"io\"\n\n \thealthcare \"google.golang.org/api/healthcare/v1\"\n )\n\n // deleteDataset deletes the given dataset.\n func deleteDataset(w io.Writer, projectID, location, datasetID string) error {\n \tctx := context.Background()\n\n \thealthcareService, err := healthcare.NewService(ctx)\n \tif err != nil {\n \t\treturn fmt.Errorf(\"healthcare.NewService: %w\", err)\n \t}\n\n \tdatasetsService := healthcareService.Projects.Locations.Datasets\n\n \tname := fmt.Sprintf(\"projects/%s/locations/%s/datasets/%s\", projectID, location, datasetID)\n \tif _, err := datasetsService.Delete(name).Do(); err != nil {\n \t\treturn fmt.Errorf(\"Delete: %w\", err)\n \t}\n\n \tfmt.Fprintf(w, \"Deleted dataset: %q\\n\", name)\n \treturn nil\n }\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[Cloud Healthcare API quickstart using\nclient libraries](https://cloud.google.com/healthcare-api/docs/store-healthcare-data-client-library).\n\n\nFor more information, see the\n[Cloud Healthcare API Java API\nreference documentation](https://googleapis.dev/java/google-api-services-healthcare/latest/index.html).\n\n\nTo authenticate to Cloud Healthcare API, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import com.google.api.client.http.https://cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.HttpRequestInitializer.html;\n import com.google.api.client.http.javanet.https://cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.http.javanet.NetHttpTransport.html;\n import com.google.api.client.json.https://cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.json.JsonFactory.html;\n import com.google.api.client.json.gson.https://cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.json.gson.GsonFactory.html;\n import com.google.api.services.healthcare.v1.CloudHealthcare;\n import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets;\n import com.google.api.services.healthcare.v1.CloudHealthcareScopes;\n import com.google.auth.http.https://cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.http.HttpCredentialsAdapter.html;\n import com.google.auth.oauth2.https://cloud.google.com/java/docs/reference/google-auth-library/latest/com.google.auth.oauth2.GoogleCredentials.html;\n import java.io.IOException;\n import java.util.Collections;\n\n public class DatasetDelete {\n private static final String DATASET_NAME = \"projects/%s/locations/%s/datasets/%s\";\n private static final JsonFactory JSON_FACTORY = new GsonFactory();\n private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();\n\n public static void datasetDelete(String datasetName) throws IOException {\n // String datasetName =\n // String.format(DATASET_NAME, \"your-project-id\", \"your-region-id\", \"your-dataset-id\");\n\n // Initialize the client, which will be used to interact with the service.\n CloudHealthcare client = createClient();\n\n // Create request and configure any parameters.\n Datasets.Delete request = client.projects().locations().datasets().delete(datasetName);\n\n // Execute the request and process the results.\n request.execute();\n System.out.println(\"Dataset deleted.\");\n }\n\n private static CloudHealthcare createClient() throws IOException {\n // Use Application Default Credentials (ADC) to authenticate the requests\n // For more information see https://cloud.google.com/docs/authentication/production\n GoogleCredentials credential =\n GoogleCredentials.getApplicationDefault()\n .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));\n\n // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.\n HttpRequestInitializer requestInitializer =\n request -\u003e {\n new HttpCredentialsAdapter(credential).initialize(request);\n request.setConnectTimeout(60000); // 1 minute connect timeout\n request.setReadTimeout(60000); // 1 minute read timeout\n };\n\n // Build the client for interacting with the service.\n return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)\n .setApplicationName(\"your-application-name\")\n .build();\n }\n }\n\n### Node.js\n\n\nBefore trying this sample, follow the Node.js setup instructions in the\n[Cloud Healthcare API quickstart using\nclient libraries](https://cloud.google.com/healthcare-api/docs/store-healthcare-data-client-library).\n\n\nFor more information, see the\n[Cloud Healthcare API Node.js API\nreference documentation](https://github.com/googleapis/google-api-nodejs-client/blob/main/src/apis/healthcare/README.md).\n\n\nTo authenticate to Cloud Healthcare API, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n const google = require('@googleapis/healthcare');\n const healthcare = google.healthcare({\n version: 'v1',\n auth: new google.auth.GoogleAuth({\n scopes: ['https://www.googleapis.com/auth/cloud-platform'],\n }),\n });\n\n const deleteDataset = async () =\u003e {\n // TODO(developer): uncomment these lines before running the sample\n // const cloudRegion = 'us-central1';\n // const projectId = 'adjective-noun-123';\n // const datasetId = 'my-dataset';\n const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;\n const request = {name: parent};\n\n await healthcare.projects.locations.datasets.delete(request);\n console.log(`Deleted dataset: ${datasetId}`);\n };\n\n deleteDataset();\n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[Cloud Healthcare API quickstart using\nclient libraries](https://cloud.google.com/healthcare-api/docs/store-healthcare-data-client-library).\n\n\nFor more information, see the\n[Cloud Healthcare API Python API\nreference documentation](https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1).\n\n\nTo authenticate to Cloud Healthcare API, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n def delete_dataset(project_id: str, location: str, dataset_id: str) -\u003e None:\n \"\"\"Deletes a dataset.\n\n See\n https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/healthcare/api-client/v1/datasets\n before running the sample.\n See https://googleapis.github.io/google-api-python-client/docs/dyn/healthcare_v1.projects.locations.datasets.html#delete\n for the Python API reference.\n\n Args:\n project_id: The project ID or project number of the Google Cloud project you want\n to use.\n location: The name of the dataset's location.\n dataset_id: The name of the dataset to delete.\n\n Returns:\n An empty response body.\n \"\"\"\n # Imports HttpError from the Google Python API client errors module.\n # Imports the Google API Discovery Service.\n from googleapiclient import discovery\n from googleapiclient.errors import HttpError\n\n api_version = \"v1\"\n service_name = \"healthcare\"\n # Returns an authorized API client by discovering the Healthcare API\n # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.\n client = discovery.build(service_name, api_version)\n\n # TODO(developer): Uncomment these lines and replace with your values.\n # project_id = 'my-project'\n # location = 'us-central1'\n # dataset_id = 'my-dataset'\n dataset_name = f\"projects/{project_id}/locations/{location}/datasets/{dataset_id}\"\n\n request = client.projects().locations().datasets().delete(name=dataset_name)\n\n try:\n request.execute()\n print(f\"Deleted dataset: {dataset_id}\")\n except HttpError as err:\n raise err\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=healthcare)."]]