Reputation: 2017
I'm a little confused by this documentation. I may be reading this wrong, but the documentation says that you can add variables to the input
object based on what you define in the text fields coming from what is given by the trigger. According to this picture, the user is defining 3 input variables body
, receiveDate
, and subject
.
(source: cachefly.net)
However in the code, they are referencing a variable called plainBody
which hasn't been defined. How would this work?
Is there an object that I can log out that has every field that comes through in my trigger? Or do I have to define them as inputs using the input fields?
Edit: I also can't get any of the z
libraries to work. According to this documentation: https://zapier.com/developer/documentation/v2/built-functions-tools/#available-libraries I should be able to do something like
// let's call http://httpbin.org/get?hello=world with an extra header
var request = {
method: 'GET',
url: 'http://httpbin.org/get',
params: {
hello: 'world'
},
headers: {
Accept: 'application/json'
},
auth: null,
data: null
};
// perform asynchronously
z.request(request, function(err, response){
console.log('Status: ' + response.status_code);
console.log('Headers: ' + JSON.stringify(response.headers));
console.log('Content/Body: ' + response.content);
});
But I get an error that says z is not defined theFunction
Upvotes: 0
Views: 567
Reputation: 3572
developer from Zapier here!
The data you provide in the input
object is all that will be provided to your code when it runs; unfortunately it looks like there's a typo in that example screenshot (both of the checks in that conditional should be for input.body
).
The documentation link you referenced is for the Zapier Developer Platform, which is how you add your own app to Zapier for other people to use. That also runs Javascript on the backend, so I see how it's easy for the two things to get mixed up!
You're looking for the documentation related to running code in a Zap.
To answer your question directly, there is no z
object available in the Code by Zapier app. To make HTTP requests, you need to use the fetch
library:
fetch('http://example.com/')
.then(function(res) {
return res.text();
}).then(function(body) {
var output = {id: 1234, rawHTML: body};
callback(null, output);
}).catch(function(error) {
callback(error);
});
That code is taken from the Introductory HTTP Example in the linked documentation.
Hope that helps!
Upvotes: 1