Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Cloud API: set share permissions for project role on request

Sam Nadarajan
Community Champion
June 21, 2023

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"
  }
 }
]
Code:
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)
The script works as far as sharing the newly created filter with the project information specified in the data, but when I add the role object it doesn't seem to work. I've looked and looked at the API but I am stumped. Please help me!

1 answer

0 votes
Michael Wohlgemuth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 15, 2025

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>
    }
  }
]

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events