Post

3 followers Follow
0
Avatar

Change Task State with API

I am trying to update the state of tasks using the API.

I have tried "/data/changeState" but I get an n internal error has occurred message.

My json message is: {"ids": ["/Task/3d9yk1s1boq3o5ani22vhog3n26"], "state": "draft"}

Can anyone tell me what I am doing wrong?

Josh Boutwell Answered

Please sign in to leave a comment.

9 comments

0
Avatar

Eyal,

 

I tried that without success.  I ended up finding a work around.  I created a custom action that mediates the change of state and then I call the Custom Action with the API.

 

Josh Boutwell 0 votes
0
Avatar

Hi Josh,

That's an unusual workaround.
Changing a task's state is definitely something that should be supported with the API, I think we could help if you let us know.

Anyway, can you elaborate on 'without success'? If you got an error message with a ref id we could use that to figure out what the issue was.
If there's something wrong on our side we'd like to fix it. If it's something you need to fix I guess you & other developers would like to know.

Thanks,

Ophir

Ophir Kenig 0 votes
0
Avatar

Hi Ophir,

 

Attached are the log outputs for an attempt to change a state:

 

{"requests":[
		           
            {"url" : "/data/changeState", "method": "POST", "body":  {"ids": ["/Task/1v220u27wm7ijzblza8dk4l7418664"], "state": "Draft"}}
         
            ]}

Array ( [responses] => Array ( [0] => Array ( [statusCode] => 500 [body] => Array ( [errorCode] => Internal [message] => An internal error has occurred, the error was logged and will be examined. [referenceId] => 1GTZ4b9Av5img1JoEnT59K ) [headers] => Array ( ) ) ) )


As a note I did manage to trigger a different response. I original task I used has since been completed and when I ran the command I cited originally I got:

[message] => Method not found from state 'Completed' to state 'Draft'



Josh Boutwell 0 votes
0
Avatar

Ok, let me withdraw my issue....

 

It now seems to work.  The error I just posted was because the object was a Milestone not a Task.  Once I corrected that it worked.

 

I don't know what changed.  Back in December I checked that as an issue.  Whatever is different I am glad.

 

Josh

Josh Boutwell 0 votes
0
Avatar

I just had an idea.  The process that generated the original issue created a task then immediately changed the state.

 

Does the API need time after the object is created before the state is changed?  My work around would have slowed the process slightly and that might be why it worked.

Josh Boutwell 0 votes
0
Avatar

Hi Josh,

Not that we know of. As we don't have the original error it's hard to tell what went wrong then.

As for the other message:

You can't change directly from 'Completed' to 'Draft'. You need to change to 'Active' first. It's the same as the Clarizen UI.

If you have other questions or issues don't hesitate to post here.

Hope this helps,

Ophir

Ophir Kenig 0 votes
0
Avatar

Ophir,

 

That was not the original problem.  Last december that Task was active and I needed to make it draft.  Since then I marked the entire project including that task as complete so when I ran the same API call the state was now completed where as before it was active.

 

I did get errors trying to change Active to Draft and Draft to Active.

Josh Boutwell 0 votes
0
Avatar

Hi Josh,

The issues you had in December were because of dropping the square brackets for ids on some messages and using 'draft' instead of 'Draft' in others (or both issues on the same message...). I did some digging in our logs and I couldn't find another issue.

Anyway, it looks like you got it working now, so no need to use that workaround.

Hope this helps,

Ophir

Ophir Kenig 0 votes