MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

document-warehouse/get-document.js:17–72  ·  view source on GitHub ↗
(
  projectNumber = 'YOUR_PROJECT_NUMBER',
  location = 'YOUR_PROJECT_LOCATION',
  documentId = 'YOUR_DOCUMENT_ID',
  userId = 'user:xxx@example.com'
)

Source from the content-addressed store, hash-verified

15
16'use strict';
17async function main(
18 projectNumber = 'YOUR_PROJECT_NUMBER',
19 location = 'YOUR_PROJECT_LOCATION',
20 documentId = 'YOUR_DOCUMENT_ID',
21 userId = 'user:xxx@example.com'
22) {
23 // [START contentwarehouse_get_document]
24
25 /**
26 * TODO(developer): Uncomment these variables before running the sample.
27 * const projectNumber = 'YOUR_PROJECT_NUMBER';
28 * const location = 'YOUR_PROJECT_LOCATION'; // Format is 'us' or 'eu'
29 * documentId = 'YOUR_DOCUMENT_ID';
30 * const userId = 'user:xxx@example.com'; // Format is "user:xxx@example.com"
31 */
32
33 // Import from google cloud
34 const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1;
35
36 const apiEndpoint =
37 location === 'us'
38 ? 'contentwarehouse.googleapis.com'
39 : `${location}-contentwarehouse.googleapis.com`;
40
41 // Create service client
42 const serviceClient = new DocumentServiceClient({
43 apiEndpoint: apiEndpoint,
44 });
45
46 // Get Document Schema
47 async function getDocument() {
48 // Initialize request argument(s)
49 const documentRequest = {
50 // The full resource name of the document, e.g.:
51 // projects/{project_number}/locations/{location}/documents/{document_id}
52 name: serviceClient.projectLocationDocumentPath(
53 projectNumber,
54 location,
55 documentId
56 ),
57 requestMetadata: {userInfo: {id: userId}},
58 };
59
60 // Make Request
61 const response = serviceClient.getDocument(documentRequest);
62
63 // Print out response
64 response.then(
65 result => console.log(`Document Found: ${JSON.stringify(result)}`),
66 error => console.log(`${error}`)
67 );
68 }
69
70 // [END contentwarehouse_get_document]
71 await getDocument();
72}
73
74main(...process.argv.slice(2)).catch(err => {

Callers 1

get-document.jsFile · 0.70

Calls 1

getDocumentFunction · 0.85

Tested by

no test coverage detected