'Create cron job on Google Cloud with custom name

Reading the docs for the Nodejs Scheduler I did not found how to pass a name for the cron job I want to create.

Does anyone know if this package supports this?

I tried:

> const job = {
>         httpTarget: {
>           uri: `my_url`,
>           httpMethod: 'GET',
>         },
>         schedule: '0 0,8-17 * * 0-6',
>         timeZone: 'my_timezone',
>         body: Buffer.from(JSON.stringify({JOB_ID: 'custom_name', name: 'custom_name'})),
>         name: 'custom_name'
>       };


Solution 1:[1]

From looking at the API spec for the Cloud Scheduler Job resource and at the Nodejs Quickstart I think you need to move the body attribute within the httpTarget as the Job resource does not have a body attribute, it should be associated with the http request.

Based on your code you would end wanting something like this:

const job = {
  httpTarget: {
    uri: 'my_url',
    httpMethod: 'GET',
    body: Buffer.from(JSON.stringify({JOB_ID: 'custom_name', name: 'custom_name'})),
  },
  schedule: '0 0,8-17 * * 0-6',
  timeZone: 'my_timezone',
  name: 'custom_name'
};

Solution 2:[2]

I figured out what was wrong in order to set the name correctly we need to set the name with the project_id and the location_id

httpTarget: {
          uri: 'my_url',
          httpMethod: 'GET',
    
        },
        schedule: '0 0,8-17 * * 0-6',
        timeZone: 'my_timezone',
        name: 'projects/YOUR_PROJECT_ID/locations/YOUR_LOCATION_ID/jobs/YOUR_CUSTOM_JOB_NAME'

      };

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Marijan Klari?