Project

General

Profile

REST API update and create

Added by Javier Hernandez about 14 years ago

Hi, i'm writing a little high-level redmine module for python.
I want to do basic things, retrieve, update and create issues or projects.

At this time, i have some code for get issues and projects, but i have some problems.

First problem is that i can't retrieve all projects or specific projects, only one project given by id.
My petition is:

a = rmclient.get_projects()
INFO:pyactiveresource.connection:GET http://demo.redmine.org/projects.xml
DEBUG:pyactiveresource.connection:request-headers:Authorization:Basic amF2aXViZTpyZWRtaW5ldGVzdHM=

i get:

ServerError: HTTP Error 502: Bad Gateway

As you can see, i can retrieve issues with no problems:

a = rmclient.get_issues()
INFO:pyactiveresource.connection:GET http://demo.redmine.org/issues.xml
DEBUG:pyactiveresource.connection:request-headers:Authorization:Basic amF2aXViZTpyZWRtaW5ldGVzdHM=
INFO:pyactiveresource.connection:--> 200 OK 19058b

Second problem is when i'm going to update an existent issue, i'm doing like this:

a = rmclient.get_issues()
INFO:pyactiveresource.connection:GET http://demo.redmine.org/issues.xml
DEBUG:pyactiveresource.connection:request-headers:Authorization:Basic amF2aXViZTpyZWRtaW5ldGVzdHM=
INFO:pyactiveresource.connection:--> 200 OK 19058b

Now, i have this issue in 'i':

i.attributes
Out[142]: 
{'assigned_to': None,
 'author': None,
 'created_on': 'Sat Feb 20 18:28:16 -0800 2010',
 'custom_fields': custom_fields(None),
 'description': 'descripcion bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla\n\n\n bla bla bla bla bla bla\n',
 'done_ratio': '40',
 'due_date': None,
 'estimated_hours': '5.0',
 'id': '12571',
 'priority': None,
 'project': None,
 'spent_hours': '0.0',
 'start_date': '2010-02-20',
 'status': None,
 'subject': 'primera peticion',
 'tracker': None,
 'updated_on': 'Mon Feb 22 14:12:58 -0800 2010'}

First thing is that i don't know why 'status' or 'project' are none, but this things maybe will be in a future message :P

Now i make:

i.description = 'new description'
i.save()
INFO:pyactiveresource.connection:PUT http://demo.redmine.org/issues/12571.xml
DEBUG:pyactiveresource.connection:request-headers:Authorization:Basic amF2aXViZTpyZWRtaW5ldGVzdHM=
DEBUG:pyactiveresource.connection:request-body:<?xml version="1.0" encoding="UTF-8"?>
<issues><status nil="true" /><due-date nil="true" /><description>new description</description><author nil="true" /><spent-hours>0.0</spent-hours><subject>primera peticion</subject><start-date>2010-02-20</start-date><project nil="true" /><created-on>Sat Feb 20 18:28:16 -0800 2010</created-on><tracker nil="true" /><custom-fields><custom-field>0</custom-field></custom-fields><assigned-to nil="true" /><updated-on>Mon Feb 22 14:12:58 -0800 2010</updated-on><estimated-hours>5.0</estimated-hours><id>12571</id><done-ratio>40</done-ratio><priority nil="true" /></issues>
INFO:pyactiveresource.connection:--> 200 OK 1b

Out[144]: True

As you can see, i get a 'True' but only thing has been changed is 'updated-on'.

I'm doing all petitions using my asami morita at http://demo.redmine.org.

Sorry for long code descriptions, but i think it can be usefull.

Lot of thanks!


Replies (3)

RE: REST API update and create - Added by Jeffrey Jones about 14 years ago

The official demo.redmine.org site is hosted on Heroku and quite often overruns its limits. I also cannot see projects.xml because it times out (30 seconds is the maximum allowed by heroku).

If you want a reliable installation to test against I would recommend download trunk and using a local copy.

RE: REST API update and create - Added by Javier Hernandez about 14 years ago

Yes, now i'm getting projects succesfully. Thanks!

But issue modifications or creation still doesn't work for me at the moment.

That's my petition on production's log:

Processing IssuesController#edit to xml (for 192.168.1.173 at 2010-02-25 15:13:48) [PUT]
  Parameters: {"format"=>"xml", "action"=>"edit", "id"=>"7940", "issues"=>{"start_date"=>"2009-03-20", "estimated_hours"=>nil, "category"=>{"name"=>"Problema técnico", "id"=>"314"}, "assigned_to"=>{"name"=>"Adrian Belmonte", "id"=>"45"}, "author"=>{"name"=>"Jose Felix Ontanon", "id"=>"23"}, "created_on"=>"Fri Mar 20 08:59:38 +0100 2009", "priority"=>{"name"=>"Normal", "id"=>"4"}, "done_ratio"=>"0", "id"=>"7940", "project"=>{"name"=>"Gbv5 Migración", "id"=>"58"}, "subject"=>"ueeeeeeee", "updated_on"=>"Thu Feb 25 15:10:47 +0100 2010", "tracker"=>{"name"=>"Tareas", "id"=>"2"}, "due_date"=>"2009-03-20", "description"=>"Medusa siempre se le quedá con el cliente-22 en 54:05 min. De pronto le vuelve a funcionar, pero ha sucedido ya 4 veces contando la actual. ", "status"=>{"name"=>"Nueva", "id"=>"1"}, "spent_hours"=>"0.0"}, "controller"=>"issues"}
Completed in 293ms (View: 1, DB: 93) | 200 OK [http://redmine/issues/7940.xml]

Changes doesn't occur. I'm doing something wrong? Maybe i have to add journal manually for changes take effect?

Thanks!

RE: REST API update and create - Added by Felix Schäfer about 14 years ago

The format of issues should be more akin to:

 "issue"=>{"start_date"=>"2010-02-25", "estimated_hours"=>"", "priority_id"=>"4", "done_ratio"=>"0", "assigned_to_id"=>"", "subject"=>"Test", "tracker_id"=>"1", "due_date"=>"", "status_id"=>"1", "description"=>"blah"}

Just create/update an issue from the web frontend an have a look at the logs, or inspect the html form to see how all the parameters are called.

    (1-3/3)