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.




Accessing Gemini API via PHP

api

I am new to the Gemini API and I have been looking through some of the Java examples and trying to get them working in PHP.

Each time I try running my PHP script I get an error back from Gemini and as I am not the administrator of Gemini system I cannot see the error logs.

Here's what I have come up with in PHP (uses the ZendHttpClient) for adding a comment to an existing issue:
// Preforming a POST request with ZendHttpClient


$client = new ZendHttpClient();
$client->setUri($geminiUrl.'/api/issues.ashx/issues/'.$issueId.'/comments');


$client->setConfig(array(
    'maxredirects' => 0,
    'timeout'      => 30));
$client->setMethod(ZendHttpClient::POST);



// Set headers
$client->setHeaders('Content-type', 'text/xml');
$client->setHeaders('Accept', 'application/json');


$client->setHeaders('gemini-username-token', $geminiUsername);
$client->setHeaders('gemini-password-token', md5($geminiPassword));



// Set XML and POST
$xml = '<?xml version="1.0" encoding="utf-8"?>
<IssueCommentEN>
    <VisibilityMemberType>2</VisibilityMemberType>


    <CommentId>0</CommentId>
    <IssueId>'.$issueId.'</IssueId>
    <ProjectId>1</ProjectId>
    <Comment>Test comment from PHP to Gemini API</Comment>


    <UserName>'.$geminiUsername.'</UserName>
    <IsClosing>false</IsClosing>
    <Visibility>1</Visibility>
    <HasRestrictedVisibility>false</HasRestrictedVisibility>


</IssueCommentEN>';

$client->setParameterPost($xml);
$response = $client->request();



Here's the vardump() from $client and $response:
object(Zend
HttpClient)[2]
protected 'config' =>
array
'maxredirects' => int 0

'strictredirects' => boolean false
'useragent' => string 'Zend
HttpClient' (length=16)

'timeout' => int 30
'adapter' => string 'Zend
HttpClientAdapterSocket' (length=31)

'httpversion' => string '1.1' (length=3)
'keepalive' => boolean false

'storeresponse' => boolean true
'strict' => boolean true
protected 'adapter' =>
object(Zend
HttpClientAdapterSocket)[4]
protected 'socket' => null

protected 'connected
to' =>
array
0 => null
1 => null

protected 'config' =>
array
'persistent' => boolean false
'ssltransport' => string 'ssl' (length=3)

'sslcert' => null
'sslpassphrase' => null
'maxredirects' => int 0

'strictredirects' => boolean false
'useragent' => string 'ZendHttpClient' (length=16)

'timeout' => int 30
'httpversion' => string '1.1' (length=3)

'keepalive' => boolean false
'storeresponse' => boolean true
'strict' => boolean true

protected 'method' => string 'POST' (length=4)
protected 'context' => resource(20, stream-context)
protected 'uri' =>
object(Zend
UriHttp)[3]
protected '
username' => string '' (length=0)

protected 'password' => string '' (length=0)
protected '
host' => string 'urlremoved.com' (length=16)

protected 'port' => int 80
protected '
path' => string '/gemini/Error.aspx' (length=18)

protected 'query' => string 'aspxerrorpath=/gemini/api/issues.ashx/issues/13586/comments' (length=59)
protected '
fragment' => string '' (length=0)

protected 'regex' =>
array
'escaped' => string '%[[:xdigit:]]{2}' (length=16)

'unreserved' => string '[A-Za-z0-9-
.!~'()[]]' (length=24)
'segment' => string '(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~
'()[]:@&=+$,;])' (length=54)

'path' => string '(?:\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~
'()[]:@&=+$,;]))?)+' (length=66)
'uric' => string '(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~
'()[];\/?:@&=+$,])' (length=56)

protected 'scheme' => string 'http' (length=4)
protected 'headers' =>
array

'accept' =>
array
0 => string 'Accept' (length=6)
1 => string 'application/json' (length=16)

