It's all about the answers!

Ask a question

Accessing ClearQuest programatically


Ana Ana (31111) | asked Nov 12 '10, 11:04 a.m.
Hi,

I need to access ClearQuest programatically using C#. I just found ClearQuest OSLC REST API. Client is planning to use ClearQuest web 7.1.1. I read that it comes with OSLC REST API out the box. Can someone please provide me some examples on how I can access the CQ through C# or Java using this API. I much appreciate any info.

Thank you,
Ana

24 answers



permanent link
Christophe Cornu (47123) | answered Nov 15 '10, 11:14 a.m.
Hi Ana:

This article is an excellent introduction on how to perform http oslc requests.
http://jazz.net/library/article/352
Caveat: the examples use RTC. The version of CQ you develop against may support different version(s) of the OSLC apis. OSLC is HTTP based, so you can even try it out with a simple web browser, curl or e.g. Firefox Poster plugin.

I'm forwarding your question to someone on the CQ team.

Christophe Cornu
RTC / Source Control Committer

permanent link
Samuel Padgett (2172) | answered Nov 15 '10, 11:22 a.m.
JAZZ DEVELOPER
Hi, Ana. The REST API sounds like a good fit for you. The documentation is here:

https://jazz.net/wiki/bin/view/Main/RcmRestCmApi

You might also find the article helpful. It uses RTC as an example, but the code works with CQ as well.

http://www.ibm.com/developerworks/rational/library/10/openservicesforlifecyclecollaborationchangemanagement/index.html?ca=drs-

Best Regards,
Samuel Padgett
CQ Bridge & OSLC Lead

permanent link
Ana Ana (31111) | answered Nov 30 '10, 1:11 p.m.
Samuel and Chris,

Thank you for the links. I went through them and I was able to create new defects(with out any attachments) programatically but I am not sure how to handle attachments. How can I add attachments programatically too. Can you please point me how I can do that. I appreciate any help.

Thank you,
Ana.

Hi, Ana. The REST API sounds like a good fit for you. The documentation is here:

https://jazz.net/wiki/bin/view/Main/RcmRestCmApi

You might also find the article helpful. It uses RTC as an example, but the code works with CQ as well.

http://www.ibm.com/developerworks/rational/library/10/openservicesforlifecyclecollaborationchangemanagement/index.html?ca=drs-

Best Regards,
Samuel Padgett
CQ Bridge & OSLC Lead

permanent link
Samuel Padgett (2172) | answered Dec 02 '10, 11:02 a.m.
JAZZ DEVELOPER
Hi, Ana. Thank you for pointing out that information about attachments is missing from our wiki. We've now added a few words describing how things work.

https://jazz.net/wiki/bin/view/Main/RcmRestCmApi#Attachments

Please let me know if you need help with this, and I should be able to point you in the right direction :)

Thanks,
Samuel Padgett
CQ Bridge & OSLC Lead

permanent link
Kevin Johnson (26) | answered Dec 06 '10, 7:33 p.m.
Hi, I am trying to use Perl LWP to upload an attachment and it is not working. I am not sure what I need for Content - any suggestions? I am now guessing on "upfilename" etc...

my $response = $userAgent->request(POST $modifyString,
Content_Type => 'form-data',
Content =>
);


Thanks...


Hi, Ana. Thank you for pointing out that information about attachments is missing from our wiki. We've now added a few words describing how things work.

https://jazz.net/wiki/bin/view/Main/RcmRestCmApi#Attachments

Please let me know if you need help with this, and I should be able to point you in the right direction :)

Thanks,
Samuel Padgett
CQ Bridge & OSLC Lead

permanent link
Ana Ana (31111) | answered Dec 08 '10, 11:56 a.m.
Hi Samuel,

Can you please post a sample POST request contents for posting attachments? Looks like skybanter is also asking for the same information. If the documentation can include the sample, it would be great.

Also, it would be nice to identify in the document what 'record-identifier' is instead of novice users like me figuring it out by themself.

Also, the documentation says that the GET on URL "/record/<record-identifier>/field/<attachment-field-name>/attachment' will give the contents of the attachment, it doesn't. There is nothing in the above url that identifies the attachment itself. The above URL just gives list of attachments associated with a record. From there you can get URL for contents of actual attachment, which looks like

'/record/<record-identifier>/field/<attachment-field-name>/attachment/<attachment-identifier>'


Thanks,
Ana


Hi, Ana. Thank you for pointing out that information about attachments is missing from our wiki. We've now added a few words describing how things work.

https://jazz.net/wiki/bin/view/Main/RcmRestCmApi#Attachments

Please let me know if you need help with this, and I should be able to point you in the right direction :)

