Gemini Community Support Site

This Gemini community support site can be used to find solutions to product issues. You can log in using Open Id, Google Profile and even Facebook. Feel free to ask a question or browse FAQs and documentation. Product tour videos are also available along with how-to videos demonstrating key Gemini capabilities.




Creating comments with REST

api

First of all, thanks for posting the link this morning to the new API docs. Is it posted somewhere on the main site?

I've been playing around with the new service. The docs have some first-version issues, but they're still a big help. My first real stumble is in creating comments. In particular, I'm not sure what the POST should look like. Can I please have an example POST request for a simple comment creation? I'm particularly interesting in the Content-Type: value and the body itself. I've tried a bunch of different things but I just keeping getting this back from the server (square brackets substituted for angle brackets):

[?xml version="1.0" encoding="utf-8"?] [RestError xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/X MLSchema"] [Message]Invalid URI - Content type must be an XML[/Message] [Type]Un supportedMediaType[/Type] [/RestError]

Thanks!

Regard, Bob

bobw
· 1
bobw
Replies (6)
helpful
0
not helpful

The content type is: content-type: text/xml

The request should be a POST and the body is the entity (best to get a comment and inspect the XML using fiddler):

 

<IssueCommentEN>
 <TimeStamp>AAAAAAAAC4o=</TimeStamp>
 <DateCreated>2009-01-17T15:21:15</DateCreated>
 <State>NoChange</State>
 <VisibilityMemberType>GlobalGroup</VisibilityMemberType>
 <CommentID>27</CommentID>
 <UserID>1</UserID>
 <IssueID>16</IssueID>
 <ProjectID>2</ProjectID>
 <Comment>fiddler</Comment>
 <UserName>Manager Person</UserName>
 <IsClosing>false</IsClosing>
 <Visibility>1</Visibility>
</IssueCommentEN>


Saar Cohen
· 5000
Saar Cohen
helpful
0
not helpful

Okay, I got comment creation to work. I wasn't setting the content-type header to the right value, and also, it seems you need to pass in the issue ID in the body for it to work (I was just passing the comment text), which seems like a bug given that the issue ID is in request URL. At least in my case, the rest of the fields are not needed. Anyway, thanks for the help there.

Moving on, I've implemented an SVN hook that uses the REST service to add commit details as comments on issues. What happens is that the commit message has the author, which my hook maps to a Gemini username and API key, and then the hook creates the comment and credits it to that user. Right now, I have it set it up for three people. For two, it works great. For the third, however, I'm getting a strange error back from Gemini. Here's the error:

SimpleXMLElement::_setstate(array( 'InnerMessage' => 'User Joe Cool does not have permission for: create comment.', 'InnerSource' => 'CounterSoft.Gemini.Presenter', 'InnerStack' => ' at CounterSoft.Gemini.Presenter.Base.BasePresenter.HandlePermissionException(String operation) at CounterSoft.Gemini.Presenter.IssuePresenter.CreateIssueComment(IssueEN issue, IssueCommentEN comment) at CounterSoft.Gemini.Web.Api.IssuesRestHandler.CommentCreate(RequestDetails rd)', 'InnerType' => 'CounterSoft.Gemini.Commons.Exception.GeminiPermissionException', 'Message' => 'Exception has been thrown by the target of an invocation.', 'Source' => 'mscorlib', 'Stack' => ' at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at CounterSoft.Gemini.Web.Api.x984df3e201a5cc4a.xd8c6760a50aeba18(RequestDetails x4f7dd955f6bfaf92, MethodInfo x2a154456227d18a2)', 'Type' => 'System.Reflection.TargetInvocationException', )), 'Message' => 'Exception has been thrown by the target of an invocation.', 'Type' => 'InternalServerError', ))

Of particular note from my perspective is that second line, which claims the user doesn't have the permissions required to create a comment. Two things:

1) Gemini is returning "Joe Cool" (the full name) in the error, but the only information I'm passing in is the username ("jcool"), so clearly, Gemini is recognizing the username I'm passing and mapping it to a user. Further, the user it's selecting is indeed the correct user.

2) The user does have permission to add comments to the indicated task, and can do so from the web site. In fact, the user has permission to add comments to any task.

Any idea what's going on here?


bobw
· 1
bobw
helpful
0
not helpful

Please make sure that the project ID is populated in the comment entity (XML POST).

Also, we have SVN integration done already (.NET code): http://www.countersoft.com/downloads/v351/CounterSoftGeminiSourceControlv35_1.zip


Mark Wing
· 9108
Mark Wing
helpful
0
not helpful

[quote user="MarkWing"]

Please make sure that the project ID is populated in the comment entity (XML POST).

[/quote]

Hmm, that complicates things a bit. I'm only looking for issue IDs in the SVN comments, not project IDs. Thus, I'd need to look up the project ID that contains the issue. I don't have the API docs in front of me--and without the required fields being indicated, I'm not sure they'd help--but I don't recall seeing an easy way to do that. What's the easiest and most efficient way to do it?

Now that I'm thinking about this, I believe I recently ran into this problem in the UI, too. I had created a browser keyword shortcut to go directly to an issue, but it only worked about half the time, with a nonsensical insufficient rights message being spit out the other half. Turns out, you have to specify a project ID URL, though as I learned from Gemini's own issue shortcuts (the autolinkification feature that looks for references of the "GEM:n" sort), you can do it with a simple pid=null and it'll work. Is there a similar magic string I can specify in the API to get around having to lookup and then pass the actual, correct value?

Incidentally, given that Gemini's issue IDs are globally unique, why the requirement to include a project ID in all these cases? Seems odd to me.

[quote]

Also, we have SVN integration done already (.NET code): http://www.countersoft.com/downloads/v351/CounterSoftGeminiSourceControlv35_1.zip

[/quote]

Thanks, but the projects I work on, and the SVN repos containing them, are all *nix-based. Thus, a .NET solution is of no help in my case. (This also happens to be the reason I'm using the REST service versus the WSE(?) service.)


bobw
· 1
bobw
helpful
0
not helpful

This restriction is for security reasons.

You can get the project id by getting the issue:

../issues.ashx/issues/X where X is the issue id. This will return the issue entity, which has the project id.


Saar Cohen
· 5000
Saar Cohen
helpful
0
not helpful

Works great, thanks!


bobw
· 1
bobw