Forbidden when creating Requirements via the OSLC API
Hi,
I am trying to create a new requirement in my test project via OSLC API.
Here is my code:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string webContextUrl = "https://jazz.net/sandbox02-rm";
string projectArea = "aaz_Project_1_ReqMng";
JazzRootServicesHelper helper = new JazzRootServicesHelper(webContextUrl, OSLCConstants.OSLC_RM_V2);
string authUrl = webContextUrl.Replace("/rm", "/jts");
JazzFormAuthClient jazzClient = helper.InitFormClient(user, passwd, authUrl);
if (jazzClient == null)
throw new Exception(LD.TKey("Client is null, please run authentication first", "General"));
if (jazzClient.FormLogin() != HttpStatusCode.OK)
throw new Exception(LD.TKey("Custom error: login failed on method FormLogin()", "General"));
string catalogUrl = helper.GetCatalogUrl();
string serviceProviderUrl = jazzClient.LookupServiceProviderUrl(catalogUrl, projectArea);
string queryCapability = jazzClient.LookupQueryCapability(serviceProviderUrl, OSLCConstants.OSLC_RM_V2, OSLCConstants.RM_REQUIREMENT_TYPE);
Requirement requirement = new Requirement();
requirement.SetTitle("New Requirement");
requirement.SetDescription("This is a New Requirement created via API");
requirement.SetCreated(DateTime.UtcNow);
string oslcReqResurceType = requirement.GetRdfTypes()[0].ToString();
string requirementFactory = jazzClient.LookupCreationFactory(serviceProviderUrl, OSLCConstants.OSLC_RM_V2, oslcReqResurceType);
HttpResponseMessage creationResponse = jazzClient.CreateResource(requirementFactory, requirement, OslcMediaType.APPLICATION_RDF_XML);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
After successful Authentication I find the factory url
//requirementFactory:
and perform creation of a new artifact.
I get a response status Forbidden.
//creationResponse.StatusCode: Forbidden
//creationResponse.RequestMessage:
//{Method: POST, RequestUri: //'https://jazz.net/sandbox02-rm/requirementFactory?projectURL=https%3A%2F%2Fjazz.net%2Fsandbox02-rm%2Fprocess%2Fproject-areas%2F_Jk3voapCEe-I9rfLYaQw7w', //Version: 1.1, Content: System.Net.Http.ObjectContent, Headers:
//{
// Accept: application/rdf+xml
// OSLC-Core-Version: 2.0
// Content-Type: application/rdf+xml
/ Content-Length: 732
//}}
When I dig deeper into the response I see expires DateTime - {1994-12-01 16:00:00 +00:00}. As if my request is not valid and because of that creation is prohibited..
//creationResponse.Content.Headers.Expires.Value: {1994-12-01 16:00:00 +00:00}
Or is there another reason?
Thx
Accepted answer
I've never used Java APIs, I'm not sure if they are supported for DOORS Next.
One thing you can't do is set system-defined properties like creation datetime, similary the creator is system-defined so no point trying to set it.
Also how are you providing a configuration?
And it looks like you're missing required information such as the instanceShape (i.e. the artifact type) and not required but should be provided to avoid putting all artifacts in the root folder) the nav:parent with the folder URI where you want the artifact created. I don't know how you specify these using Java.
Check the body of the response to your POST to see if contains any useful information about the reason for 403.
Here's the details of a successful artifact creation using HTTP Post:
Note:
1. The config is specified in parameter oslc_config.context - it could alternatively be specified in header Configuration-Context
2. In the body content the rdf:about="" is required. It just has to be present, don't think the value matters.
Host: jazz.ibm.com:9443
User-Agent: python-requests/2.31.0
Accept-Encoding: gzip, deflate, br
Accept: application/xml
Connection: Keep-Alive
X-Requested-With: XMLHttpRequest
Referer: https://jazz.ibm.com:9443/rm/web
OSLC-Core-Version: 2.0
Content-Type: application/rdf+xml
Cookie: ...
Content-Length: 1004
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/terms/" xmlns:public_rm_10="http://www.ibm.com/xmlns/rm/public/1.0/" xmlns:calm="http://jazz.net/xmlns/prod/jazz/calm/1.0/" xmlns:rm="http://www.ibm.com/xmlns/rdm/rdf/" xmlns:acp="http://jazz.net/ns/acp#" xmlns:rm_property="https://grarrc.ibm.com:9443/rm/types/" xmlns:oslc="http://open-services.net/ns/core#" xmlns:nav="http://jazz.net/ns/rm/navigation#" xmlns:oslc_rm="http://open-services.net/ns/rm#">
<rdf:Description rdf:about="">
<rdf:type rdf:resource="http://open-services.net/ns/rm#Requirement"/>
<dc:description rdf:parseType="Literal">OSLC Creation Example</dc:description>
<dc:title rdf:parseType="Literal">hello, world</dc:title>
<oslc:instanceShape rdf:resource="https://jazz.ibm.com:9443/rm/types/OT_vQmPyocYEe-VP_JEQOsc9Q"/>
<nav:parent rdf:resource="https://jazz.ibm.com:9443/rm/folders/FR_vKoxkYcYEe-VP_JEQOsc9Q"/>
</rdf:Description>
</rdf:RDF>
HTTP/1.1 201 Created
X-Powered-By: Servlet/3.0
Strict-Transport-Security: max-age=31536000
Set-Cookie: ...
X-Last-Modified-XSD: 2024-12-02T14:16:47.270Z
Last-Modified: Mon, 02 Dec 2024 14:16:47 GMT
X-Last-Modified-User: https://jazz.ibm.com:9443/jts/users/ibm
X-Jazz-Creator: https://jazz.ibm.com:9443/jts/users/ibm
X-Jazz-Created: 2024-12-02T14:16:47.270Z
X-Jazz-Owning-Context: https://jazz.ibm.com:9443/rm/process/project-areas/_vBYH4IcYEe-VP_JEQOsc9Q
ETag: "%220%22&_ELnVYLC4Ee-UEJVWrPYLCw"
Content-Length: 0
Content-Language: en-US
Date: Mon, 02 Dec 2024 14:16:48 GMT
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Cache-Control: no-cache="set-cookie, set-cookie2"