Thanks,
Samuel Padgett
CQ Bridge & OSLC Lead

permanent link
Ana Ana (31111) | answered Dec 09 '10, 11:40 a.m.
Skybanter,

Can you please post a sample content and code if you have figured it out.

Thanks,
Ana

Hi, I am trying to use Perl LWP to upload an attachment and it is not working. I am not sure what I need for Content - any suggestions? I am now guessing on "upfilename" etc...

my $response = $userAgent->request(POST $modifyString,
Content_Type => 'form-data',
Content =>
);


Thanks...


Hi, Ana. Thank you for pointing out that information about attachments is missing from our wiki. We've now added a few words describing how things work.

https://jazz.net/wiki/bin/view/Main/RcmRestCmApi#Attachments

Please let me know if you need help with this, and I should be able to point you in the right direction :)

Thanks,
Samuel Padgett
CQ Bridge & OSLC Lead

permanent link
Yuhong Yin (25123) | answered Dec 14 '10, 12:19 p.m.
JAZZ DEVELOPER
Here is a perl script example on posting an attachment. I have validated that it works :==)

I am using a very simple script to demonstrate the multipart MIME request body, you probably can use MIME::Entity or MIME::Lite to make it more usable.

Let me know if you have further questions,

-----------------------------------------------------------------
#
# Code connecting to CQ is not included
#

my $header = HTTP::Headers->new;
$header->header(Authorization => "Basic ".encode_base64("$CQ_USERNAME:$CQ_USERNAME", ""));
$header->header('Content-Type' => "multipart/form-data; boundary=UdCwYxcWhVYyLPJCRxQTEowAxgcepp");

# hardcoded attachment resource context
$link="http://qwin115.ratl.swg.usma.ibm.com:12080/cqweb/oslc/repo/7.0.0/db/SAMPL/record/16777224-33554479/field/Attachments/attachment";

# form the POST request
my $request = HTTP::Request->new( POST => "$link", $header);

# form the MIME request body
my $content = "\r\n";
$content = $content . "Content-Disposition: form-data; name=\"description\"";
$content = $content . "\r\n";
$content = $content . "Content-Type: text/plain; charset=US-ASCII";
$content = $content . "\r\n";
$content = $content . "Content-Transfer-Encoding: 8bit";
$content = $content . "\r\n";
$content = $content . "\r\n";
$content = $content . "Test Description";
$content = $content . "\r\n";
$content = $content . "--UdCwYxcWhVYyLPJCRxQTEowAxgcepp";
$content = $content . "\r\n";
$content = $content . "Content-Disposition: form-data; name=\"file\"; filename=\"test4.txt\"";
$content = $content . "\r\n";
$content = $content . "Content-Type: application/octet-stream; charset=ISO-8859-1";
$content = $content . "\r\n";
$content = $content . "Content-Transfer-Encoding: binary";
$content = $content . "\r\n";
$content = $content . "\r\n";
$content = $content . "this is a test attachment file.";
$content = $content . "\r\n";
$content = $content . "--UdCwYxcWhVYyLPJCRxQTEowAxgcepp--";
$content = $content . "\r\n";

$request->content($content);

$g_cookie_jar->add_cookie_header($request);

my $response = LWP::UserAgent->new->request($request);

if ($response->status_line eq '201 Created')
{
print "\n Attachment uploaded successfully!\n";
}

Thanks

- Yuhong

Yuhong Yin

CC/CQ CM Server & Integration

permanent link
Yuhong Yin (25123) | answered Dec 14 '10, 12:23 p.m.
JAZZ DEVELOPER
The HTTP POST request over the wire looks like this - you can use it to validate your POST request body



--UdCwYxcWhVYyLPJCRxQTEowAxgcepp

Content-Disposition: form-data; name="description"

Content-Type: text/plain; charset=US-ASCII

Content-Transfer-Encoding: 8bit



Test Description

--UdCwYxcWhVYyLPJCRxQTEowAxgcepp

Content-Disposition: form-data; name="file"; filename="test.txt"

Content-Type: application/octet-stream; charset=ISO-8859-1

Content-Transfer-Encoding: binary



this is a test attachment file.

--UdCwYxcWhVYyLPJCRxQTEowAxgcepp--

permanent link
Kevin Johnson (26) | answered Dec 15 '10, 12:42 a.m.
Hi Yuhong,

Thanks so much for your help. But it is not (yet) working. I had to slightly modify and add to your code. But this is my complete perl script which I run with cqperl. And I have 7.1.2 installed.

use LWP::UserAgent;

use HTTP::Request::Common;
use HTTP::Cookies;
use MIME::Base64;

