Requesting the REST API with ajax() (Error 400)

Hello everyone! :slight_smile:

I’m trying to request the REST API in order to insert, in an instance, a variable of type String, from a Jquery.ajax() code.

Here is the code :

$.ajax(
	{
		url: 'http://localhost:8080/engine-rest/process-instance/'+processInstanceId+'/variables/Test2',
		type: 'PUT',
		contentType: 'application/json',
		dataType : 'json',
		data: {
			"value" : JSON.stringify(JsonWeightMeasures),
			"type": "String"
		}
	}
);

This code is in a script tag of an embedded form.

processInstanceId is a string variable and JsonWeightMeasures is a JSON variable.

Here is the error generated :

What can I do? What generates this error?

Thank you in advance for your help and have a nice day ! :slight_smile:

Can you provide more details from your error? Or at the very least what the request looks like in the Network tab of the browser? Looks like you have the request mostly right, for example, mine was successful with:

curl --location --request PUT 'http://localhost:8080/rest/process-instance/82c59ae8-28d7-11eb-9dec-f20d19ddfb8f/variables/Test2' \
--header 'Content-Type: application/json' \
--data-raw '{
    "value": "{\"one\": 1, \"two\": \"two\"}",
    "type": "String"
}'

I would suspect that dataType: 'json' is telling jquery to do something unintended with the request, or the JsonWeightMeasures variable doesn’t have the json data you think it does. That’s why it might be helpful to see what the outgoing request looked like