| 44 | |
| 45 | // Get Document Schema |
| 46 | async function quickstart() { |
| 47 | // The full resource name of the location, e.g.: |
| 48 | // projects/{project_number}/locations/{location} |
| 49 | const parent = `projects/${projectNumber}/locations/${location}`; |
| 50 | |
| 51 | // Initialize request argument(s) |
| 52 | const schemaRequest = { |
| 53 | parent: parent, |
| 54 | documentSchema: { |
| 55 | displayName: 'My Test Schema', |
| 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 | }; |
| 66 | |
| 67 | // Create Document Schema |
| 68 | const documentSchema = |
| 69 | await schemaClient.createDocumentSchema(schemaRequest); |
| 70 | |
| 71 | const documentRequest = { |
| 72 | parent: parent, |
| 73 | document: { |
| 74 | displayName: 'My Test Document', |
| 75 | documentSchemaName: documentSchema[0].name, |
| 76 | plainText: "This is a sample of a document's text.", |
| 77 | properties: [ |
| 78 | { |
| 79 | name: 'testPropertyDefinitionName', |
| 80 | textValues: {values: ['GOOG']}, |
| 81 | }, |
| 82 | ], |
| 83 | }, |
| 84 | requestMetadata: {userInfo: {id: userId}}, |
| 85 | }; |
| 86 | |
| 87 | // Make Request |
| 88 | const response = serviceClient.createDocument(documentRequest); |
| 89 | |
| 90 | // Print out response |
| 91 | response.then( |
| 92 | result => console.log(`Document Created: ${JSON.stringify(result)}`), |
| 93 | error => console.log(`error: ${error}`) |
| 94 | ); |
| 95 | } |
| 96 | |
| 97 | // [END contentwarehouse_quickstart] |
| 98 | await quickstart(); |