Make a call to a sample API

Makes a call to a sample API. The returned day of the week is passed to the Wikipedia API. Relevant articles on Wikipedia about the current day of the week are returned.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

Node.js

Before trying this sample, follow the Node.js setup instructions in the Workflows quickstart using client libraries. For more information, see the Workflows Node.js API reference documentation.

/**
 * TODO(developer): Uncomment these variables before running the sample.
 */
// const projectId = 'my-project';
// const location = 'us-central1';
const {WorkflowsClient} = require('@google-cloud/workflows');
const client = new WorkflowsClient();
async function listWorkflows() {
  const [workflows] = await client.listWorkflows({
    parent: client.locationPath(projectId, location),
  });
  for (const workflow of workflows) {
    console.info(`name: ${workflow.name}`);
  }
}
listWorkflows();

YAML

main:
  params: [input]
  steps:
    - checkInputExists:
        switch:
          - condition: ${input != null}
            next: checkSearchTermInInput
        next: getCurrentTime
    - checkSearchTermInInput:
        switch:
          - condition: ${"searchTerm" in input}
            assign:
              - searchTerm: ${input.searchTerm}
            next: readWikipedia
    - getCurrentTime:
        call: http.get
        args:
          url: https://us-central1-workflowsample.cloudfunctions.net/datetime
        result: currentDateTime
    - setFromCallResult:
        assign:
          - searchTerm: ${currentDateTime.body.dayOfTheWeek}
    - readWikipedia:
        call: http.get
        args:
          url: https://en.wikipedia.org/w/api.php
          query:
            action: opensearch
            search: ${searchTerm}
        result: wikiResult
    - returnOutput:
        return: ${wikiResult.body[1]}

What's next

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