'gemini-username-token' =>
array
0 => string 'gemini-username-token' (length=21)
1 => string 'my
username' (length=19)

'gemini-password-token' =>
array
0 => string 'gemini-password-token' (length=21)
1 => string 'mypasswordinmd5format' (length=32)

protected 'method' => string 'GET' (length=3)
protected 'paramsGet' =>
array

empty
protected 'paramsPost' =>
array
empty
protected 'enctype' => string 'application/x-www-form-urlencoded' (length=33)

protected 'rawpostdata' => null
protected 'auth' => null
protected 'files' =>
array

empty
protected 'cookiejar' => null
protected 'lastrequest' => string 'POST /gemini/api/issues.ashx/issues/13586/comments HTTP/1.1


Host: urlremoved.com

Connection: close

Accept-encoding: gzip, deflate

User-Agent: Zend
HttpClient

Content-type: text/xml

Accept: application/json

gemini-username-token: my
username

gemini-password-token: mypasswordinmd5format

Content-Length: 0



' (length=338)
protected 'lastresponse' =>
object(Zend
HttpResponse)[6]
protected 'version' => string '1.1' (length=3)

protected 'code' => int 302
protected 'message' => string 'Found' (length=5)

protected 'headers' =>
array
'Connection' => string 'close' (length=5)

'Date' => string 'Sat, 28 Nov 2009 13:32:57 GMT' (length=29)
'Server' => string 'Microsoft-IIS/6.0' (length=17)

'Microsoftofficewebserver' => string '5.0
Pub' (length=7)
'X-powered-by' => string 'ASP.NET' (length=7)

'X-aspnet-version' => string '2.0.50727' (length=9)
'Location' => string '/gemini/Error.aspx?aspxerrorpath=/gemini/api/issues.ashx/issues/13586/comments' (length=78)

'Cache-control' => string 'private' (length=7)
'Content-type' => string 'text/html; charset=utf-8' (length=24)

'Content-length' => string '215' (length=3)
protected 'body' => string '<html><head><title>Object moved</title></head><body>


<h2>Object moved to <a href="%2fgemini%2fError.aspx%3faspxerrorpath%3d%2fgemini%2fapi%2fissues.ashx%2fissues%2f13586%2fcomments">here</a>.</h2>

</body></html>

' (length=215)
protected 'redirectCounter' => int 1

object(ZendHttpResponse)[6]
protected 'version' => string '1.1' (length=3)

protected 'code' => int 302
protected 'message' => string 'Found' (length=5)

protected 'headers' =>
array
'Connection' => string 'close' (length=5)

'Date' => string 'Sat, 28 Nov 2009 13:32:57 GMT' (length=29)
'Server' => string 'Microsoft-IIS/6.0' (length=17)

'Microsoftofficewebserver' => string '5.0_Pub' (length=7)
'X-powered-by' => string 'ASP.NET' (length=7)

'X-aspnet-version' => string '2.0.50727' (length=9)
'Location' => string '/gemini/Error.aspx?aspxerrorpath=/gemini/api/issues.ashx/issues/13586/comments' (length=78)

'Cache-control' => string 'private' (length=7)
'Content-type' => string 'text/html; charset=utf-8' (length=24)

'Content-length' => string '215' (length=3)
protected 'body' => string '<html><head><title>Object moved</title></head><body>


<h2>Object moved to <a href="%2fgemini%2fError.aspx%3faspxerrorpath%3d%2fgemini%2fapi%2fissues.ashx%2fissues%2f13586%2fcomments">here</a>.</h2>

</body></html>

' (length=215)

Any ideas where I am going wrong?

Thanks for any help!

sebf
· 1
sebf
Replies (3)
helpful
0
not helpful

Please make sure that the issue id belongs to the project id (1) in the comment XML.


Mark Wing
· 9108
Mark Wing
helpful
0
not helpful

