any way to upload files to an existing github issue by REST API #46951
Replies: 7 comments 17 replies
-
Hello @vincezh0205 here is some pseudo code. Give it a try but you will have to verify if I works or not for your use case. As I cannot. import requests
import json
url = "https://api.github.com/repos/{owner}/{repo}/issues/{issue_number}/comments".format(owner="", repo="", issue_number='')
headers = {
"Authorization": "token XXX",
"Accept": "application/vnd.github+json",
"Content-Type": "application/octet-stream",
}
file = open("path/to/file.ext", "rb")
response = requests.post(url, headers=headers, data=file)
if response.status_code == 201:
print("File attached successfully")
else:
print("Failed to attach file. Response status code:", response.status_code) |
Beta Was this translation helpful? Give feedback.
-
I have the same question. I would like to migrate 2000+ PRs from bugzilla to GitHub Issues. I managed to export the PRs to XML and found the GitHub Issues REST API v2022-11-28. Based on this I should be able to create new issues and comments from the XML. But how do I add attachments? Is it possible at all? @vincezh0205 any insights from your recent attempts? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Quite old thread here. I am in the same situation.
|
Beta Was this translation helpful? Give feedback.
-
Here is the whole code modified to truly check that the credentials are ok:
This gives now response 400, Bad request. |
Beta Was this translation helpful? Give feedback.
-
I recently managed to import some 2000 bugzilla reports via:
Instead of attaching files via Rest API, I created a repository of attachments, stored by bugzilla ID (attachments/attachment-N, N=1,...) and converted attachment links in reports to URLs in this repository via their ID. This has the added advantage of not being limited to GitHub allowed file types/extensions. |
Beta Was this translation helpful? Give feedback.
-
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
-
Select Topic Area
Question
Body
I tried to add one comment with file attached to an existing github issue by calling github REST API in Python code. But I have no idea how to do this. I could only add some plain txt into as a new comment. Here is my existing code for adding a plain txt comment into an issue. Anyone could help me to figure out how to upload files into a comment. Thanks a lot
Beta Was this translation helpful? Give feedback.
All reactions