Error 400 while setting issue properties

Hello Experts,

I am calling AP.request() method in the hello-world.hbs file to set issue property using the Jira cloud app. But I am getting 400 error. Here is my hello-world.hbs file.

{{!< layout}}

 <header>
  <script>
	  AJS.toInit(function(context)
	{
		alert("INIT DONE");
		
	AP.request({
        url: '/rest/api/2/issue/CD-1/properties/myinfo',
        auth: { username: 'user@example.com', password: '<someToken>' },
        type: 'PUT',
        data: {name: "user"},
        success: function(response)
         {
            response = JSON.parse(response);
            
            console.log(response);
        },
        error: function(response) {
            console.log(response);
        },
        contentType: "application/json"
		}); 
	
	});
	
</script>

</header>

<form>
//some code
</form>

Hi,
One thing that could help is to serialize sent data to string by using JSON.stringify method, see what happens if instead:

data: {name: "user"}

you write:

data: JSON.stringify({name: "user"})

Hi @LukaszWiatrak Thanks for the response.
Tried this way as well and getting below error:-

AP.request({
url: ‘/rest/api/2/issue/CD-1/properties/myinfo’,
auth: { username: ‘user@example.com’, password: ‘’ },
type: ‘PUT’,
data: JSON.stringify({name: “user”}),
success: function(response)
{
response = JSON.parse(response);

        console.log(response);
    },
    error: function(response) {
        console.log(response);
    },
    contentType: "application/json"
	});

Looks like it’s almost working -> you can see from stack trace that operation was successful (success method was called), but there’s some problem with deserializing response. Response is not used in your case so exception should be gone after you remove this line:

response = JSON.parse(response);

Worth to check what is written to the console log after this line is removed -> to see what exactly was passed to success method

@LukaszWiatrak Thanks for the response. It worked!:grinning:
After removing that line I am not getting any response code either success or failure but then I use the GET method to fetch the set property and then received the data in response which I had set earlier.

1 Like