I am pretty certain that the project id is 1 and the issue id is 13586 (from the link when I created a test issue the URL is: http://domain.com/gemini/issue/ViewIssue.aspx?id=13586&PROJID=1).

One thing I did notice that I wasn't sending the XML as:

$client->setParameterPost($xml);
Wasn't actually sending anything, however I have replaced it with:
$client->setRawData(urlencode($xml));
Which gives me the following output:
object(ZendHttpClient)[2]
protected 'config' =>
array
'maxredirects' => int 0

'strictredirects' => boolean false
'useragent' => string 'ZendHttpClient' (length=16)

'timeout' => int 30
'adapter' => string 'ZendHttpClientAdapterSocket' (length=31)

'httpversion' => string '1.1' (length=3)
'keepalive' => boolean false

'storeresponse' => boolean true
'strict' => boolean true
protected 'adapter' =>
object(ZendHttpClientAdapterSocket)[4]
protected 'socket' => null

protected 'connectedto' =>
array
0 => null
1 => null

protected 'config' =>
array
'persistent' => boolean false
'ssltransport' => string 'ssl' (length=3)

'sslcert' => null
'sslpassphrase' => null
'maxredirects' => int 0

'strictredirects' => boolean false
'useragent' => string 'Zend
HttpClient' (length=16)

'timeout' => int 30
'httpversion' => string '1.1' (length=3)

'keepalive' => boolean false
'storeresponse' => boolean true
'strict' => boolean true

protected 'method' => string 'POST' (length=4)
protected '
context' => resource(2, stream-context)
protected 'uri' =>
object(ZendUriHttp)[3]
protected 'username' => string '' (length=0)

protected '
password' => string '' (length=0)
protected 'host' => string 'domain.com' (length=16)

protected '
port' => int 80
protected 'path' => string '/gemini/Error.aspx' (length=18)

protected '
query' => string 'aspxerrorpath=/gemini/api/issues.ashx/issues/13586/comments' (length=59)
protected 'fragment' => string '' (length=0)

protected '
regex' =>
array
'escaped' => string '%[[:xdigit:]]{2}' (length=16)

'unreserved' => string '[A-Za-z0-9-.!~*'()[]]' (length=24)
'segment' => string '(?:%[[:xdigit:]]{2}|[A-Za-z0-9-
.!~'()[]:@&=+$,;])' (length=54)

'path' => string '(?:\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-.!~*'()[]:@&=+$,;])*)?)+' (length=66)
'uric' => string '(?:%[[:xdigit:]]{2}|[A-Za-z0-9-
.!~*'()[];\/?:@&=+$,])' (length=56)

protected 'scheme' => string 'http' (length=4)
protected 'headers' =>
array

'accept' =>
array
0 => string 'Accept' (length=6)
1 => string 'application/json' (length=16)

'gemini-username-token' =>
array
0 => string 'gemini-username-token' (length=21)
1 => string 'my
username' (length=19)

'gemini-password-token' =>
array
0 => string 'gemini-password-token' (length=21)
1 => string 'mypasswordinmd5format' (length=32)

protected 'method' => string 'GET' (length=3)
protected 'paramsGet' =>
array

empty
protected 'paramsPost' =>
array
empty
protected 'enctype' => null

protected 'rawpostdata' => null
protected 'auth' => null
protected 'files' =>
array

empty
protected 'cookiejar' => null
protected 'lastrequest' => string 'POST /gemini/api/issues.ashx/issues/13586/comments HTTP/1.1


Host: domain.com

Connection: close

Accept-encoding: gzip, deflate

User-Agent: Zend
HttpClient

Content-type: text/xml

Accept: application/json

gemini-username-token: my
username

gemini-password-token: mypasswordinmd5format

Content-Length: 582



