Project

General

Profile

API writing time_entries fails 422

Added by Olav Kvittem over 12 years ago

Hei,

I am trying to automate logging time_entries via the rest API.

Querying works fine, but creating entries fails with 422 Unprocessable Entity :
<error>Activity can't be blank</error>
<error>Hours can't be blank</error>

I am using perl LWP:UserAgent and my parameters are as seen below.
So hours og activity is not blank as claimed by the error message ?

Redmine version is supposed to be 1.3.0, but can I check this as a web user or via the API ?

My code is essentially :

my $req = HTTP::Request -> new( POST => 'https://my.redmine.host/time_entries.xml');
$req->content_type('application/x-www-form-urlencoded');
    $req->content('key="my api key"&issue_id=347&activity_id=10&hours=8&comments="test" 
');
    my $res = $ua->request($req);


Replies (1)

RE: API writing time_entries fails 422 - Added by Olav Kvittem over 12 years ago

I succeed by changing to XML style and using api_key as username i URL.
I do

  use LWP::UserAgent;

  content-type application/xml and
  content formattet with XML :
  <?xml version="1.0" encoding="UTF-8"?><time_entry><id>44</id><project name="IoU basis" id="62"/><issue id="347"/><user   name="Olav Kvittem" id="34"/><activity name="Generic work" id="10"/><hours>4.37</hours><comments>testing</comments><spent_on>2011-12-28</spent_on><created_on>2011-12-28T10:37:25+01:00</created_on><updated_on>2011-12-28T10:37:25+01:00</updated_on></time_entry>

cheers

    (1-1/1)