API로 에이전트 데이터를 업데이트할 때 전체 데이터 유형을 덮어쓰거나 데이터 유형의 특정 필드만 덮어쓸 수 있습니다.
모든 데이터를 실수로 덮어쓰지 않도록 일반적으로 특정 필드를 덮어쓰는 것이 가장 좋습니다.
특정 필드를 덮어쓰려면 업데이트 요청에 FieldMask를 제공합니다.
다음 예시에서는 Intent 유형의 표시 이름을 업데이트하기 위해 FieldMask를 제공하는 방법을 보여줍니다.
CTS에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
importcom.google.cloud.dialogflow.cx.v3.Intent;importcom.google.cloud.dialogflow.cx.v3.Intent.Builder;importcom.google.cloud.dialogflow.cx.v3.IntentsClient;importcom.google.cloud.dialogflow.cx.v3.UpdateIntentRequest;importcom.google.protobuf.FieldMask;importjava.io.IOException;publicclassUpdateIntent{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringprojectId="my-project-id";StringagentId="my-agent-id";StringintentId="my-intent-id";Stringlocation="my-location";StringdisplayName="my-display-name";updateIntent(projectId,agentId,intentId,location,displayName);}// DialogFlow API Update Intent sample.publicstaticvoidupdateIntent(StringprojectId,StringagentId,StringintentId,Stringlocation,StringdisplayName)throwsIOException{// Note: close() needs to be called on the IntentsClient object to clean up resources// such as threads. In the example below, try-with-resources is used,// which automatically calls close().try(IntentsClientclient=IntentsClient.create()){StringintentPath="projects/"+projectId+"/locations/"+location+"/agents/"+agentId+"/intents/"+intentId;BuilderintentBuilder=client.getIntent(intentPath).toBuilder();intentBuilder.setDisplayName(displayName);FieldMaskfieldMask=FieldMask.newBuilder().addPaths("display_name").build();Intentintent=intentBuilder.build();UpdateIntentRequestrequest=UpdateIntentRequest.newBuilder().setIntent(intent).setLanguageCode("en").setUpdateMask(fieldMask).build();// Make API request to update intent using fieldmaskIntentresponse=client.updateIntent(request);System.out.println(response);}}}
Node.js
CTS에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
const{IntentsClient}=require('@google-cloud/dialogflow-cx');constintentClient=newIntentsClient();//TODO(developer): Uncomment these variables before running the sample.// const projectId = 'your-project-id';// const agentId = 'your-agent-id';// const intentId = 'your-intent-id';// const location = 'your-location';// const displayName = 'your-display-name';asyncfunctionupdateIntent(){constagentPath=intentClient.projectPath(projectId);constintentPath=`${agentPath}/locations/${location}/agents/${agentId}/intents/${intentId}`;//Gets the intent from intentPathconstintent=awaitintentClient.getIntent({name:intentPath});intent[0].displayName=displayName;//Specifies what is being updatedconstupdateMask={paths:['display_name'],};constupdateIntentRequest={intent:intent[0],updateMask,languageCode:'en',};//Send the request for update the intent.constresult=awaitintentClient.updateIntent(updateIntentRequest);console.log(result);}updateIntent();
Python
CTS에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다.
자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eWhen using the API to update agent data, you have the option to either overwrite all data or modify only specific fields.\u003c/p\u003e\n"],["\u003cp\u003eIt is generally recommended to update specific fields to prevent the accidental overwriting of all your data.\u003c/p\u003e\n"],["\u003cp\u003eTo update specific fields, a \u003ccode\u003eFieldMask\u003c/code\u003e must be included in the update request to indicate the fields to be modified.\u003c/p\u003e\n"],["\u003cp\u003eThe examples provided illustrate how to use a \u003ccode\u003eFieldMask\u003c/code\u003e to specifically update the display name for an \u003ccode\u003eIntent\u003c/code\u003e type across REST, Java, Node.js and Python.\u003c/p\u003e\n"]]],[],null,["# Update data with a FieldMask\n\nWhen updating agent data with the API,\nyou can choose to overwrite the entire data type\nor to overwrite only specific fields of the data type.\nIt is usually best to overwrite specific fields,\nso you avoid accidentally overwriting all of your data.\nTo overwrite specific fields,\nsupply a\n[`FieldMask`](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#fieldmask)\nto your update request.\n\nThe following examples show how to supply a `FieldMask`\nto update the display name for an `Intent` type.\n\n\nGo to the Intent API reference \n**Select a protocol and version for the Intent reference:**\n\nClose\n\n\u003cbr /\u003e\n\n### REST\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: your Google Cloud project ID\n- \u003cvar translate=\"no\"\u003eAGENT_ID\u003c/var\u003e: your agent ID\n- \u003cvar translate=\"no\"\u003eREGION_ID\u003c/var\u003e: your [region ID](/dialogflow/cx/docs/concept/region)\n- \u003cvar translate=\"no\"\u003eINTENT_ID\u003c/var\u003e: your intent ID\n- \u003cvar translate=\"no\"\u003eDISPLAY_NAME\u003c/var\u003e: your desired display name\n\n\nHTTP method and URL:\n\n```\nPATCH https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents/INTENT_ID?updateMask=displayName\n```\n\n\nRequest JSON body:\n\n```\n{\n \"displayName\": \"DISPLAY_NAME\"\n}\n```\n\nTo send your request, expand one of these options:\n\n#### curl (Linux, macOS, or Cloud Shell)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nSave the request body in a file named `request.json`,\nand execute the following command:\n\n```\ncurl -X PATCH \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"x-goog-user-project: PROJECT_ID\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n -d @request.json \\\n \"https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents/INTENT_ID?updateMask=displayName\"\n```\n\n#### PowerShell (Windows)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nSave the request body in a file named `request.json`,\nand execute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\"; \"x-goog-user-project\" = \"PROJECT_ID\" }\n\nInvoke-WebRequest `\n -Method PATCH `\n -Headers $headers `\n -ContentType: \"application/json; charset=utf-8\" `\n -InFile request.json `\n -Uri \"https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents/INTENT_ID?updateMask=displayName\" | Select-Object -Expand Content\n```\n\nYou should receive a JSON response similar to the following:\n\n```\n{\n \"name\": \"projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents/INTENT_ID\",\n \"displayName\": \"DISPLAY_NAME\",\n ...\n}\n```\n\n### Java\n\n\nTo authenticate to Dialogflow, 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.dialogflow.cx.v3.https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.Intent.html;\n import com.google.cloud.dialogflow.cx.v3.https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.Intent.html.Builder;\n import com.google.cloud.dialogflow.cx.v3.https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.IntentsClient.html;\n import com.google.cloud.dialogflow.cx.v3.https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.UpdateIntentRequest.html;\n import com.google.protobuf.https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.FieldMask.html;\n import java.io.IOException;\n\n public class UpdateIntent {\n\n public static void main(String[] args) throws IOException {\n // TODO(developer): Replace these variables before running the sample.\n String projectId = \"my-project-id\";\n String agentId = \"my-agent-id\";\n String intentId = \"my-intent-id\";\n String location = \"my-location\";\n String displayName = \"my-display-name\";\n updateIntent(projectId, agentId, intentId, location, displayName);\n }\n\n // DialogFlow API Update Intent sample.\n public static void updateIntent(\n String projectId, String agentId, String intentId, String location, String displayName)\n throws IOException {\n\n // Note: close() needs to be called on the IntentsClient object to clean up resources\n // such as threads. In the example below, try-with-resources is used,\n // which automatically calls close().\n try (https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.IntentsClient.html client = https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.IntentsClient.html.create()) {\n String intentPath =\n \"projects/\"\n + projectId\n + \"/locations/\"\n + location\n + \"/agents/\"\n + agentId\n + \"/intents/\"\n + intentId;\n\n Builder intentBuilder = client.getIntent(intentPath).toBuilder();\n\n intentBuilder.setDisplayName(displayName);\n https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.FieldMask.html fieldMask = https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.FieldMask.html.newBuilder().https://cloud.google.com/java/docs/reference/protobuf/latest/com.google.protobuf.FieldMask.Builder.html#com_google_protobuf_FieldMask_Builder_addPaths_java_lang_String_(\"display_name\").build();\n\n https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.Intent.html intent = intentBuilder.build();\n https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.UpdateIntentRequest.html request =\n https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.UpdateIntentRequest.html.newBuilder()\n .setIntent(intent)\n .setLanguageCode(\"en\")\n .setUpdateMask(fieldMask)\n .build();\n\n // Make API request to update intent using fieldmask\n https://cloud.google.com/java/docs/reference/google-cloud-dialogflow-cx/latest/com.google.cloud.dialogflow.cx.v3.Intent.html response = client.updateIntent(request);\n System.out.println(response);\n }\n }\n }\n\n### Node.js\n\n\nTo authenticate to Dialogflow, 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 const {IntentsClient} = require('https://cloud.google.com/nodejs/docs/reference/dialogflow-cx/latest/overview.html');\n\n const intentClient = new https://cloud.google.com/nodejs/docs/reference/dialogflow-cx/latest/overview.html();\n\n //TODO(developer): Uncomment these variables before running the sample.\n // const projectId = 'your-project-id';\n // const agentId = 'your-agent-id';\n // const intentId = 'your-intent-id';\n // const location = 'your-location';\n // const displayName = 'your-display-name';\n\n async function updateIntent() {\n const agentPath = intentClient.projectPath(projectId);\n const intentPath = `${agentPath}/locations/${location}/agents/${agentId}/intents/${intentId}`;\n\n //Gets the intent from intentPath\n const intent = await intentClient.getIntent({name: intentPath});\n intent[0].displayName = displayName;\n\n //Specifies what is being updated\n const updateMask = {\n paths: ['display_name'],\n };\n\n const updateIntentRequest = {\n intent: intent[0],\n updateMask,\n languageCode: 'en',\n };\n\n //Send the request for update the intent.\n const result = await intentClient.updateIntent(updateIntentRequest);\n console.log(result);\n }\n\n updateIntent();\n\n### Python\n\n\nTo authenticate to Dialogflow, 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 from google.cloud.dialogflowcx_v3.services.intents import IntentsClient\n from google.protobuf import field_mask_pb2\n\n\n def update_intent(project_id, agent_id, intent_id, location, displayName):\n intents_client = IntentsClient()\n\n intent_name = intents_client.intent_path(project_id, location, agent_id, intent_id)\n\n intent = intents_client.get_intent(request={\"name\": intent_name})\n\n intent.display_name = displayName\n update_mask = field_mask_pb2.FieldMask(paths=[\"display_name\"])\n response = intents_client.update_intent(intent=intent, update_mask=update_mask)\n return response\n\n\u003cbr /\u003e"]]