%3C%3Fxml+version%3D%221.0%22+encoding%3D%22utf-8%22%3F%3E%0A%3CIssueCommentEN%3E%0A++++%3CVisibilityMemberType%3E2%3C%2FVisibilityMemberType%3E%0A++++%3CCommentId%3E0%3C%2FCommentId%3E%0A++++%3CIssueId%3E13586%3C%2FIssueId%3E%0A++++%3CProjectId%3E1%3C%2FProjectId%3E%0A++++%3CComment%3ETest+comment+from+PHP+to+Gemini+API%3C%2FComment%3E%0A++++%3CUserName%3Emyusername%3C%2FUserName%3E%0A++++%3CIsClosing%3Efalse%3C%2FIsClosing%3E%0A++++%3CVisibility%3E1%3C%2FVisibility%3E%0A++++%3CHasRestrictedVisibility%3Efalse%3C%2FHasRestrictedVisibility%3E%0A%3C%2FIssueCommentEN%3E' (length=922)
protected 'last
response' =>
object(ZendHttpResponse)[6]
protected 'version' => string '1.1' (length=3)

protected 'code' => int 302
protected 'message' => string 'Found' (length=5)

protected 'headers' =>
array
'Connection' => string 'close' (length=5)

'Date' => string 'Mon, 30 Nov 2009 13:03:33 GMT' (length=29)
'Server' => string 'Microsoft-IIS/6.0' (length=17)

'Microsoftofficewebserver' => string '5.0Pub' (length=7)
'X-powered-by' => string 'ASP.NET' (length=7)

'X-aspnet-version' => string '2.0.50727' (length=9)
'Location' => string '/gemini/Error.aspx?aspxerrorpath=/gemini/api/issues.ashx/issues/13586/comments' (length=78)

'Cache-control' => string 'private' (length=7)
'Content-type' => string 'text/html; charset=utf-8' (length=24)

'Content-length' => string '215' (length=3)
protected 'body' => string '<html><head><title>Object moved</title></head><body>


<h2>Object moved to <a href="%2fgemini%2fError.aspx%3faspxerrorpath%3d%2fgemini%2fapi%2fissues.ashx%2fissues%2f13586%2fcomments">here</a>.</h2>

</body></html>

' (length=215)
protected 'redirectCounter' => int 1

object(Zend
HttpResponse)[6]
protected 'version' => string '1.1' (length=3)

protected 'code' => int 302
protected 'message' => string 'Found' (length=5)

protected 'headers' =>
array
'Connection' => string 'close' (length=5)

'Date' => string 'Mon, 30 Nov 2009 13:03:33 GMT' (length=29)
'Server' => string 'Microsoft-IIS/6.0' (length=17)

'Microsoftofficewebserver' => string '5.0
Pub' (length=7)
'X-powered-by' => string 'ASP.NET' (length=7)

'X-aspnet-version' => string '2.0.50727' (length=9)
'Location' => string '/gemini/Error.aspx?aspxerrorpath=/gemini/api/issues.ashx/issues/13586/comments' (length=78)

'Cache-control' => string 'private' (length=7)
'Content-type' => string 'text/html; charset=utf-8' (length=24)

'Content-length' => string '215' (length=3)
protected 'body' => string '<html><head><title>Object moved</title></head><body>


<h2>Object moved to <a href="%2fgemini%2fError.aspx%3faspxerrorpath%3d%2fgemini%2fapi%2fissues.ashx%2fissues%2f13586%2fcomments">here</a>.</h2>

</body></html>

' (length=215)

However as you can see from the var_dump() I am still getting an error back from Gemini, but I am not sure what's causing it?

Checking the API documents it doesn't tell you how to form/format a request to the Gemini API. It might be helpful to provide a few examples of what URLs, headers and what XML elements the API expects for each of the API interfaces (e.g. commenting, creating new issues, adding source control etc)

Any ideas on why my Gemini API request is returning an error?

Thanks for any help.


sebf
· 1
sebf
helpful
0
not helpful

Please ask your administrator to check the error log, this might help.
Is it possible to send your code to support at countersoft dot com?


Mark Wing
· 9108
Mark Wing