Some products and features are in the process of being renamed. Generative playbook and flow features are also being migrated to a single consolidated console. See the details.

Manage pages with the API

In most cases, you will use the console to manage pages. In advanced scenarios, you may wish to use the API to manage pages. This guide describes how to create, list, and delete pages using the API.

Create page

To create a page for your agent, call the create method on the Page type.

Select a protocol and version for the Page reference:

Protocol V3 V3beta1
REST Page resource Page resource
RPC Page interface Page interface
C++ PagesClient Not available
C# PagesClient Not available
Go PagesClient Not available
Java PagesClient PagesClient
Node.js PagesClient PagesClient
PHP Not available Not available
Python PagesClient PagesClient
Ruby Not available Not available

Java

To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

importcom.google.cloud.dialogflow.cx.v3.CreatePageRequest ;
importcom.google.cloud.dialogflow.cx.v3.Page ;
importcom.google.cloud.dialogflow.cx.v3.PagesClient ;
importjava.io.IOException;
publicclass CreateSimplePage{
publicstaticvoidmain(String[]args)throwsIOException{
// TODO(developer): Replace these variables before running the sample.
StringprojectId="my-project-id";
StringagentId="my-agent-id";
StringflowId="my-flow-id";
Stringlocation="my-location";
StringdisplayName="my-display-name";
createPage(projectId,agentId,flowId,location,displayName);
}
// DialogFlow API Create Page Sample.
// Creates a page from the provided parameters
publicstaticPage createPage(
StringprojectId,StringagentId,StringflowId,Stringlocation,StringdisplayName)
throwsIOException{
Page response;
CreatePageRequest .BuildercreateRequestBuilder=CreatePageRequest .newBuilder();
Page .BuilderpageBuilder=Page .newBuilder();
pageBuilder.setDisplayName(displayName);
createRequestBuilder
.setParent(
"projects/"
+projectId
+"/locations/"
+location
+"/agents/"
+agentId
+"/flows/"
+flowId)
.setPage(pageBuilder);
// Make API request to create page
// Note: close() needs to be called on the PagesClient object to clean up resources
// such as threads. In the example below, try-with-resources is used,
// which automatically calls close().
try(PagesClient client=PagesClient .create()){
response=client.createPage(createRequestBuilder.build());
System.out.println("Successfully created page!");
returnresponse;
}
}

Node.js

To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

asyncfunctioncreatePage(projectId,agentId,flowId,location,displayName){
constpagesClient=newPagesClient();
constcreatePageRequest={
parent:`projects/${projectId}/locations/${location}/agents/${agentId}/flows/${flowId}`,
page:{
displayName:displayName,
},
};
constresponse=awaitpagesClient.createPage(createPageRequest);
console.log(response);
}

Python

To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

async defcreate_page(project_id, agent_id, flow_id, location, displayName):
 pages_client = PagesAsyncClient()
 page = Page()
 page.display_name = displayName
 request = CreatePageRequest()
 request.parent = (
 "projects/"
 + project_id
 + "/locations/"
 + location
 + "/agents/"
 + agent_id
 + "/flows/"
 + flow_id
 )
 request.page = page
 response = await pages_client.create_page(request=request)
 return response

List pages

To list the pages for your agent, call the list method on the Page type.

Select a protocol and version for the Page reference:

Protocol V3 V3beta1
REST Page resource Page resource
RPC Page interface Page interface
C++ PagesClient Not available
C# PagesClient Not available
Go PagesClient Not available
Java PagesClient PagesClient
Node.js PagesClient PagesClient
PHP Not available Not available
Python PagesClient PagesClient
Ruby Not available Not available

Java

To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

importcom.google.cloud.dialogflow.cx.v3.ListPagesRequest ;
importcom.google.cloud.dialogflow.cx.v3.ListPagesRequest.Builder;
importcom.google.cloud.dialogflow.cx.v3.Page ;
importcom.google.cloud.dialogflow.cx.v3.PagesClient ;
importjava.io.IOException;
publicclass ListPages{
publicstaticvoidmain(String[]args)throwsIOException{
// TODO(developer): Replace these variables before running the sample.
StringprojectId="my-project-id";
StringagentId="my-agent-id";
StringflowId="my-flow-id";
Stringlocation="my-location";
listPages(projectId,agentId,flowId,location);
}
// DialogFlow API List Pages Sample.
// Lists all pages from the provided parameters
publicstaticvoidlistPages(StringprojectId,StringagentId,StringflowId,Stringlocation)
throwsIOException{
// Note: close() needs to be called on the PagesClient object to clean up resources
// such as threads. In the example below, try-with-resources is used,
// which automatically calls close().
try(PagesClient client=PagesClient .create()){
BuilderlistRequestBuilder=ListPagesRequest .newBuilder();
StringparentPath=
String.format(
"projects/%s/locations/%s/agents/%s/flows/%s",projectId,location,agentId,flowId);
listRequestBuilder.setParent(parentPath);
listRequestBuilder.setLanguageCode("en");
// Make API request to list all pages in the project
for(Page element:client.listPages(listRequestBuilder.build()).iterateAll()){
System.out.println(element);
}
}
}

Node.js

To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

asyncfunctionlistPages(projectId,agentId,flowId,location){
constpagesClient=newPagesClient();
constlistPageRequest={
parent:`projects/${projectId}/locations/${location}/agents/${agentId}/flows/${flowId}`,
languageCode:'en',
};
constresponse=awaitpagesClient.listPages(listPageRequest);
console.log(response);
}

Python

To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

async deflist_page(project_id, agent_id, flow_id, location):
 pages_client = PagesAsyncClient()
 request = ListPagesRequest()
 request.parent = (
 f"projects/{project_id}/locations/{location}/agents/{agent_id}/flows/{flow_id}"
 )
 request.language_code = "en"
 response = await pages_client.list_pages(request=request)
 return response

Delete pages

To delete a page for your agent, call the delete method on the Page type.

Select a protocol and version for the Page reference:

Protocol V3 V3beta1
REST Page resource Page resource
RPC Page interface Page interface
C++ PagesClient Not available
C# PagesClient Not available
Go PagesClient Not available
Java PagesClient PagesClient
Node.js PagesClient PagesClient
PHP Not available Not available
Python PagesClient PagesClient
Ruby Not available Not available

Java

To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

importcom.google.cloud.dialogflow.cx.v3.DeletePageRequest ;
importcom.google.cloud.dialogflow.cx.v3.DeletePageRequest.Builder;
importcom.google.cloud.dialogflow.cx.v3.PagesClient ;
importjava.io.IOException;
publicclass DeletePage{
publicstaticvoidmain(String[]args)throwsIOException{
// TODO(developer): Replace these variables before running the sample.
StringprojectId="my-project-id";
StringagentId="my-agent-id";
StringflowId="my-flow-id";
StringpageId="my-page-id";
Stringlocation="my-location";
deletePage(projectId,agentId,flowId,pageId,location);
}
// DialogFlow API Delete Page Sample.
// Deletes a page from the provided parameters
publicstaticvoiddeletePage(
StringprojectId,StringagentId,StringflowId,StringpageId,Stringlocation)
throwsIOException{
// Note: close() needs to be called on the PagesClient object to clean up resources
// such as threads. In the example below, try-with-resources is used,
// which automatically calls close().
try(PagesClient client=PagesClient .create()){
BuilderdeleteRequestBuilder=DeletePageRequest .newBuilder();
deleteRequestBuilder.setName(
"projects/"
+projectId
+"/locations/"
+location
+"/agents/"
+agentId
+"/flows/"
+flowId
+"/pages/"
+pageId);
// Make API request to delete page
client.deletePage(deleteRequestBuilder.build());
System.out.println("Successfully deleted page!");
}
}

Node.js

To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

asyncfunctiondeletePage(projectId,agentId,flowId,pageId,location){
constpagesClient=newPagesClient();
constreq={
name:`projects/${projectId}/locations/${location}/agents/${agentId}/flows/${flowId}/pages/${pageId}`,
};
constresponse=awaitpagesClient.deletePage(req);
console.log(response);
}

Python

To authenticate to Dialogflow, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

async defdelete_page(project_id, agent_id, flow_id, page_id, location):
 pages_client = PagesAsyncClient()
 request = DeletePageRequest()
 request.name = f"projects/{project_id}/locations/{location}/agents/{agent_id}/flows/{flow_id}/pages/{page_id}"
 response = await pages_client.delete_page(request=request)
 return response

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.