It's all about the answers!

Ask a question

Create defect with OSLC


Ivaylo Kubratov (152) | asked Jul 16 '21, 12:03 p.m.
edited Jul 19 '21, 9:09 a.m.

 I want to create defect using OSLC.

Using "OSLC-Core-Version=2.0" and "Accept=Application/RDF+XML"
From services I'm using "oslc:creation" link (from the image) to POST defect:

I have allowed value for each field.

Question1:
How can I find mandatory fields for each Project area?

Question2:
What is xml format for the body (context) of POST request?
I mean this format:

<oslc_cm:ChangeRequest
  rdf:about="">
  <dc:title>---title---</dc:title>
  <dc:type rdf:resource="---type---"/>
  <oslc_cm:severity rdf:resource="---severity---"/>
  <rtc_cm:com.howfound rdf:resource="---howfound---"/>
  <rtc_cm:foundIn rdf:resource="---foundIn---"/>
  <rtc_cm:com.Occurrence rdf:resource="---Occurrence---"/>
  <rtc_cm:filedAgainst rdf:resource="---filedAgainst---"/>
  <rtc_cm:plannedFor rdf:resource="---plannedFor---"/>
  <rtc_cm:com.workitem.defectc.defect.description>---description---</rtc_cm:com.workitem.defectc.defect.description>
</oslc_cm:ChangeRequest>


Accepted answer


permanent link
Ralph Schoon (63.1k33646) | answered Jul 21 '21, 4:56 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I am not able to debug your code for you, there is not enough to work with. No information about the actual Request and URI, the request data is incomplete and likely uninteresting. The request headers URI and the response headers/body would be of interest for debugging. Anyway this is almost impossible in the forum. 


Note that a valid creation factory for a defect for me looks as follows: https://elm.example.com:9443/ccm/oslc/contexts/_8e5qfFpmEeukW7cqqDjAuA/workitems/defect 
 
I had a hard time learning this myself, so here some hints.

0. Use POSTMAN, RESTCLIENT, cURL or Python if you want to experiment.

1. The headers are absolutely critical, if you mess up the headers you fail. Important are OSLC-Core-Version: 2.0, Accept: application/rdf+xml, Content:  application/rdf+xml. 

2. You must be logged in - form based auth or basic auth. Session handling and Cookies are vital! See https://rsjazz.wordpress.com/2019/05/13/using-a-rest-client-to-authenticate-to-elm-clm-applications/

3. Be practical. Get a work item first (of the same type you want to create!). Then copy the Response body. Maybe remove the Work item ID from the RDF, you can try to leave it in as well and POST the response body to the factory URI. If you can create a work item that way, you can start looking at the resource shape and the request body you have now and strip unnecessary data away and to understand how to generate such a request body.  

Ivaylo Kubratov selected this answer as the correct answer

Comments
Ralph Schoon commented Jul 21 '21, 4:59 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

5 other answers



permanent link
Ralph Schoon (63.1k33646) | answered Aug 24 '21, 3:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Sorry, but how should we be able to answer that question. There is so much information missing. I would consider to create a new question as this is already answered and accepted as such.


I would expect that you are not authenticated/logged in.

My hint would be, to configure your test environment and remove all required attributes. In that case you can create a work item with just providing the summary. Below a minimal POST body with the summary, the description and the cathegory. It is JSON not rdf+xml, because I find that easier to use. 

I have played around with that API and can only tell, that the following is important if you want information in the forum:
Request headers, request body, response headers, response body, cookies.
You must be logged in!

If you are authenticated the below is the minimal information I had to provide for this to work:


Request header

Accept application/json; charset=utf-8
Content-type application/json; charset=utf-8
OSLC-Core-Version 2.0

Cookies: I am logged in 

Cookie JSESSIONID=00000WtRQR4gMrEI9wG-rtDlVsH:0a6f8041-a5ba-4a69-8631-ea43db7983fa; LtpaToken2=pg5qZWk2AIUvXJxvPxtcWsZUYEFHTAwFFJT7p9ruHs2FmLq+kzVjc66w81HGEXfoDiruzJ/El3aZ6AV555J4EbA76I01M8asQdRbcfm1DuaWwGnGix1lSXXJ2unc/ehjtEKWRHjXE/rPOaakwcwCCsjq2f+JQUqhhgQQgsxFPSeub92BdezQ8aAlTPKmBqOndPcyKuDstDMwRK8SF4mWOqpb/IwSyhcwBejs+qCmn2GOKR2uUrkD7vGE3E43mmqkyGr1FCXh9k6UAyeF7UfCXwQGtfVahReIaFwdycAW83lPIiYx/oEnEAOIZ8AQu1dK

Minimal body
{"dcterms:title": "Work Item Created from JSON in Python.", "dcterms:description": "This is a work item linking to <a href=\"https://jazz.net/\">Jazz.net</a>.", "rtc_cm:filedAgainst": {"rdf:resource": "https://elm.example.com:9443/ccm/resource/itemOid/com.ibm.team.workitem.Category/_HWNLMFpnEeukW7cqqDjAuA", "rdf:type": [{"rdf:resource": "http://jazz.net/xmlns/prod/jazz/rtc/cm/1.0/Category"}]}}

