This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

API to change Document workflow state problem

Dear all,

I have problem when using M-Files API change object workflow state, please help.

I have a workflow with somes state.

I using API create a file and create document with this file.

The document on M-Files have default state, then i want to change default state to next state (Requestor)

I get all next state via API: {{MFWSUrl}}/structure/workflows/{{WorkflowID}}/states?currentstate=null 

and call the API: {{MFWSUrl}}/objects/{{ObjectType}}/{{ObjectID}}/{{ObjectVersion}}/workflowstate?_method=PUT

to update state but M-Files not working?

Here is the change object workflow state when i using M-Files Web GUI

  • Here is the document state when i using API to change state

  • What does the full request body look like?

    The endpoint documentation seems to indicate that the body should be one of these, but your request body seems to include an array of property definitions which looks wrong.

    That could explain why the workflow seems to be removed as well; it can't interpret the input so is resetting them all to empty...?

  • Thanks for your response!

    Here is full request body, I sent class, workflow and next state.

    Even request body only contains next state and response 200 OK. 

    The workflow state still removed.

  • So, that looks really wrong, at least according to the documentation.  The documentation says that the request body should an ObjectWorkflowState instance, so I'd expect the syntax to be more like this:

    {
        "StateID": 1924,
        "State": {
            "PropertyDef": 39,
            "TypedValue": {
                "DataType": 9,
                "Lookup": {
                    "Item": 1924,
                    "Version: -1
                }
            }
        },
        "StateName": "state name",
        "WorkflowID": 163,
        "Workflow": {
            "PropertyDef": 38,
            "TypedValue": {
                "DataType": 9,
                "Lookup": {
                    "Item": 163,
                    "Version: -1
                }
            }
        },
        "WorkflowName": "workflow name",
        "VersionComment": "hello world"
    }

    I'd expect that some of those values are optional (e.g. I would guess that the state and workflow name aren't needed, as they wouldn't be needed for the underlying COM API call).  I would need to check the source to the REST API to see whether you could choose to just provide the state or state ID properties, for example, too.

    But at a minimum I think your request body should be formatted like that.  I think I've copied the values across from your request properly - could you maybe test that and see whether it works?  If so then I can cross-reference the REST API code to see whether we could optimise it a bit.

  • Thank you very much!

    With your recommend, I called api with body like this the state has been updated.

    I remove state, workflow propertyDef, because with this, the workflow still removed.

    Thank you again!