Create tasks from App Engine app

App Engine app for tutorial: Using Cloud Tasks to trigger Cloud Functions.

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample

Node.js

To learn how to install and use the client library for Cloud Tasks, see Cloud Tasks client libraries.

app.post('/send-email', (req, res) => {
  // Set the task payload to the form submission.
  const {to_name, from_name, to_email, date} = req.body;
  const payload = {to_name, from_name, to_email};

  createHttpTaskWithToken(
    process.env.GOOGLE_CLOUD_PROJECT,
    QUEUE_NAME,
    QUEUE_LOCATION,
    FUNCTION_URL,
    SERVICE_ACCOUNT_EMAIL,
    payload,
    date
  );

  res.status(202).send('📫 Your postcard is in the mail! 💌');
});

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser