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 SetAgent
method for the
Agent
type.
These examples are creating agents,
but the same methods can be used to update agent settings,
like agent edition.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
HTTP method and URL:
POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID /agent
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://dialogflow.googleapis.com/v2/projects/PROJECT_ID /agent"
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://dialogflow.googleapis.com/v2/projects/PROJECT_ID /agent" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "parent": "projects/PROJECT_ID ", "displayName": "My display name", "defaultLanguageCode": "en", "timeZone": "America/New_York", "apiVersion": "API_VERSION_V2" }
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 DeleteAgent
method for the
Agent
type.
Before using any of the request data, make the following replacements:
- PROJECT_ID: your Google Cloud project ID
HTTP method and URL:
DELETE https://dialogflow.googleapis.com/v2/projects/PROJECT_ID /agent
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://dialogflow.googleapis.com/v2/projects/PROJECT_ID /agent"
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://dialogflow.googleapis.com/v2/projects/PROJECT_ID /agent" | Select-Object -Expand Content
You should receive a successful status code (2xx) and an empty response.