Certains produits et fonctionnalités sont en cours de changement de nom. Les fonctionnalités de playbook et de flux génératifs sont également en cours de migration vers une console unique. Consultez les détails.
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
En temps normal, vous créez et supprimez des intentions à l'aide de la console.
Toutefois, dans certains scénarios avancés, il peut s'avérer plus simple d'utiliser l'API.
Créer un intent
Les exemples suivants montrent comment appeler la méthode Create pour le type Intent.
Sélectionnez un protocole et une version pour la référence de l'intent :
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eIntents can be created and deleted via the API for advanced scenarios, offering an alternative to the console.\u003c/p\u003e\n"],["\u003cp\u003eThe API reference provides protocol-specific (REST, RPC) and language-specific (C++, C#, Go, Java, Node.js, Python) guidance for creating and deleting intents.\u003c/p\u003e\n"],["\u003cp\u003eCreating an intent using the REST API involves a POST request to a specified URL, with a JSON body containing the intent's display name.\u003c/p\u003e\n"],["\u003cp\u003eDeleting an intent using the REST API involves a DELETE request to a specific URL that includes the \u003ccode\u003eINTENT_ID\u003c/code\u003e, returning a successful status code and an empty response.\u003c/p\u003e\n"],["\u003cp\u003eUpdating specific fields of an intent can be done by using the field mask guide provided in the content.\u003c/p\u003e\n"]]],[],null,["# Manage intents with the API\n\nNormally, you create and delete intents using the console.\nHowever, in certain advanced scenarios,\nyou may find it easier to use the API.\n\nCreate an intent\n----------------\n\nThe following examples show how to call the `Create` method for the `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\"\u003eREGION_ID\u003c/var\u003e: your [region ID](/dialogflow/cx/docs/concept/region)\n- \u003cvar translate=\"no\"\u003eAGENT_ID\u003c/var\u003e: your agent ID\n\n\nHTTP method and URL:\n\n```\nPOST https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents\n```\n\n\nRequest JSON body:\n\n```\n{\n \"displayName\": \"My intent 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 POST \\\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\"\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 POST `\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\" | 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\": \"My intent display name\",\n \"priority\": 500000\n}\n```\n\n\u003cbr /\u003e\n\nUpdate an intent\n----------------\n\nThe\n[field mask guide](/dialogflow/cx/docs/how/field-mask)\nshows how to update individual fields of an intent.\n\nDelete an intent\n----------------\n\nThe following examples show how to call the `Delete` method for the `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\"\u003eREGION_ID\u003c/var\u003e: your [region ID](/dialogflow/cx/docs/concept/region)\n- \u003cvar translate=\"no\"\u003eAGENT_ID\u003c/var\u003e: your agent ID\n- \u003cvar translate=\"no\"\u003eINTENT_ID\u003c/var\u003e: your intent ID, found in the create response\n\n\nHTTP method and URL:\n\n```\nDELETE https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents/INTENT_ID\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\nExecute the following command:\n\n```\ncurl -X DELETE \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"x-goog-user-project: PROJECT_ID\" \\\n \"https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents/INTENT_ID\"\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\nExecute 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 DELETE `\n -Headers $headers `\n -Uri \"https://REGION_ID-dialogflow.googleapis.com/v3/projects/PROJECT_ID/locations/REGION_ID/agents/AGENT_ID/intents/INTENT_ID\" | Select-Object -Expand Content\n```\n\nYou should receive a successful status code (2xx) and an empty response.\n\n\u003cbr /\u003e"]]