Skip to content

Commit a7ed03c

Browse files
fix: Add endpoint override for Document AI Warehouse samples (#3585)
* fix: Add endpoint override for Document AI Warehouse samples - Reported in: - GoogleCloudPlatform/document-ai-samples#676 - https://www.googlecloudcommunity.com/gc/AI-ML/Document-AI-Warehouse-API-Sample-Python-Code-location-eu-Issue/td-p/677608 - https://stackoverflow.com/a/77648118/6216983 ## Description Fixes GoogleCloudPlatform/document-ai-samples#676 * Try changing endpoint to default for us * Change default endpoint to us * Fix formatting error --------- Co-authored-by: Patti Shin <[email protected]>
1 parent e6153a9 commit a7ed03c

File tree

8 files changed

+77
-27
lines changed

8 files changed

+77
-27
lines changed

document-warehouse/create-document-schema.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,38 @@ async function main(
3131
const {DocumentSchemaServiceClient} =
3232
require('@google-cloud/contentwarehouse').v1;
3333

34+
const apiEndpoint =
35+
location === 'us'
36+
? 'contentwarehouse.googleapis.com'
37+
: `${location}-contentwarehouse.googleapis.com`;
38+
3439
// Create service client
35-
const serviceClient = new DocumentSchemaServiceClient();
40+
const serviceClient = new DocumentSchemaServiceClient({
41+
apiEndpoint: apiEndpoint,
42+
});
3643

3744
// Create Document Schema
3845
async function createDocumentSchema() {
39-
// Initialize request argument(s)
40-
const request = {};
41-
42-
// Property Definition
43-
const propertyDefinition = {};
44-
propertyDefinition.name = 'testPropertyDefinitionName'; // Must be unique within a document schema (case insensitive)
45-
propertyDefinition.displayName = 'searchable text';
46-
propertyDefinition.isSearchable = true;
47-
propertyDefinition.textTypeOptions = {};
48-
49-
// Document Schema
50-
const documentSchema = {};
51-
documentSchema.displayName = 'My Test Schema';
52-
documentSchema.propertyDefinitions = [propertyDefinition];
53-
54-
request.documentSchema = documentSchema;
55-
5646
// The full resource name of the location, e.g.:
5747
// projects/{project_number}/locations/{location}
58-
request.parent = `projects/${projectNumber}/locations/${location}`;
48+
const parent = `projects/${projectNumber}/locations/${location}`;
49+
// Initialize request argument(s)
50+
const request = {
51+
parent: parent,
52+
// Document Schema
53+
documentSchema: {
54+
displayName: 'My Test Schema',
55+
// Property Definition
56+
propertyDefinitions: [
57+
{
58+
name: 'testPropertyDefinitionName', // Must be unique within a document schema (case insensitive)
59+
displayName: 'searchable text',
60+
isSearchable: true,
61+
textTypeOptions: {},
62+
},
63+
],
64+
},
65+
};
5966

6067
// Make Request
6168
const response = serviceClient.createDocumentSchema(request);

document-warehouse/delete-document-schema.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@ async function main(
3434
const {DocumentSchemaServiceClient} =
3535
require('@google-cloud/contentwarehouse').v1;
3636

37+
const apiEndpoint =
38+
location === 'us'
39+
? 'contentwarehouse.googleapis.com'
40+
: `${location}-contentwarehouse.googleapis.com`;
41+
3742
// Create service client
38-
const serviceClient = new DocumentSchemaServiceClient();
43+
const serviceClient = new DocumentSchemaServiceClient({
44+
apiEndpoint: apiEndpoint,
45+
});
3946

4047
// Delete Document Schema
4148
async function deleteDocumentSchema() {

document-warehouse/fetch-acl.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ async function main(
3434
// Import from google cloud
3535
const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1;
3636

37+
const apiEndpoint =
38+
location === 'us'
39+
? 'contentwarehouse.googleapis.com'
40+
: `${location}-contentwarehouse.googleapis.com`;
41+
3742
// Create service client
38-
const serviceClient = new DocumentServiceClient();
43+
const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint});
3944

4045
// Fetches access control policies on project or document level.
4146
async function fetchACL() {

document-warehouse/get-document-schema.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ async function main(
3232
const {DocumentSchemaServiceClient} =
3333
require('@google-cloud/contentwarehouse').v1;
3434

35+
const apiEndpoint =
36+
location === 'us'
37+
? 'contentwarehouse.googleapis.com'
38+
: `${location}-contentwarehouse.googleapis.com`;
39+
3540
// Create service client
36-
const serviceClient = new DocumentSchemaServiceClient();
41+
const serviceClient = new DocumentSchemaServiceClient({
42+
apiEndpoint: apiEndpoint,
43+
});
3744

3845
// Get Document Schema
3946
async function getDocumentSchema() {

document-warehouse/get-document.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@ async function main(
3333
// Import from google cloud
3434
const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1;
3535

36+
const apiEndpoint =
37+
location === 'us'
38+
? 'contentwarehouse.googleapis.com'
39+
: `${location}-contentwarehouse.googleapis.com`;
40+
3641
// Create service client
37-
const serviceClient = new DocumentServiceClient();
42+
const serviceClient = new DocumentServiceClient({
43+
apiEndpoint: apiEndpoint,
44+
});
3845

3946
// Get Document Schema
4047
async function getDocument() {

document-warehouse/quickstart.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ async function main(
3131
const {DocumentSchemaServiceClient, DocumentServiceClient} =
3232
require('@google-cloud/contentwarehouse').v1;
3333

34+
const apiEndpoint =
35+
location === 'us'
36+
? 'contentwarehouse.googleapis.com'
37+
: `${location}-contentwarehouse.googleapis.com`;
38+
3439
// Create service client
35-
const schemaClient = new DocumentSchemaServiceClient();
36-
const serviceClient = new DocumentServiceClient();
40+
const schemaClient = new DocumentSchemaServiceClient({
41+
apiEndpoint: apiEndpoint,
42+
});
43+
const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint});
3744

3845
// Get Document Schema
3946
async function quickstart() {

document-warehouse/search-document.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ async function main(
3232
// Import from google cloud
3333
const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1;
3434

35+
const apiEndpoint =
36+
location === 'us'
37+
? 'contentwarehouse.googleapis.com'
38+
: `${location}-contentwarehouse.googleapis.com`;
39+
3540
// Create service client
36-
const serviceClient = new DocumentServiceClient();
41+
const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint});
3742

3843
// Get Document Schema
3944
async function searchDocuments() {

document-warehouse/set-acl.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ async function main(
3737
//Import service client from google cloud
3838
const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1;
3939

40+
const apiEndpoint =
41+
location === 'us'
42+
? 'contentwarehouse.googleapis.com'
43+
: `${location}-contentwarehouse.googleapis.com`;
44+
4045
// Create client
41-
const serviceClient = new DocumentServiceClient();
46+
const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint});
4247

4348
// Set access control policies on project or document level.
4449
async function setACL() {

0 commit comments

Comments
 (0)