This article guides you on how to use our API to gift a tree to every client who fills a Microsoft form, using Power Automate
How it works
This process uses the Tree-Nation's API to trigger the plantation of trees.
The basic information about the recipient is collected through a form and sent to Tree-Nation via our API. The API then generates a link to send to the recipient. With this link, the recipient can access his tree.
What you need
In order to use this process, you need connection information provided by Tree-Nation:
- API key (token) : your identifier to access the API
- Planter ID : to link the trees planted to your forest - User ID : same as Planter ID
- The species ID used to specify the species you plant
For more information on our API, please refer to this documentation.
To get your API Test Token and access to the test site, please fill the form at the end of this page.
Create the form
The purpose of the form is to collect the information that is needed to plant a tree.
Using Microsoft Forms, create a simple form with at least 3 inputs : name, email address and message.
Create the power automate flow
The purpose of the Power Automate flow is to automatically collect the information from the form, plant the tree and send a confirmation to the recipient.
The flow consist of 5 steps:
- A new filled form is received
- Get the content of this form
- Call the Tree-Nation API to plant the tree
- Extract data from the API’s response
- Send an email to the recipient with the information collected
The email sent is located in a « For each » group because the API accepts the plantation of more than one tree at a time.
The trigger is a new form reply.
When someone fills the form, the reply is stored in the list of replies. And when a new reply appears on the list, the flow is triggered.
The form ID is the name of the form. This input field helps you navigate to the right form. The next step is to get the content of the reply.
Call the Tree-Nation’s API
The call to the API is an http POST request. All the text between <braquest> has to be replaced by your personal data.
A test API is available to build and test your flow.
Send the confirmation to the recipient
The information of the confirmation that is going to be sent to the recipient has to be retrieved by the response sent by the API. This response is a JSON fragment based on this scheme:
The content to be analyzed is the Body sent by the previous step (http request).
The next step (send an email) is embedded in a For Each loop because the API accepts multiple trees to be planted and the response sends the information about the trees in an array called "trees".
At this step, the Email address and Message variables are picked from the Form content, and the collect_url comes from the http request response extracted in the previous step.
Here is the email result :
This integration makes you the sender of the Tree-Gifts and not us by default.
In case you want us to be the ones sending the Tree-Gifts to your recipients, let us know, and remove the last step (send an email) from the flow.
This integration shares the emails of your recipients with us by default so that only the true recipient of the email can claim the Tree-Gift. If you are concerned with GDPR, you may remove the email from the HTTP flow, as it is not mandatory (line 5 of the body).