Note, sometimes, dependent on the context, you have to provide the header X-Jazz-CSRF-Prevent with the value set to the value of JSESSIONID. This is to prevent cross site scripting.



Comments
Ivaylo Kubratov commented Aug 24 '21, 3:50 a.m.

Hello Ralph,

I used Mozilla REST extention, which was blocked from Windows firewall.
After that I had another response code 403, in the error message was written
" Preconditions have not been met: The 'How Found' attribute needs to be set "
This was fixed with change of tags in POST request

<rtc_cm:com.xxxxxx.howfound> -> <rtc_ext:com.xxxxxx.howfound>

Regards



Ralph Schoon commented Aug 24 '21, 4:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Does it work for you then? 


permanent link
Ivaylo Kubratov (152) | answered Aug 24 '21, 3:02 a.m.

 This is body of POST request:

  <dc:title>Test</dc:title>
  <oslc_cm:severity rdf:resource="https://jazz.xxxxxx.com:9443/ccm3/oslc/enumerations/_GTd-1Y3mEeWdW5Wc42wZnA/severity/severity.literal.l2"/>
  <rtc_ext:com.xxxxxx.howfound rdf:resource="https://jazz.xxxxxx.com:9443/ccm3/oslc/enumerations/_GTd-1Y3mEeWdW5Wc42wZnA/com.xxxxxx.howfound/com.xxxxxx.howfound.literal.l7"/>
  <rtc_cm:foundIn rdf:resource="https://jazz.xxxxxx.com:9443/ccm3/resource/itemOid/com.ibm.team.workitem.Deliverable/_N1m_MN2bEeutgIqMiQdXZA"/>
  <rtc_ext:com.xxxxxx.Occurrence rdf:resource="https://jazz.xxxxxx.com:9443/ccm3/oslc/enumerations/_GTd-1Y3mEeWdW5Wc42wZnA/com.xxxxxx.Occurrence/com.xxxxxx.Occurrence.literal.l8"/>
  <rtc_cm:filedAgainst rdf:resource="https://jazz.xxxxxx.com:9443/ccm3/resource/itemOid/com.ibm.team.workitem.Category/_LjU5cI3nEeWVhYfSLiIgNw"/>
  <rtc_cm:plannedFor rdf:resource="https://jazz.xxxxxx.com:9443/ccm3/oslc/iterations/_DqgEQKfLEeWkn4MNI1pzIw"/>
  <rtc_cm:com.xxxxxx.workitem.defectc.defect.description> Test Sequence:   Expected behaviour:    Actual behaviour:
  </rtc_cm:com.xxxxxx.workitem.defectc.defect.description>
</oslc_cm:ChangeRequest>


permanent link
Ivaylo Kubratov (152) | answered Jul 20 '21, 1:27 p.m.
edited Jul 20 '21, 1:28 p.m.

 Thank you for all responses,

1. I'm try to create Defect with POST request to address, which I get from services
2. I get required properties from Defect shape
3. The request body is this:

<dc:title rdf:parseType="Literal">Test</dc:title>
<dc:description rdf:parseType="Literal">OSLC Creation Example</dc:description>
</rdf:RDF>
Status from this request is 403 Forbidden.
Can you tell me what is the reason for this response code?


permanent link
Ralph Schoon (63.1k33646) | answered Jul 19 '21, 3:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Please go to https://jazz.net/wiki/bin/view/Deployment/CLMProductAPILanding and check the links in the General OSLC section. At least look into the OSLC workshop.


permanent link
David Honey (1.8k17) | answered Jul 16 '21, 12:59 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Discover the OSLC creation factory - see OSLC Core discovery.
The creation factory should reference an OSLC resource shape. That shape will tell you the supported properties.

Construct an RDF model conformant with the shape and POST using a supported RDF serialization form such as application/rdf+xml or text/turtle to the creation factory URI.


Comments
Ivaylo Kubratov commented Jul 19 '21, 10:14 a.m. | edited Jul 19 '21, 10:50 a.m.

 Yes I have the shape and all allowed values and I have CreationFactory for "creation of change requests", but can find there required properties to create defect, I don't want to use all available properties


David Honey commented Jul 19 '21, 10:18 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Look at the oslc:occurs of each OSLC property in the resource shape. That should tell you whether it is required.


Ralph Schoon commented Jul 19 '21, 10:22 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I think you have to know the required properties that are imposed by EWM in the preconditions such as Required Attributes by type and state. I do not think that state dependent mandatory attributes are presented in the shape. I am not aware of a way to query this information. 


Ralph Schoon commented Jul 19 '21, 10:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

From my own experience, the minimum information a work item requires to be created is a summary and the category (filed against). You can modify your process that the only required attribute is the subject/summary attribute, which is a string. 


The category is not a simple value and you would have to retrieve all the allowed values and you would have to pick one that is not the unassigned value. 


David Honey commented Jul 19 '21, 10:28 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Yes, that's true. I think that was part of what the old proposed OSLC Automation specification was going to address. But that specification fell by the way side and never reached published state, and now there seems little appetite for developing it into a public standard.


Ralph Schoon commented Jul 19 '21, 10:30 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Also note, if you get a work item, you get valid values for one and you can remove the stuff you are not interested in. Once you have the values, you can easily create an XML with the ones you pick.  

showing 5 of 6 show 1 more comments

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.