Normally, you create and delete agents using the console. However, in certain advanced scenarios, you may find it easier to use the API.
Create an agent
The following examples show how to call the Create
method for the Agent
type.
Select a protocol and version for the Agent reference:
Protocol | V3 | V3beta1 |
---|---|---|
REST | Agent resource | Agent resource |
RPC | Agent interface | Agent interface |
C++ | AgentsClient | Not available |
C# | AgentsClient | Not available |
Go | AgentsClient | Not available |
Java | AgentsClient | AgentsClient |
Node.js | AgentsClient | AgentsClient |
PHP | Not available | Not available |
Python | AgentsClient | AgentsClient |
Ruby | Not available | Not available |
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
- REGION_ID: your region ID
HTTP method and URL:
POST https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents
Request JSON body:
{ "displayName": "My display name", "defaultLanguageCode": "en", "timeZone": "America/New_York" }
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Save the request body in a file named request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:PROJECT_ID " \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents"
PowerShell (Windows)
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_ID " }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID ", "displayName": "My display name", "defaultLanguageCode": "en", "timeZone": "America/New_York", "startFlow": "projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID /flows/00000000-0000-0000-0000-000000000000", "advancedSettings": { "loggingSettings": {} } }
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Delete an agent
The following examples show how to call the Delete
method for the Agent
type.
Select a protocol and version for the Agent reference:
Protocol | V3 | V3beta1 |
---|---|---|
REST | Agent resource | Agent resource |
RPC | Agent interface | Agent interface |
C++ | AgentsClient | Not available |
C# | AgentsClient | Not available |
Go | AgentsClient | Not available |
Java | AgentsClient | AgentsClient |
Node.js | AgentsClient | AgentsClient |
PHP | Not available | Not available |
Python | AgentsClient | AgentsClient |
Ruby | Not available | Not available |
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
- REGION_ID: your region ID
- AGENT_ID: your agent ID, found in the agent creation response
HTTP method and URL:
DELETE https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID
To send your request, expand one of these options:
curl (Linux, macOS, or Cloud Shell)
Execute the following command:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:PROJECT_ID " \
"https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID "
PowerShell (Windows)
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_ID " }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://REGION_ID -dialogflow.googleapis.com/v3/projects/PROJECT_ID /locations/REGION_ID /agents/AGENT_ID " | Select-Object -Expand Content
You should receive a successful status code (2xx) and an empty response.