Project

General

Profile

How to reply in an issue using python script

Added by alexis sanosa over 1 year ago

Here is my sample python script

import requests

base_url = "https://matrix.philsys.gov.ph"
api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
issue_id = 8100
comment_text = "Hello"

endpoint_url = f"{base_url}/issues/{issue_id}/comments.json"

headers = {
"Content-Type": "application/json",
"X-Redmine-API-Key": api_key
}

payload = {
"comment": {
"body": comment_text
}
}

response = requests.post(endpoint_url, headers=headers, json=payload)

if response.status_code == 201:
print("Comment created successfully!")
else:
print("Failed to create comment. Status code:", response.status_code)
print("Response content:", response.content)

But I got this error

Failed to create comment. Status code: 404
Response content: b'<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8" />\n <title>Redmine 404 error</title>\n <style>\n body {font-family: "Trebuchet MS", Georgia, "Times New Roman", serif; color: #303030; margin: 10px;}\n h1 {font-size:1.5em;}\n p {font-size:0.8em;}\n </style>\n</head>\n<body>\n <h1>Page not found</h1>\n <p>The page you were trying to access doesn\'t exist or has been removed.</p>\n <p><a href="javascript:history.back()">Back</a></p>\n</body>\n</html>\n'


Replies (1)

RE: How to reply in an issue using python script - Added by Mayama Takeshi over 1 year ago

Try these changes:


endpoint_url = f"{base_url}/issues/{issue_id}.json" 

payload = {
  "issue": {
    "notes": comment_text
   }
}

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

    (1-1/1)