How to insert/update String variable with GraphQL on completeTask

I am using the following complete task query.

mutation completeTask ($taskId: String!, $variables: [VariableInput!]!) {
    completeTask (taskId: $taskId, variables: $variables) {
        id
        name
        taskDefinitionId
        processName
        creationTime
        completionTime
        assignee
        variables {
            id
            name
            value
            previewValue
            isValueTruncated
        }
        taskState
        sortValues
        isFirst
        formKey
        processDefinitionId
        candidateGroups
    }
}

My GraphQL variables are:

{
  "taskId": {{taskid}},
  "variables": [{
    "name": "foo",
    "value": 7
  }]
}

And it works fine. But this does not work.

{
  "taskId": {{taskid}},
  "variables": [{
    "name": "foo",
    "value": "bar"
  }]
}

I get an ā€œUnrecognized typeā€ error.

ā€œmessageā€: ā€œUnrecognized token ā€˜barā€™: was expecting (JSON String, Number, Array, Object or token ā€˜nullā€™, ā€˜trueā€™ or ā€˜falseā€™)\n at [Source: (String)ā€œbarā€; line: 1, column: 4]ā€,

What am I doing incorrectly?

Thanks.

Hi @chrisallen ,

Try escaping some quotes into the string, so:

{
  "taskId": {{taskid}},
  "variables": [{
    "name": "foo",
    "value": "\"bar\""
  }]
}

Does that work?

Josh

2 Likes

Hi @jwulf . Yes that works, thanks. As an additional test, I also added a string variable ad-hoc to a user task in Tasklist for C8, and saw that it complained that the string was not ā€œJSON stringā€, and suggested a pop up editor where I put double quotes around it. That helped give me some context.

Thanks.

Hello,

I have actually the same problem using TaskList GraphQL API with Node.JS server.

My code is :

const body = {
        operationName: null,
        query: `mutation { completeTask(taskId: "${idTask}", variables: [{ name: "VARTEST", value: "TestValue" }]) { id, name, taskDefinitionId, processName, creationTime, completionTime, assignee, taskState, sortValues, isFirst, formKey, processDefinitionId, candidateGroups }}`,
        variables: {}
    }

    try {
        const response = await fetch(ENDPOINT, {headers: {'Content-Type': 'application/json', "Authorization": "Bearer ..."}, method: 'POST', body: JSON.stringify(body)})
        const data = await response.json()
        console.log("data=", data);
        
    } catch(err) {
        console.log(err);
    }

Error is :

data= {
  errors: [
    {
      message: "Unrecognized token 'TestValue': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n" +
        ' at [Source: (String)"TestValue"; line: 1, column: 10]',
      locations: [Array],
      path: [Array],
      extensions: [Object]
    }
  ],
  data: null
}

Query work with no ā€œvariablesā€ attribute or setted to ā€œ[]ā€

What am I doing incorrectly?

Thanks a lotā€¦