Using a popular CMS? Maybe we already have a module for your CMS system. Check our Integrations

Treerating is using a simple CRUD style API with Create and Read commands available. Simply make a HTTP POST call to our API including your API credentials, and send your fields or commands to get what you want.

You will find your API key and username on your settings page when you are logged in on your Treerating account.

The URL of where you should make your API calls is http://www.treerating.com/api/v1/. Append commands such as /create/ or /read/ to the end of the API url depending on what request and action you are trying to do. All requests and responses should be done in json format.

When an order is created in your store, you need to send Treerating the order and customer information for us to be able to send out a review-request to the customer and ask them for their review, rating and feedback. We also use this information to be able to verify the reviewer and know what reviewer that is basing their review on real customer experience and not.

You can decide yourself how long you want us to wait before we ask the customer for a review. You do this by setting your "Send Delay" setting on your Settings page.

To create an order you will do a Create request, which means that you will send your POST call to http://www.treerating.com/api/v1/create/.

Here is an example of a simple Create request that creates an order in Treerating:

// The API URL of Treerating $url = 'http://www.treerating.com/api/v1/create/'; // Create the array of data that will be send $fields = array(); $fields['username'] = "_YOUR_TREERATING_USERNAME_"; // Replace with your own username $fields['apikey'] = "_YOUR_TREERATING_API_KEY_"; // Replace with your own API key $fields['first_name'] = "Jane"; $fields['last_name'] = "Doe"; $fields['email'] = "jane.doe@mail.com"; $fields['order_id'] = "123456"; // Must be an unique id $fields['order_date'] = "2015-03-05 11:03:15"; $fields['language'] = "sv"; // Make a HTTP POST call to the API URL // Remember to also json_encode() your $fields-array before sending $result = $this->postCall($url, $fields);

Remember to encode your array into json format before you send it. Our API expects all data to be send in json.

A short description of each line:

  • Note that the $url got /create/ in the end because we are doing a Create request call.
  • $fields['username'] is our API username and can be found on your settings page.
  • $fields['apikey'] is our API key and can be found on your settings page.
  • $fields['first_name'] is the customers first name.
  • $fields['last_name'] is the customers last name.
  • $fields['email'] is the customers email. We use this email to send a request email where we ask for an review.
  • $fields['order_id'] is your own internal order id. This id must be unique. You can not have 2 orders with the same order_id.
  • $fields['order_date'] is the date of when your order was created. We use this date to calculate when the review request email should be send using your "Send Delay" setting on your profile settings page.
  • $fields['language'] is the iso code of what language we should use to contact the user in with our review request email. Recommended is to use the same language as the user browsed your website in. Else use en.
  • $this->postCall() is the function that makes the HTTP POST call and sends the data to the API URL. The function also encodes the $fields into json before the request is made. All requests should be send in json format.

To get your aggregated, average rating and display it on your own website, you need to make a read request call to our API. You do this by sending your HTTP POST request to http://www.treerating.com/api/v1/read/.

You will then get your rating, your profile url, your Treerating image badge and other data send back to you in json format.

To display it on your website, use the data we send you and format it just the way you want it yourself. Remember to use Rich Snippets to make sure you get full advantage of the rating in the search engine search results.

Here is an example of a simple Read request that get your rating and profile data:

// The API URL of Treerating $url = 'http://www.treerating.com/api/v1/read/'; // Create the array of data that will be send $fields = array(); $fields['username'] = "_YOUR_TREERATING_USERNAME_"; // Replace with your own username $fields['apikey'] = "_YOUR_TREERATING_API_KEY_"; // Replace with your own API key $fields['get'] = 'rating_block'; // Make the HTTP POST call and save the response in $result $result = $this->postCall($url, $fields); // Remember, all responses from Treerating are done in json. So you need to decode it first. $result = json_decode($result, true); // Check if result was successfully fetched if($result['status'] == 'OK') { $rating = $result['rating']; $url = $result['url']; $total_reviews = $result['total_reviews']; $image = $result['star_image']; // Use the data fetched to return it into your HTML view // and display it to the visitors on your website. } // If status is not OK, return null to make sure nothing is displayed on the website. else { return null; }

You can then use the data returned to format your own HTML and display it just the way you want in your own language. However remember to use Rich Snippets to get full power out of the ratings.

$fields['get'] tell the API what it is that you want to read from it. rating_block is the value required to make the API return your aggregated rating used in the example above.