0

I am trying to post issues in redmine using the rest API, I am using a python script to do so:

here is my script:

import requests
import json

username = "x"
password = "x"

url = "http://localhost:3000/issues.json"
data = open('rest.json', 'rb')

r = requests.post(url, auth=(username, password), data=data)

print(r.status_code) 
print(r.text)

and here is the JSON I am trying to post

{
    "issue" : {
        "id" : 2,
        "projet_id" : 1,
        "tracker_id" : 1,
        "priority_id" :1,
        "status_id" : 1,
        "author_id" : 1,
        "subject" : "Subject changed",
        "description": "The subject was changed",
        "category_id" :1,
        "assigned_to_id" : 1        
    }
}  

the problem is that each time I am having an error 422 telling me that "issues cant be empty, tracker cant be empty and status as well"

can you guys help me with that?

thank you

Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48
Ôokami
  • 21
  • 6
  • Have you tried using strings? when i post via ResT api, all of the values need to be in strings, but that could be software specific – AJames Oct 14 '21 at 15:51
  • i just tried to put the int in string mode, but i still have the same error – Ôokami Oct 15 '21 at 08:34
  • i upgraded my python script, so it can handle the json file. and now it shows me an http error 400, any ideas fam? here is my script import requests from requests.structures import CaseInsensitiveDict import json username = "Admin" password = "Admin1111" url = "http://localhost:3000/issues.json" header = CaseInsensitiveDict() header["Accept"] = "application/json" header["Content-Type"] = "application/json" f = open('rest.json', 'rb') data = json.load(f) r = requests.post(url, auth=(username, password),headers=header, data=data) print(r.status_code) – Ôokami Oct 15 '21 at 09:12

0 Answers0