Create project failed via REST api
Added by ibm bbc about 7 years ago
Hello,
I try to use python to create a project, but it always return "HTTP Error 422: Unprocessable Entity", here are my python codes which can get all kinds of redmine data if data is None, is there something wrong?
headers = {'Content-Type': 'application/json', "X-Redmine-API-Key" : "62ab473dec64ebc3d9514b0176f1f2f4a66e298c"} data = json.dumps({"is_public": false, "identifier": "test", "name": "test"}) request = urllib2.Request(url=url, headers=headers, data=data) response = urllib2.urlopen(request, timeout=5) result = json.load(response)
And I try to use curl in terminal like this:
curl -v -H "Content-Type: application/json" -H "X-Redmine-API-Key: 62ab473dec64ebc3d9514b0176f1f2f4a66e298c" -X POST --data "{\"identifier\": \"test\", \"name\": \"test\"}" localhost:3000/redmine/projects.json
it responded, but always return name blank error, however, my data contained name and identifier indeed, why they were not recognized?
{"errors":["Name cannot be blank","Identifier cannot be blank","Identifier is too short (minimum is 1 characters)"]}
My redmine information
Environment: Redmine version 3.3.0.stable Ruby version 2.1.10-p492 (2016-04-01) [x86_64-linux] Rails version 4.2.6 Environment production Database adapter Mysql2
Thanks in advance.
Replies (2)
RE: Create project failed via REST api - Added by Mayama Takeshi about 7 years ago
Hi,
try enclosing the data in a project:
curl -v -H "Content-Type: application/json" -H "X-Redmine-API-Key: 62ab473dec64ebc3d9514b0176f1f2f4a66e298c" -X POST -d '{"project": {"identifier": "test", "name": "test"}}' localhost:3000/redmine/projects.json
RE: Create project failed via REST api - Added by ibm bbc about 7 years ago
It succeed! Thanks a lot.
Looks like I forget the outermost "project", which not mentioned in wiki example. I think wiki should update the example.