Hi.
Great question and you're touching on a good issue.
The Web Services API (
WSAPI) does have support for batch updates. There is a 'batch' endpoint that can allow a single http post request batching up multiple api requests. Check out the "Bulk Operations" section in the WSAPI page for more information.
We can add up a number of projectpermission updates into such a batch. I've included a text file that has an example for you, it has the URL as well as the JSON example.
However, the "bad" news is that the PyRal kit doesn't support the Batch endpoint and there isn't a pyral object that represents this endpoint. And so, what you can do in your Python code is simply construct this http payload and make a direct http post from your code. But, you will need to make sure you code also checks and handles the http errors.
By the way, I suspect that the reason you added the 'wait' in between your individual calls is for a 'concurrency' error. Is that correct? Did that wait fix it?
From my experience a concurrency error can still occur even with the batch endpoint and so you may need to look into why it's happening.
Normally, we recommend you don't add a 'wait' between your statements but simply retry. So, for example you catch the error, if a concurrency error then resend the same request, perhaps do it twice and almost certainly it'll work - you may want to give that a try instead of a wait (if the issue was the concurrency error).
Let us know if that helped.
Sagi
Original Message:
Sent: 09-23-2019 03:57 PM
From: Andy S
Subject: Creating users via WebAPI--possible to set all project permissions in single API call?
Hi,
I have a Python script that I use to automatically add new Rally users. The script uses the Pyral package.
Standard access grants our users Editor permissions to (currently) 184 projects, all children of the MAIN project. I want the script to do 2 things:
a) Dynamically build a list of all projects under the MAIN project (as this list is subject to change by upper management any time).
b) Add the user(s) to all projects.
The problem is, I have to send a single JSON payload for EACH project permission--with there currently being 184 projects under MAIN, executing steps (a) and (b) means performing 368 separate API requests just to add one user. With this number of requests, the many requests fail unless I add a few seconds between requests which makes the process take an extremely long time.
The payload looks something like this:
payloadProjectPermissions = {
'HierarchicalRequirement': {
'Project': techProjectPermissions[i],
'User': newUserID,
'Role': 'Editor'
}
}
Can someone let me know of a way to add ~200 project permissions for a user in a single API call? Or in general, a more efficient way to do this?