I have a nodejs function in Lambda that works fine. However when I try to integrate it with Zapier. The function doesn’t return a value to Zapier. Is their a specific way to callback your function in lambda so that Zapier can receive the returned values?
Well, you can show as some code to get an idea. My guess is that you return an object to Zapier, while Zapier always expects an array of data. If I am correct, try to wrap your object in array before send.
Related
I have seen three ways to return a JSON object or end a Lambda function. My trigger is Smart Home Alexa.
I am using now is context.succeed(response_JSON);This one works for me. Even if this instructions is inside a nested function. The whole Lambda ends and return the response_JSON to Smart Home Alexa.
I have seen in other blogs that say callback(response_error,response_JSON). This one did not work for me. It did not return anything to Smart Home.
Others just uses the return response_JSON. I have not used this one.
I am using now is context.succeed(response_JSON);This one works for me. Even if this instructions is inside a nested function. The whole Lambda ends and return the response_JSON to Smart Home Alexa.
context.succeed()/fail() causes the Lambda function to terminate immediately. However, I have not seen this documented in the context object docs, so it may get deprecated in later Node versions (?).
I have seen in other blogs that say callback(response_error,response_JSON). This one did not work for me. It did not return anything to Smart Home.
This one probably doesn't work for you because by default Node.js waits for the event loop to be empty before executing the callback statement. This may be due to open network/database connection. As per the doc, set the context.callbackWaitsForEmptyEventLoop variable to false to send the response right away.
Others just uses the return response_JSON. I have not used this one.
This should be used with async handlers. Read more about async and non-async handlers here: https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html
I'm facing an issue where when my twilio funciton is called, when i pass in two function parameters as shown below, they cannot be accessed from within the twilio function. The error says that event.name is undefined. but im passing a parameter called name through the funciton like shown below. So after passing a paremeter like this (edit: here im passing test but its the same output for test as well) :
I get this output
my code is as below :
FIXED! Sorry it was totally a problem on my end, I had configured the SMS and the Call for the same number, that was creating a bit of a issue.
What do you get back when you log out the entire event object stringified like so; console.log(JSON.stringify(event))
I am trying to use the google cloud console to test a cloud function. Below is a snippet.
exports.requestCreated = functions.firestore
.document('users/{userId}/requests/{requestId}')
.onWrite((change, context) => {
// execute operation
});
I have tried all sorts of combination of JSON data. E.g.
{"userId":"Xl86pqOpF9T2MAn12p24OJAfYJW2","requestId":"abc1234"}
But I keep getting the following statement in logs:
Request created by {userId}
The actual userId is not being read from the JSON data in the console. Can you help?
This is not a problem with the execution of the cloud function. It's a problem with hardcoding the string.
'users/{userId}/requests/{requestId}' is a hardcoded string. Node.js will not automatically replace {userId} with the value of the variable userId.
Following this previous SO post, try something like this using template strings:
`users/${userId}/requests/${requestId}`
Please note it is surrounded by backticks (`), not single quotes (').
This assumes you already have a userId and requestId variables defined. You must restructure your cloud function like this to retrieve that data. Notice that the specific variable values must be extracted from the event variable.
Thank you, Nareddyt. The function is for Firestore, and the way it is written right now checks if a new document is created under the collection requests. I tried replacing the string as you suggested, but as you pointed out, it requires these variables to be defined. I do not quite understand how to restructure the cloud function because the syntax I have used is how event detection is suggested in the Firestore documentation. My function currently works in its entirety, but testing it is a major pain. I have to go through my mobile app and do the whole userflow to test this function. I am new to Node.js and any guidance would be appreciated.
The MySQL JavaScript api is asynchronous.
If I try to write the filling REST Endpoint it fails as the call to MySQL is asynchronous.
#endpoint
String getSometing(){
RetVal = MySQL.asynchApiQuery(“someSql”)
return RetVal;
}
It will fail as RetVal will not be populated when the function returns.
I’ve spoken to a number of people who rave about JavaScripts asynchronous capabilities yet they have been unable to solve this simple synchronous problem
I’m hoping for a simple answer but so far all I’ve got is observable,promise, subscribe, continuation all of which cannot return the query as a promise simply creates a new thread that cannot be associated with the invoked of the REST api.
Any answer to this should return RetVal and not simply print it.
Look forward to a simple answer.
It's asynchronous but it has something named "callback functions". You can use them to decide what's going to happen with data after a mysql query
Example:
db.query("sqlquery",(err,data)=>{console.log(data)})
In the spirit of test-driven development, I'm trying to find a way to verify that my API can return results wrapped in a callback function when requested to do so. Like this:
GET http://example.com/api/resource/?callback=handleThis
handleThis( {"foo": "bar"} );
I'm using mocha & supertest. Short of turning the response variable into a string and comparing that to a reference string, is there any other clever way to verify that the test suite is receiving a function call with JSON inside?
You must use sinon and stub the handleThis function.