This article provides a step-by-step guide on how to send tree gifts through Tree-Nation's email system using Zapier, rather than your own email service.
Step 1: Request an API Token
To receive your token and installation instructions, please fill the form below and submit it. Your API-token will be sent via email soon after.
Step 2: Setup your Trigger
We will review a case below where we will offer a tree to every person added into our Zoho CRM.
- Start by creating a zap trigger. To do that, go to your Zapier Homepage and at the top left corner click on create Zaps.
- Click on the Trigger button to select the app that will perform the trigger. In our case example, It is HubSpot.
- On the setup tab, select the App and its trigger that will offer a tree to your recipient, and connect your account. In the case below, we have used Zoho app to offer trees to every new contact.
- On the test tab, test the trigger to obtain a list of records that will be used as examples to visualise their properties.
Note the properties displayed that contains the information of the name of the recipient and his email address. You will use these fields later.
Step 3: Setup your Action
- Add an action step on the Zapier Zap and choose Code
- On the setup tab, set the Action event to "Run Javascript"
- On the configure tab, set the following parameters:
- Input data:
- email: Add the email of the recipient obtained through trigger
- name: Add the name of the recipient obtained through trigger
- Code: Paste the code below and replace the token in the second line with yours
- Input data:
const url = 'https://tree-nation.com/api/plant';
const token = 'abcdefgh123456789';
// Prepare the request body using the input data
const requestBody = {
recipients: [
{
name: inputData.name || 'Unknown',
email: inputData.email || 'unknown@example.com'
}
],
quantity: 1,
language: 'en',
message: 'Thank you for planting trees at our side!'
};
// Send a POST request to the API endpoint
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
});
// Check if the response is not successful and throw an error if so
if (!response.ok) throw new Error('Failed to send request');
// Parse the JSON response
const data = await response.json();
// Prepare the output with the response data
output = data;
You should now be able to test your integration. Complete your test and publish your zap to automate your planting habit with Tree-Nation.