Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to request a list of artifacts in a project using Python REST API?

I am trying to access requirements using a Python API, and am having trouble with this query. Using the services query I got the baseURLs for requirement and folder queryCapability, and I've had success using the Folder Query Capability to browse folders and subfolders. However when I try the following request using the requirement queryCapability baseURL, I get a 403:Forbidden response.


self.headers = {'Content-type': 'application/x-www-form-urlencoded', 'OSLC-Core-Version': '2.0', 'Accept': 'application/rdf+xml'}
resp = requests.get('https://ServerName/rm/views?oslc.query=true&projectURL=https%3A%2F%2FServerName%2Frm%2Fprocess%2Fproject-areas%2F_1ipDAGUlEemksZVbt6XKiw',cookies=jar,verify=False,headers=self.headers)


Thank you in advance

0 votes

Comments

Hi Allison


I suggest you use a single requests session for all get/post because the cookies from login will then automatically be included in your subsequent actions on the session.

Try that, does it work better?


If it doesn't work:
1. Are you sure your authentication is working?
2. Once you have authentication working, one way of finding out what might be wrong is to first get your request working using a REST client like Postman, as Jim suggests, then use a proxy like Telerik Fiddler to trace all communication with the server - this way you can compare a working GET with your non-working GET using Python.

HTH
Ian

As Jim says your url doesn't have a parameter like oslc.where (which is the query) or oslc.select (which specifies which attributes you want returned in the results). These shouldn't be used with the folder query URL because it doesn't support them, but the resources query does need them - you don't usually want to get the entire server results back, it would be too big and put load on your server.


Try adding, where 1234 is an identifier you know is in the project,
NOTE the values after the first = must be url encoded like the parameters already in your url 

Does that produce some results?

Could you help provide some instruction on how to add these parameters to the query? For example, would the identifier be the ID of a component that holds other artifacts? And should these parameters be appended to the URL in the GET request like this:



resp = requests.get('https://ServerName/rm/views?oslc.query=true&projectURL=https%3A%2F%2FServerName%2Frm%2Fprocess%2Fproject-areas%2F_1ipDAGUlEemksZVbt6XKiw&oslc.where=dcterms:identifier=1234
',cookies=jar,verify=False,headers=self.headers)

Additionally, is there a resource somewhere that provides the URL formats for these different OSLC requests?

 Hi Allison



Use the discovery steps described here to find the Query Capability for the resource type you're looking for: https://jazz.net/library/article/1197

This gives you the base URL to add the OSLC Query parameters to. Make sure to not hardcode th query base URL, always use the discovery steps.



One answer

Permanent link

 403 indicates the authenticated user likely doesn't have privileges to do the operation. Did you try the request with Postman?


But the queryCapability service provides a queryBase URL that can be used with GET to do OSLC queries. I'm not sure what the GET that failed with 403 is trying to do, it doesn't contain an OSLC query.


0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,936
× 478

Question asked: Dec 02 '20, 9:48 p.m.

Question was seen: 2,897 times

Last updated: Jul 12 '21, 8:47 a.m.

Confirmation Cancel Confirm