GoogleCloudPlatform / nodejs-docs-samples

Node.js samples for Google Cloud Platform products.
https://cloud.google.com/nodejs
Apache License 2.0
2.81k stars 1.95k forks source link

Jobs API requestMetadata #1112

Closed codenprose closed 5 years ago

codenprose commented 5 years ago

In the location-search-sample there isn't any info on how to obtain the userId and sessionId values for the required requestMetadata property.

The docs mention that UNKNOWN can be used in the absence of said values, but I'm currently not getting a matchingJobs property back in the SearchJobsResponse object.

I've authenticated via a service account. My initial assumption is that I need to introduce outh2 flow to get a userId and sessionId? If so, why are these required?

Example Request

const getJobs = async () => {
  try {
    const REQUEST_META_DATA = {
      userId: 'UNKNOWN',
      sessionId: 'UNKNOWN',
      domain: 'UNKNOWN'
    };

    const jobServiceClient = await createAuthCredential();

    const locationFilter = {
      address: JOB_LOCATION,
      distanceInMiles: 50,
    };

    const jobQuery = {
      query: JOB_KEYWORD,
      locationFilters: [locationFilter]
    };

    const request = {
      parent: `projects/${PROJECT_ID}`,
      resource: {
        jobQuery: jobQuery,
        requestMetadata: REQUEST_META_DATA,
        searchMode: 'JOB_SEARCH',
        jobView: 'JOB_VIEW_FULL',
        orderBy: 'posting_publish_time desc'
      },
    };

    const result = await jobServiceClient.projects.jobs.search(request);
    return result.data.matchedJobs // returns undefined
  } catch (e) {
    console.error(e);
    throw e;
  }
};
fhinkel commented 5 years ago

@dkh215 👋 thanks for reporting the issue.

@RenlongZ can you have a look at the samples please. Thanks!

RenlongZ commented 5 years ago

@dkh215 Thanks for asking the issue. Actually, all fields in REQUEST_META_DATA have nothing to do with authentication.

The REQUEST_META_DATA collected here is about the job searcher. Our system would use this information to improve the search quality of the service. The identifiers, (such as userId or sessionId) should be provided by you, and must be unique and consistent.

See https://cloud.google.com/talent-solution/job-search/docs/search#requestmetadata for more information.