It's all about the answers!

Ask a question

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

Allison Schwoboda (133) | asked Dec 02 '20, 9:48 p.m.

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

Ian Barnard commented Dec 03 '20, 8:20 a.m. | edited Dec 03 '20, 8:21 a.m.

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.


Ian Barnard commented Dec 03 '20, 8:43 a.m.

As Jim says your url doesn't have a parameter like oslc.where (which is the query) or (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?

Allison Schwoboda commented Dec 03 '20, 5:30 p.m.

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

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

Ian Barnard commented Jul 12 '21, 8:47 a.m.

 Hi Allison

Use the discovery steps described here to find the Query Capability for the resource type you're looking for:

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
Jim Amsden (26837) | answered Dec 03 '20, 7:50 a.m.

 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.

Your answer

Register or to post your answer.