Cloud Data Loss Prevention (Cloud DLP) is now a part of Sensitive Data Protection. The API name remains the same: Cloud Data Loss Prevention API (DLP API). For information about the services that make up Sensitive Data Protection, see
Sensitive Data Protection overview.
Get an inspection job
Stay organized with collections
Save and categorize content based on your preferences.
Get DLP inspection job.
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"]],[],[],[],null,["# Get an inspection job\n\nGet DLP inspection job.\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Creating and scheduling Sensitive Data Protection inspection jobs](/sensitive-data-protection/docs/creating-job-triggers)\n\nCode sample\n-----------\n\n### C#\n\n\nTo learn how to install and use the client library for Sensitive Data Protection, see\n[Sensitive Data Protection client libraries](/sensitive-data-protection/docs/libraries).\n\n\nTo authenticate to Sensitive Data Protection, 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\n using https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dlp.V2/latest/Google.Cloud.Dlp.V2.html;\n using System;\n\n public class JobsGet\n {\n public static DlpJob GetDlpJob(string jobName)\n {\n var dlp = https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dlp.V2/latest/Google.Cloud.Dlp.V2.DlpServiceClient.html.https://cloud.google.com/dotnet/docs/reference/Google.Cloud.Dlp.V2/latest/Google.Cloud.Dlp.V2.DlpServiceClient.html#Google_Cloud_Dlp_V2_DlpServiceClient_Create();\n\n var response = dlp.GetDlpJob(jobName);\n\n Console.WriteLine($\"Job: {response.Name} status: {response.State}\");\n\n return response;\n }\n }\n\n### Go\n\n\nTo learn how to install and use the client library for Sensitive Data Protection, see\n[Sensitive Data Protection client libraries](/sensitive-data-protection/docs/libraries).\n\n\nTo authenticate to Sensitive Data Protection, 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 \tdlp \"cloud.google.com/go/dlp/apiv2\"\n \t\"cloud.google.com/go/dlp/apiv2/dlppb\"\n )\n\n // jobsGet gets an inspection job using jobName\n func jobsGet(w io.Writer, projectID string, jobName string) error {\n \t// projectId := \"my-project-id\"\n \t// jobName := \"your-job-id\"\n\n \tctx := context.Background()\n\n \t// Initialize a client once and reuse it to send multiple requests. Clients\n \t// are safe to use across goroutines. When the client is no longer needed,\n \t// call the Close method to cleanup its resources.\n \tclient, err := dlp.https://cloud.google.com/go/docs/reference/cloud.google.com/go/dlp/latest/apiv2.html#cloud_google_com_go_dlp_apiv2_Client_NewClient(ctx)\n \tif err != nil {\n \t\treturn err\n \t}\n\n \t// Closing the client safely cleans up background resources.\n \tdefer client.https://cloud.google.com/go/docs/reference/cloud.google.com/go/dlp/latest/apiv2.html#cloud_google_com_go_dlp_apiv2_Client_Close()\n\n \t// Construct the request to be sent by the client.\n \treq := &dlppb.GetDlpJobRequest{\n \t\tName: jobName,\n \t}\n\n \t// Send the request.\n \tresp, err := client.GetDlpJob(ctx, req)\n \tif err != nil {\n \t\treturn err\n \t}\n\n \t// Print the results.\n \tfmt.Fprintf(w, \"Job Name: %v Job Status: %v\", resp.Name, resp.State)\n \treturn nil\n }\n\n### Java\n\n\nTo learn how to install and use the client library for Sensitive Data Protection, see\n[Sensitive Data Protection client libraries](/sensitive-data-protection/docs/libraries).\n\n\nTo authenticate to Sensitive Data Protection, 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\n import com.google.cloud.dlp.v2.https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.cloud.dlp.v2.DlpServiceClient.html;\n import com.google.privacy.dlp.v2.https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.DlpJobName.html;\n import com.google.privacy.dlp.v2.https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.GetDlpJobRequest.html;\n import java.io.IOException;\n\n public class JobsGet {\n\n public static void main(String[] args) throws Exception {\n // TODO(developer): Replace these variables before running the sample.\n String projectId = \"your-project-id\";\n String jobId = \"your-job-id\";\n getJobs(projectId, jobId);\n }\n\n // Gets a DLP Job with the given jobId\n public static void getJobs(String projectId, String jobId) throws IOException {\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests. After completing all of your requests, call\n // the \"close\" method on the client to safely clean up any remaining background resources.\n try (https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.cloud.dlp.v2.DlpServiceClient.html dlpServiceClient = https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.cloud.dlp.v2.DlpServiceClient.html.create()) {\n\n // Construct the complete job name from the projectId and jobId\n https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.DlpJobName.html jobName = https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.DlpJobName.html.of(projectId, jobId);\n\n // Construct the get job request to be sent by the client.\n https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.GetDlpJobRequest.html getDlpJobRequest =\n https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.GetDlpJobRequest.html.newBuilder().setName(jobName.https://cloud.google.com/java/docs/reference/google-cloud-dlp/latest/com.google.privacy.dlp.v2.DlpJobName.html#com_google_privacy_dlp_v2_DlpJobName_toString__()).build();\n\n // Send the get job request\n dlpServiceClient.getDlpJob(getDlpJobRequest);\n System.out.println(\"Job got successfully.\");\n }\n }\n }\n\n### Node.js\n\n\nTo learn how to install and use the client library for Sensitive Data Protection, see\n[Sensitive Data Protection client libraries](/sensitive-data-protection/docs/libraries).\n\n\nTo authenticate to Sensitive Data Protection, 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 // Imports the Google Cloud Data Loss Prevention library\n const DLP = require('https://cloud.google.com/nodejs/docs/reference/dlp/latest/overview.html');\n\n // Instantiates a client\n const dlp = new DLP.https://cloud.google.com/nodejs/docs/reference/dlp/latest/overview.html();\n\n // Job name to look for\n // const jobName = 'your-job-name';\n\n async function getJob() {\n // Construct request for finding job using job name.\n const request = {\n name: jobName,\n };\n\n // Send the request and receive response from the service\n const [job] = await dlp.getDlpJob(request);\n\n // Print results.\n console.log(`Job ${job.name} status: ${job.state}`);\n }\n\n getJob();\n\n### PHP\n\n\nTo learn how to install and use the client library for Sensitive Data Protection, see\n[Sensitive Data Protection client libraries](/sensitive-data-protection/docs/libraries).\n\n\nTo authenticate to Sensitive Data Protection, 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 use Google\\Cloud\\Dlp\\V2\\Client\\DlpServiceClient;\n use Google\\Cloud\\Dlp\\V2\\GetDlpJobRequest;\n\n /**\n * Get DLP inspection job.\n * @param string $jobName Dlp job name\n */\n function get_job(\n string $jobName\n ): void {\n // Instantiate a client.\n $dlp = new DlpServiceClient();\n try {\n // Send the get job request\n $getDlpJobRequest = (new GetDlpJobRequest())\n -\u003esetName($jobName);\n $response = $dlp-\u003egetDlpJob($getDlpJobRequest);\n printf('Job %s status: %s' . PHP_EOL, $response-\u003egetName(), $response-\u003egetState());\n } finally {\n $dlp-\u003eclose();\n }\n }\n\n### Python\n\n\nTo learn how to install and use the client library for Sensitive Data Protection, see\n[Sensitive Data Protection client libraries](/sensitive-data-protection/docs/libraries).\n\n\nTo authenticate to Sensitive Data Protection, 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\n import google.cloud.dlp\n\n\n def get_dlp_job(project: str, job_name: str) -\u003e None:\n \"\"\"Uses the Data Loss Prevention API to retrieve a DLP job.\n Args:\n project: The project id to use as a parent resource.\n job_name: The name of the DlpJob resource to be retrieved.\n \"\"\"\n\n # Instantiate a client.\n dlp = google.cloud.https://cloud.google.com/python/docs/reference/dlp/latest/.https://cloud.google.com/python/docs/reference/dlp/latest/google.cloud.dlp_v2.services.dlp_service.DlpServiceClient.html()\n\n # Convert the project id and job name into a full resource id.\n job_name = f\"projects/{project}/locations/global/dlpJobs/{job_name}\"\n\n # Call the API\n response = dlp.get_dlp_job(request={\"name\": job_name})\n\n print(f\"Job: {response.name} Status: {response.state}\")\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=dlp)."]]