my $CQWEB_LOGIN = 'admin';
my $CQWEB_PASSWD = 'admin';
my $CQWEB_HOST = 'localhost';
my $CQWEB_PORT = '12080';
my $CQWEB_HOST_PORT = "${CQWEB_HOST}:${CQWEB_PORT}";

my $CQWEB_REPO = '7.0.0';

my $CQWEB_REALM = "${CQWEB_REPO}";

my $CQWEB_DB = 'SAMPL';

my $APP_CONTEXT = 'cqweb/oslc';

my $ENTITY_DEF = '16777433';

#my $RECORD_ID = '33554479';
my $RECORD_ID = '33554463';

my $header = HTTP::Headers->new;
$header->header(Authorization => "Basic ".encode_base64("$CQWEB_LOGIN:$CQWEB_PASSWD", ""));
$header->header('Content-Type' => "multipart/form-data; boundary=UdCwYxcWhVYyLPJCRxQTEowAxgcepp");

# hardcoded attachment resource context
# $link="http://qwin115.ratl.swg.usma.ibm.com:12080/cqweb/oslc/repo/7.0.0/db/SAMPL/record/16777224-33554479/field/Attachments/attachment";
# Notice I have -33554463 instead... and I double-checked this...
my $link="http://${CQWEB_HOST}:${CQWEB_PORT}/${APP_CONTEXT}/repo/${CQWEB_REPO}/db/${CQWEB_DB}/record/${ENTITY_DEF}-${RECORD_ID}/field/Attachements/attachment";

# form the POST request
my $request = HTTP::Request->new( POST => "$link", $header);

# form the MIME request body
my $content = "\r\n";
$content = $content . "Content-Disposition: form-data; name=\"description\"";
$content = $content . "\r\n";
$content = $content . "Content-Type: text/plain; charset=US-ASCII";
$content = $content . "\r\n";
$content = $content . "Content-Transfer-Encoding: 8bit";
$content = $content . "\r\n";
$content = $content . "\r\n";
$content = $content . "Test Description";
$content = $content . "\r\n";
$content = $content . "--UdCwYxcWhVYyLPJCRxQTEowAxgcepp";
$content = $content . "\r\n";
$content = $content . "Content-Disposition: form-data; name=\"file\"; filename=\"test4.txt\"";
$content = $content . "\r\n";
$content = $content . "Content-Type: application/octet-stream; charset=ISO-8859-1";
$content = $content . "\r\n";
$content = $content . "Content-Transfer-Encoding: binary";
$content = $content . "\r\n";
$content = $content . "\r\n";
$content = $content . "this is a test attachment file.";
$content = $content . "\r\n";
$content = $content . "--UdCwYxcWhVYyLPJCRxQTEowAxgcepp--";
$content = $content . "\r\n";

$request->content($content);

# I had to add this
my $g_cookie_jar = HTTP::Cookies->new(autosave => 1);
$g_cookie_jar->add_cookie_header($request);

my $userAgent = LWP::UserAgent->new();

#my $response = LWP::UserAgent->new->request($request);
my $response = $userAgent->request($request);

if ($response->status_line eq '201 Created')
{
print "\n Attachment uploaded successfully!\n";
}
else { # added this to see my error
print "Response: " . $response->error_as_HTML . "\n";

$response2 = $response->as_string;

print "Response: " . $response2 . "\n";
}


And here is the mystery error:

C:\Temp>cqperl -w att2.pl

Response: <HTML>
<HEAD><TITLE>An Error Occurred</TITLE></HEAD>
<BODY>
<H1>An Error Occurred</H1>
400 Bad Request
</BODY>
</HTML>

Response: HTTP/1.1 400 Bad Request
Cache-Control: no-cache="set-cookie, set-cookie2"
Connection: Close
Date: Wed, 15 Dec 2010 05:36:22 GMT
Server: WebSphere Application Server/6.1
Content-Language: en-US
Content-Type: application/xml; charset=UTF-8
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Client-Date: Wed, 15 Dec 2010 05:36:22 GMT
Client-Peer: 127.0.0.1:12080
Client-Response-Num: 1
Client-Transfer-Encoding: chunked
Set-Cookie: JSESSIONID=00002ox8gAwo4k4X7wP8pWe__p4:-1; Path=/

<xml>
<Error>
<message>CRVSV0119E Property not found.</message>
<statusCode>400</statusCode>
<cq>conflict</cq>
<Error>
<message>CRVSV0119E Property not found.</message>
<statusCode>400</statusCode>
<cq>property-not-supported-by-server</cq>
</Error>
</Error>


Any chance you can help me out on this error? "property-not-supported-by-server" but not further clues.

Thanks!

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.