Hello!
I am trying to set the sharePermissions on an HttpRequest for a filter that I am creating through python. I'd like to share a filter with a specific role within a project, but I can't get my payload right for some reason.
Data:
filtername | jql query | shareperms |
Sams Filters | status = "Waiting for support" and project = "Platform Development" | [ { "type": "project", "project": { "id": "10019" }, "role": { "id": "10002", "name": "Administrators" } } ] |
def create_jira_filter(jql, filter_name, share_perms):
headers = {
"Content-Type": "application/json"
}
auth = (username, api_token)
data = {
"jql": jql,
"name": filter_name,
"description": "Filter created using Jira REST API",
"favourite": True,
"sharePermissions": share_perms
}
response = requests.post(api_url, headers=headers, auth=auth, data=json.dumps(data))
if response.status_code == 200:
filter_id = response.json()["id"]
print("Filter created successfully. Filter ID:", filter_id)
else:
print("Failed to create filter. Status code:", response.status_code)
print("Error message:", response.text)
# Read JQL queries and filter names from CSV file
def read_filters_from_csv(file_path):
with open(file_path, newline='') as csv_file:
reader = csv.reader(csv_file)
next(reader) # Skip header row
for row in reader:
filter_name = row[0]
jql_query = row[1]
share_perms = json.loads(row[2])
create_jira_filter(jql_query, filter_name, share_perms)
Heyo!
Just because i just found this post while also scratching my head when reading the REST API documentation, and also came along the solution, I'm going to pull this post out of its hibernation. The correct payload for setting project with role is this (the last one sets a group and can be ignored. im just leaving it in to better show the structure for multiple permissions):
[
{
"type": "projectRole",
"project": {
"id": <projectId>
},
"role": {
"id": <projectRoleId>
}
},
{
"type": "group",
"group": {
"name": <groupname>
}
}
]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.