addObjectRecordComment

/api/v2/objectrecords/{objectRecordId}/comment

All authorized users can add a comment to an object record in eHive. A request to the /api/v2/objectrecords/{objectRecordId}/comment resource will return an Comment JSON object.


Try the addObjectRecordComment Method

You can enter real values into the form below and test them against our live API. The response you see is a genuine JSON response from the API.

Name Data Type Parameter Type Length Required Description
objectRecordId Integer Path 64-bit signed two's complement YES The id for the record you wish to add the comment to.
Comment Object Body YES The Comment domain object is made up of a commentorName, commentorEmailAddress and a commentText field.

	

Code Examples

Included below are some code snippets from our code samples projects. The examples show the main elements needed to use our API client libraries.

Java

Prerequisites

  1. Download the Java API client library.
  2. Create a new Java class file.
  3. Add the Java API client library JAR to your classpath.
  4. Create a blank file that is accessible from wherever you are running this example. The file is used to store your API authentication token, so it must be readable and writable. You can name the file anything you like as long as it is valid in Java.

Start Coding

  1. Instantiate an EHiveApi object. The EHiveApi object contains all of the methods available in the API. The API requires authentication credentials so you will need to configure your EHiveApi object with valid credentials. There are a number of ways to instantiate the EHiveApi object but for this example you will simply pass all of the parameters you need into the EHiveApi object's constructor:
    private static String clientId = "...462";
    private static String clientSecret = "...98a9";
    private static String trackingId = "...eaca";
    private static String pathToOauthPropertiesFile = "oauth.properties";
    ...
    EHiveApi eHiveApi = new EHiveApi(clientId, clientSecret, trackingId, pathToOauthPropertiesFile);
  2. Invoke the addObjectRecordComment() method and assign the return value to an Comment domain object as follows:
    Comment addedComment = eHiveApi.addObjectRecordComment(2509L, comment);
  3. Access the comment information using the Comment domain object's getter method.
    String comment = addedComment.getCommentText();
    System.out.println(comment);

View the full example below.

import com.ehive.api.EHiveApi;
import com.ehive.api.domain.comments.Comment;
import com.ehive.api.exceptions.EHiveApiException;
import com.ehive.api.exceptions.EHiveFatalServerException;
import com.ehive.api.exceptions.EHiveForbiddenException;
import com.ehive.api.exceptions.EHiveNotFoundException;
import com.ehive.api.exceptions.EHiveUnauthorizedException;

public class AddObjectRecordComment {
	
	private static String clientId = "...462";
	private static String clientSecret = "...98a9";
	private static String trackingId = "...eaca";
	private static String pathToOauthPropertiesFile = "oauth.properties";
	
	private static Long objectRecordId = 2509L;
	
	public static void main(String[] args) throws EHiveApiException, EHiveFatalServerException, EHiveNotFoundException, 
												  EHiveUnauthorizedException, EHiveForbiddenException {
			// Instantiate the EHiveApi object
			EHiveApi eHiveApi = new EHiveApi(clientId, clientSecret, trackingId, pathToOauthPropertiesFile);
			
			// Create a new Comment object
			Comment comment = new Comment();
			
			// Populate the parameters on the Comment request object
			comment.setCommentorEmailAddress("john.doe@ehivedevelopers.com");
			comment.setCommentorName("John Doe");
			comment.setCommentText("This is a test comment posted from developers.ehive.com. " +
													 "You can check the timestamp on the response below against the " +
													 "timestamp on the eHive object record to verify that your " +
													 "comment was added.");
			
			// Invoke an API method
			Comment addedComment = eHiveApi.addObjectRecordComment(objectRecordId, comment);
			
			// Print some output using the added comment object
			printObjectRecordInfo(addedComment);
	}
	
	private static void printObjectRecordInfo(Comment addedComment) {
		StringBuilder stringBuilder = new StringBuilder();
		
		stringBuilder.append("Commentor Name:\t\t " + addedComment.getCommentorName() + "\n");
		stringBuilder.append("Commentor Email Address: " + addedComment.getCommentorEmailAddress() + "\n");
		stringBuilder.append("Comment Text:\t\t " + addedComment.getCommentText() + "\n\n");
		
		System.out.println(stringBuilder.toString());
	}
}
		


PHP

Prerequisites

  1. Download the PHP API client library.
  2. Create a new php script file.
  3. Add EHiveApi.php from the PHP API client library to your include path.
  4. Locate the oauth.tok file in the transport/oauth directory of the PHP API client library and ensure that it has both read and write permission enabled.

Start Coding

  1. Instantiate an EHiveApi object. The EHiveApi class contains all of the functions available to you in the API.
  2. Configure your EHiveApi object with valid authentication credentials. There are a number of ways to instantiate the EHiveApi object but for this example you will simply pass all of the parameter you need into the EHiveApi object's constructor:
    private static $clientId = "...5935";
    private static $clientSecret = "...4c4b";
    private static $trackingId = "...eaca";
    
    ...
    $eHiveApi = new EHiveApi(AddObjectRecordCommentDemo::$clientId, 
    						 				AddObjectRecordCommentDemo::$clientSecret, 
    						 				AddObjectRecordCommentDemo::$trackingId);
    			
  3. Invoke the addObjectRecordComment() method and assign the return value to a variable as follows:
    $addedComment = $eHiveApi->addObjectRecordComment(2509, $comment);
  4. Access the information on the comment object.
    echo $addedComment->commentText;

View the full example below.


require_once '../../lib/ehive_api_client-php-1.0.0/EHiveApi.php';
require_once '../../lib/ehive_api_client-php-1.0.0/domain/comments/Comment.php';

class AddObjectRecordCommentDemo {
	
	private static $clientId = "...5935";
	private static $clientSecret = "...4c4b";
	private static $trackingId = "...eaca";
	
	
	private static $objectRecordId = 2509;
	
	public function printAccountInfo() {
		
		// Instantiate the EHiveApi object
		$eHiveApi = new EHiveApi(AddObjectRecordCommentDemo::$clientId, 
						 					    AddObjectRecordCommentDemo::$clientSecret, 
						 					    AddObjectRecordCommentDemo::$trackingId);
		
		// Create a new Comment object
		$comment = new Comment();
		$comment->commentorEmailAddress = "john.doe@ehivedevelopers.com";
		$comment->commentorName = "John Doe";
		$comment->commentText = "This is a test comment posted from developers.ehive.com."
								. " You can check the timestamp on the response below against the timestamp on the eHive object record to verify that your comment was added.";
		
		// Invoke an API method
		$addedComment = $eHiveApi->addObjectRecordComment(AddObjectRecordCommentDemo::$objectRecordId, AddObjectRecordCommentDemo::$comment);
		
		// Print some output using the returned comment that has been added object
		if ($addedComment->commentorEmailAddress) {
			echo "Commentor Email Address:\n\t";
			echo $addedComment->commentorEmailAddress;
		}
		
		if ($addedComment->commentorName) {
			echo "Commentor name:\n\t";
			echo $addedComment->commentorName;
		}
		
		if ($addedComment->commentText) {
			echo "Comment text:\n\t";
			echo $addedComment->commentText;
		}
		echo "\n\n";
	}
}

$addObjectRecordCommentDemo = new GetAccountInCommunityDemo();

$addObjectRecordCommentDemo->printAccountInfo();