Update variable via REST on subprocess scope

I have a variable setup in a subprocess with a value, let’s say A.
On the subprocess I have a User Task in which I want to update the variable via REST (before submitting the form).

return $http.get(Uri.appUri(‘engine://engine/:engine/task/’ + camForm.taskId)).success(function(result){

var item = camForm.variableManager.variables[variableName];

var updateValue = {
type: item.type,
value: JSON.stringify(item.value),
valueInfo: item.valueInfo
};

return $http.put(Uri.appUri(‘engine://engine/:engine/process-instance/’ + result.processInstanceId + ‘/variables/’ + variableName),
updateValue,
function() {
console.log(“VARIABLE UPDATED”)
});

                   });

Instead of updating the variable, I’m getting a new variable on the main process scope.
How can I do to update the correct variable scope?

I’m getting a duplicated variable on the scope for the subprocess and the main process.

Thanks,
Leonardo

Found it!

I had to use this endpoint instead:

                      return $http.put(Uri.appUri('engine://engine/:engine/task/' + camForm.taskId + '/variables/' + variableName),

https://docs.camunda.org/manual/7.5/reference/rest/task/variables/put-task-variable/