Calls

A common type of workflow step uses the call field to run a function and return a result:

YAML

  
 - 
  
  STEP_NAME 
 
 : 
  
 call 
 : 
  
  FUNCTION_NAME 
 
  
 args 
 : 
  
  ARG_1 
 
 : 
  
  VALUE_1 
 
  
  ARG_2 
 
 : 
  
  VALUE_2 
 
  
 ... 
  
 result 
 : 
  
  OUTPUT_VARIABLE 
 

JSON

  
 [ 
  
 { 
  
 " STEP_NAME 
" 
 : 
  
 { 
  
 "call" 
 : 
  
 " FUNCTION_NAME 
" 
 , 
  
 "args" 
 : 
  
 { 
  
 " ARG_1 
" 
 : 
  
 " VALUE_1 
" 
 , 
  
 " ARG_2 
" 
 : 
  
 " VALUE_2 
" 
  
 }, 
  
 "result" 
 : 
  
 " OUTPUT_VARIABLE 
" 
  
 } 
  
 } 
  
 ] 

Replace the following:

  • FUNCTION_NAME : the name of the function you are calling
  • ARG_1 , ARG_2 (optional): if the function accepts parameters, the arguments you are passing and their values ( VALUE_1 , VALUE_2 )
  • OUTPUT_VARIABLE (optional): if the function returns anything, the variable to store the returned data in

Calls are often HTTP requests but can be made to any function including a connector, a standard library function, or a subworkflow (user-defined function):

  • Connectors can be used to connect to other Google Cloud APIs within a workflow, and to integrate your workflows with those products, allowing you to perform operations from other Google Cloud services.
  • Standard library functions include modules and frequently used functions, such as for data type and format conversions, as well as functions that make HTTP calls like http.get and http.post . To access HTTP response data saved in a variable, see Make an HTTP request .
  • Subworkflows let you define a piece of logic that can be called from the main workflow, similar to a routine or function in a programming language.

Samples

The following samples demonstrate the syntax. For more samples, see Make an HTTP request .

Assign the response from an API call

This sample 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.

YAML

  main 
 : 
  
 params 
 : 
  
 [ 
 input 
 ] 
  
 steps 
 : 
  
 - 
  
 checkSearchTermInInput 
 : 
  
 switch 
 : 
  
 - 
  
 condition 
 : 
  
 '${"searchTerm" 
  
 in 
  
 input}' 
  
 assign 
 : 
  
 - 
  
 searchTerm 
 : 
  
 '${input.searchTerm}' 
  
 next 
 : 
  
 readWikipedia 
  
 - 
  
 getLocation 
 : 
  
 call 
 : 
  
 sys.get_env 
  
 args 
 : 
  
 name 
 : 
  
 GOOGLE_CLOUD_LOCATION 
  
 result 
 : 
  
 location 
  
 - 
  
 setFromCallResult 
 : 
  
 assign 
 : 
  
 - 
  
 searchTerm 
 : 
  
 '${text.split(location, 
  
 "-")[0]}' 
  
 - 
  
 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]}' 
 

JSON

  { 
  
 "main" 
 : 
  
 { 
  
 "params" 
 : 
  
 [ 
  
 "input" 
  
 ], 
  
 "steps" 
 : 
  
 [ 
  
 { 
  
 "checkSearchTermInInput" 
 : 
  
 { 
  
 "switch" 
 : 
  
 [ 
  
 { 
  
 "condition" 
 : 
  
 "${\"searchTerm\" in input}" 
 , 
  
 "assign" 
 : 
  
 [ 
  
 { 
  
 "searchTerm" 
 : 
  
 "${input.searchTerm}" 
  
 } 
  
 ], 
  
 "next" 
 : 
  
 "readWikipedia" 
  
 } 
  
 ] 
  
 } 
  
 }, 
  
 { 
  
 "getLocation" 
 : 
  
 { 
  
 "call" 
 : 
  
 "sys.get_env" 
 , 
  
 "args" 
 : 
  
 { 
  
 "name" 
 : 
  
 "GOOGLE_CLOUD_LOCATION" 
  
 }, 
  
 "result" 
 : 
  
 "location" 
  
 } 
  
 }, 
  
 { 
  
 "setFromCallResult" 
 : 
  
 { 
  
 "assign" 
 : 
  
 [ 
  
 { 
  
 "searchTerm" 
 : 
  
 "${text.split(location, \"-\")[0]}" 
  
 } 
  
 ] 
  
 } 
  
 }, 
  
 { 
  
 "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]}" 
  
 } 
  
 } 
  
 ] 
  
 } 
 } 
 

Make an external HTTP POST request

This sample makes a POST request to an external HTTP endpoint.

YAML

  - 
  
 send_message 
 : 
  
 call 
 : 
  
 http.post 
  
 args 
 : 
  
 url 
 : 
  
 https://www.example.com/endpoint 
  
 body 
 : 
  
 some_val 
 : 
  
 "Hello 
  
 World" 
  
 another_val 
 : 
  
 123 
  
 result 
 : 
  
 the_message 
 - 
  
 return_value 
 : 
  
 return 
 : 
  
 ${the_message.body} 
 

JSON

  [ 
  
 { 
  
 "send_message" 
 : 
  
 { 
  
 "call" 
 : 
  
 "http.post" 
 , 
  
 "args" 
 : 
  
 { 
  
 "url" 
 : 
  
 "https://www.example.com/endpoint" 
 , 
  
 "body" 
 : 
  
 { 
  
 "some_val" 
 : 
  
 "Hello World" 
 , 
  
 "another_val" 
 : 
  
 123 
  
 } 
  
 }, 
  
 "result" 
 : 
  
 "the_message" 
  
 } 
  
 }, 
  
 { 
  
 "return_value" 
 : 
  
 { 
  
 "return" 
 : 
  
 "${the_message.body}" 
  
 } 
  
 } 
 ] 
 
Create a Mobile Website
View Site in Mobile | Classic
Share by: