Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

cloud function task within an application integration

now I have an application integration that consists of 3 main components 

1) API Trigger 

2) Cloud function 

3)Data mapper task

the integration takes a json object as an input and should call the cloud function for some simple property extraction in node.js and should also return a json object as an output of integration 

the problem is I can not receive the output of the cloud function step in my data mapper step 

the cloud function executes successfully according to the logs and returns in error info { "message": "", "code": 0.0 }

 

// Cloud Function (JavaScript)
exports.helloWorld = (req, res) => {
  const { f_name, l_name, age, title, startdate } = req.body;

  // Calculate the full name
  const fullname = `${f_name} ${l_name}`;

  // Calculate the working period (assumes startdate is in 'YYYY-MM-DD' format)
  const startDate = new Date(startdate);
  const currentDate = new Date();
  const workingPeriod = Math.floor((currentDate - startDate) / (1000 * 60 * 60 * 24 * 365.25));

   Return the new object
   res.json({
    fullname: fullname,
    title: title,
  workingPeriod: workingPeriod
   });
 
};
Solved Solved
0 12 454
2 ACCEPTED SOLUTIONS

The issue is the format of the output. There are two choices here.

1. Create cloud function on Application Integration UI. https://cloud.google.com/application-integration/docs/configure-cloud-function-task#configure-the-cl.... This will create a python cloud function with proper template. So you don't need to worry about format.

2. Use javascript but with correct output format. The format should be like 

 
let response = {"eventParameters":{"parameters":[{"key":"input","value":{"stringValue":"2"}}]}};
res.send(JSON.stringify(response));
 
 

View solution in original post

Ok,

I just took a look at following documentation : https://cloud.google.com/application-integration/docs/configure-cloud-function-task#format and saw a warning that could be related :

Note: Cloud Function task in Application Integration only supports Python language runtime. Contact technical support for information on using other runtime languages.

It would indicate your Cloud function has to be in Python?

View solution in original post

12 REPLIES 12

Hello,

I'm not creating lots of javascript cloud functions but from your code I see could the problem be the formating of the json payload?

Properties names should be between "" like for example res.json({ "foo": "bar"});

Do you get the expected payload when you call the Cloud function from Postman or another tool?

Regards

Philippe

am sure that the cloud function itself runs and returns the expected output because I tried this from another application integration that calls the cloud function but using REST callout instead of Cloud function task 
I just can not get it done using the cloud function task , can not receive the output object though the integration executes successfully with no errors 

Ok,

I just took a look at following documentation : https://cloud.google.com/application-integration/docs/configure-cloud-function-task#format and saw a warning that could be related :

Note: Cloud Function task in Application Integration only supports Python language runtime. Contact technical support for information on using other runtime languages.

It would indicate your Cloud function has to be in Python?

Forget my answer, is incomplete. @fengwan has a better one.

The issue is the format of the output. There are two choices here.

1. Create cloud function on Application Integration UI. https://cloud.google.com/application-integration/docs/configure-cloud-function-task#configure-the-cl.... This will create a python cloud function with proper template. So you don't need to worry about format.

2. Use javascript but with correct output format. The format should be like 

 
let response = {"eventParameters":{"parameters":[{"key":"input","value":{"stringValue":"2"}}]}};
res.send(JSON.stringify(response));
 
 

great this is how I will return the response in my cloud function 
how can I configure and receive it in my application integration ?

You can use "Link existing function" on the cloud function task config panel. Application Integration will parse the response and set the variable accordingly. 

I already did that and linked it to the existing cloud function, 
so just to make sure I get this straight

if I need to return this object { "fullname": "John Doe", "title": "Software Engineer", "workingPeriod": 9 }
 it needs to be in this format  ??

  // Prepare the response in the required format
  const response = {
    eventParameters: {
      parameters: [
        {
          key: "fullname",
          value: { stringValue: fullname }
        },
        {
          key: "title",
          value: { stringValue: title }
        },
        {
          key: "workingPeriod",
          value: { stringValue: workingPeriod.toString() }  // Convert to string if needed
        }
      ]
    }
  };

  // Send the formatted response as JSON
  res.send(JSON.stringify(response));



Yes, and remember to use quota on key/value/stringValue/etc

Yes this is correct. And you would need to create variables with same name in the integration as well.

should these parameters be defined in the cloud function task parameters or output variables of integration ?

Since you don't need to read those param inside the cloud function, you don't have to add them in the task param. And based on your need, you can define them as output or local variables.

Top Labels in this Space