Cannot clear parent epic using api, in python

I am trying to loop through all the issues in one repo, and then remove the parent epic link from one of them. This code doesn’t remove the parent link, but I’m not sure why. Does anyone know what changes I need?
Thanks
Wally

import requests

url = "https://gitlab.com/api/v4/projects/8675309/issues"

payload = {}
headers = {
  'PRIVATE-TOKEN': 'glpat-xxxxxxxxxxxxxxxxxxxx’
}



response = requests.request("GET", url, headers=headers, data=payload,params={"per_page": 100})
issues = response.json()

for issue in issues:
 issue_iid = issue['iid']
 issue_title = issue['title']
 parent = issue.get('epic_iid')

 if parent:
  print(f"Issue #{issue_iid}: {issue_title}")
  print(f"\033[31m  ↳ Parent ID: {parent}\033[0m")


put_url = "https://gitlab.com/api/v4/projects/8675309/issues/12"

#PUT /projects/:id/issues/:issue_iid
#Remove Epic connection
  
payload = {
    "id" : “4212345,
    "iid" : "12",
    "confidential": "False",
    #"epic_iid" : "null",
    "epic":{
        #"id" : "null",
        "iid" : "null"
        }
    }

response = requests.put(put_url, headers=headers, json=payload)

Hi,

I hope I’m not too late.

First, if you work with python, I would recommend using the wrapper lib python-gitlab. Makes it much easier.

But if you want to stick with the raw API calls, it’s fine too. I notice you’re using the wrong endpoint. You need the epic endpoint which btw is marked as deprecated for v5.

Removes an epic - issue association.

DELETE /groups/:id/epics/:epic_iid/issues/:epic_issue_id

But as I said with python-gitlab this is much easier.

pip install python-gitlab
from gitlab import Gitlab

gl = Gitlab(
    url="<url>",
    private_token="<token>"
)

group = gl.groups.get(group_id)
epic = group.epics.get(epic_id)

for issue in epic.issues.list(get_all=True):
    issue.delete()  # doesnt delete the issue but removes from epic

Please make sure to use the rights ids


Edit: I notice you might wanna check the project before removing the issue from epic. I don’t know whether you might have other issues from other project assigned to that epic.

1 Like