Stay organized with collections
Save and categorize content based on your preferences.
When updating agent data with the API,
you can choose to overwrite the entire data type
or to overwrite only specific fields of the data type.
It is usually best to overwrite specific fields,
so you avoid accidentally overwriting all of your data.
To overwrite specific fields,
supply a
FieldMask
to your update request.
The following examples show how to supply a FieldMask
to update the display name for an
Intents
type.
REST
Supply the updateMask
URL query parameter for the patch method.
For example:
importcom.google.cloud.dialogflow.v2.Intent;importcom.google.cloud.dialogflow.v2.Intent.Builder;importcom.google.cloud.dialogflow.v2.IntentsClient;importcom.google.cloud.dialogflow.v2.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";StringintentId="my-intent-id";Stringlocation="my-location";StringdisplayName="my-display-name";updateIntent(projectId,intentId,location,displayName);}// DialogFlow API Update Intent sample.publicstaticvoidupdateIntent(StringprojectId,StringintentId,Stringlocation,StringdisplayName)throwsIOException{try(IntentsClientclient=IntentsClient.create()){StringintentPath="projects/"+projectId+"/locations/"+location+"/agent/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);}}}
const{IntentsClient}=require('@google-cloud/dialogflow');constintentClient=newIntentsClient();constagentPath=intentClient.projectAgentPath(projectId);constintentPath=agentPath+'/intents/'+intentId;constintent=awaitintentClient.getIntent({name:intentPath});intent[0].displayName=displayName;constupdateMask={paths:['display_name'],};constupdateIntentRequest={intent:intent[0],updateMask:updateMask,languageCode:'en',};//Send the request for update the intent.constresult=awaitintentClient.updateIntent(updateIntentRequest);console.log(result);
[[["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"]],["Last updated 2025-03-27 UTC."],[[["When updating agent data via the API, you can choose to overwrite either the entire data type or specific fields within it."],["Overwriting specific fields using a `FieldMask` is generally recommended to avoid accidental data loss."],["The `updateMask` parameter, supplied either as a URL query parameter in REST or through a dedicated object in the code, specifies which fields to update."],["The provided examples demonstrate how to use `FieldMask` to update the display name of an Intent for REST, Java, Node.js, and Python."],["Application Default Credentials are required for authentication to Dialogflow, with instructions available for local development environments."]]],[]]